From 6886ca3542907f498eb6c30aa76474f15e7afc39 Mon Sep 17 00:00:00 2001 From: randomdan Date: Fri, 29 Mar 2013 21:37:22 +0000 Subject: Split variable and variabletype code into separate files Use variabletype in populating options data Add code for guessing the type of some input data --- project2/cgi/cgiEnvironment.cpp | 2 +- project2/cgi/cgiEnvironment.h | 2 +- project2/common/options.cpp | 9 +- project2/common/options.h | 36 +++-- project2/common/pch.hpp | 1 + project2/common/variableConvert.cpp | 4 +- project2/common/variableType.cpp | 258 ++++++++++++++++++++++++++++++++ project2/common/variableType.h | 105 +++++++++++++ project2/common/variables.cpp | 244 ------------------------------ project2/common/variables.h | 97 +----------- project2/common/variables/config.cpp | 4 +- project2/console/consoleEnvironment.cpp | 2 +- project2/streams/streamNvpRows.cpp | 3 +- 13 files changed, 401 insertions(+), 366 deletions(-) create mode 100644 project2/common/variableType.cpp create mode 100644 project2/common/variableType.h diff --git a/project2/cgi/cgiEnvironment.cpp b/project2/cgi/cgiEnvironment.cpp index 6462f5c..048f7d7 100644 --- a/project2/cgi/cgiEnvironment.cpp +++ b/project2/cgi/cgiEnvironment.cpp @@ -193,7 +193,7 @@ HostnamePlatformIdentifier::paramRequired() const } void -HostnamePlatformIdentifier::consume(const Glib::ustring & p, const Glib::ustring & r) const +HostnamePlatformIdentifier::consume(const Glib::ustring & p, const VariableType & r) const { if (!platform && Glib::Regex::create(r, Glib::REGEX_CASELESS | Glib::REGEX_DOTALL)->match(Environment::getCurrent()->getServerName())) { platform = new Glib::ustring(p); diff --git a/project2/cgi/cgiEnvironment.h b/project2/cgi/cgiEnvironment.h index 176ca8d..c09f5a9 100644 --- a/project2/cgi/cgiEnvironment.h +++ b/project2/cgi/cgiEnvironment.h @@ -21,7 +21,7 @@ class HostnamePlatformIdentifier : public Options::Target { virtual ~HostnamePlatformIdentifier(); void reset() const; bool paramRequired() const; - void consume(const Glib::ustring &, const Glib::ustring &) const; + void consume(const Glib::ustring &, const VariableType &) const; const Glib::ustring & derivedPlatform() const; private: mutable Glib::ustring * platform; diff --git a/project2/common/options.cpp b/project2/common/options.cpp index 94ae861..60fd7cd 100644 --- a/project2/common/options.cpp +++ b/project2/common/options.cpp @@ -11,7 +11,7 @@ class NamedOption : public Options::Option { desc(d) { } - void consume(const Glib::ustring & n, const Glib::ustring & p, const Glib::ustring & v) const { + void consume(const Glib::ustring & n, const Glib::ustring & p, const VariableType & v) const { if (n == id) { target->consume(p, v); } @@ -44,7 +44,7 @@ class OptionAlias : public Options::Option { target(t) { } - void consume(const Glib::ustring & a, const Glib::ustring & p, const Glib::ustring & v) const { + void consume(const Glib::ustring & a, const Glib::ustring & p, const VariableType & v) const { if (a == alias) { target->target->consume(p, v); } @@ -108,12 +108,13 @@ Options::reset() const } void -Options::consume(const Glib::ustring & n, const Glib::ustring & p, const Glib::ustring & v) const +Options::consume(const Glib::ustring & n, const Glib::ustring & p, const VariableType & v) const { BOOST_FOREACH(const OptionPtr & o, options) { o->consume(n, p, v); } } + const Options::Option * Options::find(const Glib::ustring & n) const { BOOST_FOREACH(const OptionPtr & o, options) { @@ -130,7 +131,7 @@ Options::InstanceTarget::InstanceTarget() : } void -Options::InstanceTarget::consume(const Glib::ustring & p, const Glib::ustring & v) const +Options::InstanceTarget::consume(const Glib::ustring & p, const VariableType & v) const { if (ts != Platform && p.empty()) { assign(v); diff --git a/project2/common/options.h b/project2/common/options.h index 93c6aa5..8b9e9a0 100644 --- a/project2/common/options.h +++ b/project2/common/options.h @@ -7,6 +7,7 @@ #include #include #include +#include "variableType.h" #if !__GNUC_PREREQ(4,7) // If gcc_version >= 4.0 @@ -41,7 +42,7 @@ class Options { public: virtual void reset() const = 0; virtual bool paramRequired() const = 0; - virtual void consume(const Glib::ustring & platform, const Glib::ustring & value) const = 0; + virtual void consume(const Glib::ustring & platform, const VariableType & value) const = 0; }; typedef boost::intrusive_ptr TargetPtr; @@ -51,9 +52,9 @@ class Options { bool paramRequired() const { return true; } - void consume(const Glib::ustring & platform, const Glib::ustring & value) const; + void consume(const Glib::ustring & platform, const VariableType & value) const; protected: - virtual void assign(const Glib::ustring & value) const = 0; + virtual void assign(const VariableType & value) const = 0; mutable TargetState ts; }; @@ -71,18 +72,27 @@ class Options { ts = Default; *target = defValue; } - void assign(const Glib::ustring & value) const { + void assign(const VariableType & value) const { doAssign(value); } protected: T * target; private: template - void doAssign(const Glib::ustring & value, typename boost::disable_if, dummy>::type = 0) const { - *target = boost::lexical_cast(value); + void doAssign(const VariableType & value, + typename boost::disable_if, dummy>::type = 0, + typename boost::disable_if, dummy>::type = 0) const { + *target = boost::lexical_cast(value.as()); } template - void doAssign(const Glib::ustring & value, typename boost::enable_if, dummy>::type = 0) const { + void doAssign(const VariableType & value, + typename boost::enable_if, dummy>::type = 0) const { + *target = value.as(); + } + template + void doAssign(const VariableType & value, + typename boost::disable_if, dummy>::type = 0, + typename boost::enable_if, dummy>::type = 0) const { *target = value; } D defValue; @@ -98,18 +108,18 @@ class Options { ts = Default; target->clear(); } - void assign(const Glib::ustring & value) const { + void assign(const VariableType & value) const { doAssign(value); } protected: VofT * target; private: template - void doAssign(const Glib::ustring & value, typename boost::disable_if, dummy>::type = 0) const { - target->push_back(boost::lexical_cast(value)); + void doAssign(const VariableType & value, typename boost::disable_if, dummy>::type = 0) const { + target->push_back(boost::lexical_cast(value.as())); } template - void doAssign(const Glib::ustring & value, typename boost::enable_if, dummy>::type = 0) const { + void doAssign(const VariableType & value, typename boost::enable_if, dummy>::type = 0) const { target->push_back(T(value)); } }; @@ -121,7 +131,7 @@ class Options { virtual Glib::ustring name() const = 0; virtual Glib::ustring description() const = 0; virtual bool accepts(const Glib::ustring & name) const = 0; - virtual void consume(const Glib::ustring & name, const Glib::ustring & platform, const Glib::ustring & value) const = 0; + virtual void consume(const Glib::ustring & name, const Glib::ustring & platform, const VariableType & value) const = 0; }; typedef boost::intrusive_ptr