summaryrefslogtreecommitdiff
path: root/tclap-1.2.1/include/tclap/ValuesConstraint.h
diff options
context:
space:
mode:
authorChristian Linke <christian.linke@bmw.de>2015-04-15 19:05:53 +0200
committerChristian Linke <christian.linke@bmw.de>2015-04-15 19:05:53 +0200
commit64944e1fa72f346f1161da60c033de2e10513bea (patch)
tree12f668bf4024365311dd46bd3dc904f57e00f8fa /tclap-1.2.1/include/tclap/ValuesConstraint.h
parenta0b06e2a9b466cfcc6f6810a66d9522a56872cbb (diff)
downloadaudiomanager-64944e1fa72f346f1161da60c033de2e10513bea.tar.gz
* implemend command line options for plugins. rework of command line
* add tclap as template library * implement bug 344 Signed-off-by: Christian Linke <christian.linke@bmw.de>
Diffstat (limited to 'tclap-1.2.1/include/tclap/ValuesConstraint.h')
-rw-r--r--tclap-1.2.1/include/tclap/ValuesConstraint.h148
1 files changed, 148 insertions, 0 deletions
diff --git a/tclap-1.2.1/include/tclap/ValuesConstraint.h b/tclap-1.2.1/include/tclap/ValuesConstraint.h
new file mode 100644
index 0000000..cb41f64
--- /dev/null
+++ b/tclap-1.2.1/include/tclap/ValuesConstraint.h
@@ -0,0 +1,148 @@
+
+
+/******************************************************************************
+ *
+ * file: ValuesConstraint.h
+ *
+ * Copyright (c) 2005, Michael E. Smoot
+ * All rights reverved.
+ *
+ * See the file COPYING in the top directory of this distribution for
+ * more information.
+ *
+ * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ *****************************************************************************/
+
+#ifndef TCLAP_VALUESCONSTRAINT_H
+#define TCLAP_VALUESCONSTRAINT_H
+
+#include <string>
+#include <vector>
+#include <tclap/Constraint.h>
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#else
+#define HAVE_SSTREAM
+#endif
+
+#if defined(HAVE_SSTREAM)
+#include <sstream>
+#elif defined(HAVE_STRSTREAM)
+#include <strstream>
+#else
+#error "Need a stringstream (sstream or strstream) to compile!"
+#endif
+
+namespace TCLAP {
+
+/**
+ * A Constraint that constrains the Arg to only those values specified
+ * in the constraint.
+ */
+template<class T>
+class ValuesConstraint : public Constraint<T>
+{
+
+ public:
+
+ /**
+ * Constructor.
+ * \param allowed - vector of allowed values.
+ */
+ ValuesConstraint(std::vector<T>& allowed);
+
+ /**
+ * Virtual destructor.
+ */
+ virtual ~ValuesConstraint() {}
+
+ /**
+ * Returns a description of the Constraint.
+ */
+ virtual std::string description() const;
+
+ /**
+ * Returns the short ID for the Constraint.
+ */
+ virtual std::string shortID() const;
+
+ /**
+ * The method used to verify that the value parsed from the command
+ * line meets the constraint.
+ * \param value - The value that will be checked.
+ */
+ virtual bool check(const T& value) const;
+
+ protected:
+
+ /**
+ * The list of valid values.
+ */
+ std::vector<T> _allowed;
+
+ /**
+ * The string used to describe the allowed values of this constraint.
+ */
+ std::string _typeDesc;
+
+};
+
+template<class T>
+ValuesConstraint<T>::ValuesConstraint(std::vector<T>& allowed)
+: _allowed(allowed),
+ _typeDesc("")
+{
+ for ( unsigned int i = 0; i < _allowed.size(); i++ )
+ {
+
+#if defined(HAVE_SSTREAM)
+ std::ostringstream os;
+#elif defined(HAVE_STRSTREAM)
+ std::ostrstream os;
+#else
+#error "Need a stringstream (sstream or strstream) to compile!"
+#endif
+
+ os << _allowed[i];
+
+ std::string temp( os.str() );
+
+ if ( i > 0 )
+ _typeDesc += "|";
+ _typeDesc += temp;
+ }
+}
+
+template<class T>
+bool ValuesConstraint<T>::check( const T& val ) const
+{
+ if ( std::find(_allowed.begin(),_allowed.end(),val) == _allowed.end() )
+ return false;
+ else
+ return true;
+}
+
+template<class T>
+std::string ValuesConstraint<T>::shortID() const
+{
+ return _typeDesc;
+}
+
+template<class T>
+std::string ValuesConstraint<T>::description() const
+{
+ return _typeDesc;
+}
+
+
+} //namespace TCLAP
+#endif
+