This is the mail archive of the
cygwin-apps
mailing list for the Cygwin project.
[PATCH setup 4/9] Add Option::isPresent() method
- From: Jon Turney <jon dot turney at dronecode dot org dot uk>
- To: cygwin-apps at cygwin dot com
- Cc: Jon Turney <jon dot turney at dronecode dot org dot uk>
- Date: Tue, 6 Jun 2017 12:54:27 +0100
- Subject: [PATCH setup 4/9] Add Option::isPresent() method
- Authentication-results: sourceware.org; auth=none
- References: <20170606115432.105020-1-jon.turney@dronecode.org.uk>
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