From f18aa4f90896805ce64d2299ab1c909d8ba94b70 Mon Sep 17 00:00:00 2001 From: randomdan Date: Fri, 26 Aug 2011 18:00:16 +0000 Subject: Slash XML bloat with parameters and remove a pointless --- project2/cache.cpp | 4 ++-- project2/iHaveParameters.cpp | 18 +++++------------- project2/iHaveParameters.h | 9 +-------- project2/sqlMergeTask.cpp | 2 +- project2/variables-modlookup.cpp | 2 +- project2/variables.h | 2 -- 6 files changed, 10 insertions(+), 27 deletions(-) diff --git a/project2/cache.cpp b/project2/cache.cpp index 32dc3c5..1dc435f 100644 --- a/project2/cache.cpp +++ b/project2/cache.cpp @@ -31,11 +31,11 @@ void Cache::applyKeys(const boost::function2 & f, const IHaveParameters * ps) const { BOOST_FOREACH(const IHaveParameters::Parameters::value_type & p, allParameters()) { - f(p.first, p.second->value()); + f(p.first, p.second); } if (inherit) { BOOST_FOREACH(const IHaveParameters::Parameters::value_type & p, ps->allParameters()) { - f(p.first, p.second->value()); + f(p.first, p.second); } } } diff --git a/project2/iHaveParameters.cpp b/project2/iHaveParameters.cpp index e254a4f..e4f456a 100644 --- a/project2/iHaveParameters.cpp +++ b/project2/iHaveParameters.cpp @@ -7,11 +7,9 @@ IHaveParameters::Stack IHaveParameters::scope; IHaveParameters::IHaveParameters(const xmlpp::Element * p) { - BOOST_FOREACH(xmlpp::Node * node, p->find("parameters/param")) { - const xmlpp::Element * elem = dynamic_cast(node); - if (elem) { - ParameterPtr p = new Parameter(elem); - parameters[p->name] = p; + BOOST_FOREACH(xmlpp::Node * node, p->find("parameters/*")) { + if (const xmlpp::Element * pelem = dynamic_cast(node)) { + parameters.insert(Parameters::value_type(pelem->get_name(), Variable(pelem, boost::optional()))); } } } @@ -20,18 +18,12 @@ IHaveParameters::~IHaveParameters() { } -IHaveParameters::Parameter::Parameter(const xmlpp::Element * p) : - name(p->get_attribute_value("name")), - value(p, "value") -{ -} - VariableType IHaveParameters::getParameter(const Glib::ustring & name) const { Parameters::const_iterator i = parameters.find(name); if (i != parameters.end()) { - return i->second->value; + return i->second; } throw ParamNotFound(name); } @@ -55,7 +47,7 @@ IHaveParameters::getScopedParameter(const Glib::ustring & name) for(Stack::const_reverse_iterator ihp = scope.rbegin(); ihp != scope.rend(); ihp++) { Parameters::const_iterator i = (*ihp)->parameters.find(name); if (i != (*ihp)->parameters.end()) { - return i->second->value; + return i->second; } } throw ParamNotFound(name); diff --git a/project2/iHaveParameters.h b/project2/iHaveParameters.h index 51378ee..28dbf7d 100644 --- a/project2/iHaveParameters.h +++ b/project2/iHaveParameters.h @@ -10,14 +10,7 @@ /// Mix-in base class to store parameters for component execution class IHaveParameters { public: - class Parameter : public virtual IntrusivePtrBase { - public: - Parameter(const xmlpp::Element * p); - const Glib::ustring name; - const Variable value; - }; - typedef boost::intrusive_ptr ParameterPtr; - typedef std::map Parameters; + typedef std::map Parameters; IHaveParameters(const xmlpp::Element * p); virtual ~IHaveParameters() = 0; diff --git a/project2/sqlMergeTask.cpp b/project2/sqlMergeTask.cpp index 2c38bf1..09657f8 100644 --- a/project2/sqlMergeTask.cpp +++ b/project2/sqlMergeTask.cpp @@ -31,7 +31,7 @@ class SqlMergeInsert : IHaveParameters, public Task { void execute() const { unsigned int col = 0; BOOST_FOREACH(const Parameters::value_type & v, parameters) { - boost::apply_visitor(SqlVariableBinder(insert, col++), v.second->value); + boost::apply_visitor(SqlVariableBinder(insert, col++), v.second); } insert->execute(); } diff --git a/project2/variables-modlookup.cpp b/project2/variables-modlookup.cpp index 026362c..85a1fbe 100644 --- a/project2/variables-modlookup.cpp +++ b/project2/variables-modlookup.cpp @@ -46,7 +46,7 @@ class VariableLookup : public VariableImplDyn, public RowProcessor { Key k; k.reserve(parameters.size()); BOOST_FOREACH(const Parameters::value_type & p, parameters) { - k.push_back(p.second->value()); + k.push_back(p.second); } return safeMapFind(map, k)->second; } diff --git a/project2/variables.h b/project2/variables.h index 54ac52c..6dbbf2b 100644 --- a/project2/variables.h +++ b/project2/variables.h @@ -80,7 +80,6 @@ class Variable { Variable(const xmlpp::Element *, const boost::optional &); Variable(VariableType def); - static Variable makeFromCode(const Glib::ustring & s); static Variable makeParent(const Glib::ustring & name, bool attr, unsigned int depth); operator VariableType () const { return var->value(); } @@ -89,7 +88,6 @@ class Variable { private: Variable(VariableImpl *); friend class VariableParse; - static VariableImplPtr create(const Glib::ustring & s); VariableImplPtr var; }; -- cgit v1.2.3