[PATCH setup 4/9] Add Option::isPresent() method
Jon Turney
jon.turney@dronecode.org.uk
Tue Jun 6 11:54:00 GMT 2017
Add Option::isPresent() method, so we can distinguish between the cases of
an option which is present with the default value, and an option which is
absent.
---
libgetopt++/include/getopt++/Option.h | 4 ++++
libgetopt++/src/Option.cc | 2 +-
libgetopt++/src/OptionSet.cc | 3 ++-
3 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/libgetopt++/include/getopt++/Option.h b/libgetopt++/include/getopt++/Option.h
index 7ea0786..a32f949 100644
--- a/libgetopt++/include/getopt++/Option.h
+++ b/libgetopt++/include/getopt++/Option.h
@@ -46,8 +46,12 @@ public:
};
virtual Argument argument () const = 0;
+ void setPresent(bool _present) { present = _present; }
+ bool isPresent() { return present; }
+
protected:
Option ();
+ bool present;
};
#endif // _OPTION_H_
diff --git a/libgetopt++/src/Option.cc b/libgetopt++/src/Option.cc
index ac13ab9..7c61eba 100644
--- a/libgetopt++/src/Option.cc
+++ b/libgetopt++/src/Option.cc
@@ -15,7 +15,7 @@
#include "getopt++/Option.h"
-Option::Option ()
+Option::Option () : present(false)
{
}
diff --git a/libgetopt++/src/OptionSet.cc b/libgetopt++/src/OptionSet.cc
index 82e1253..f57b89a 100644
--- a/libgetopt++/src/OptionSet.cc
+++ b/libgetopt++/src/OptionSet.cc
@@ -229,7 +229,8 @@ OptionSet::doOption(string &option, string::size_type const &pos)
optionValue = value.c_str();
}
break;
- }
+ }
+ theOption->setPresent(true);
lastResult = theOption->Process(optionValue);
}
--
2.12.3
More information about the Cygwin-apps
mailing list