diff options
-rw-r--r-- | project2/Jamfile.jam | 2 | ||||
-rw-r--r-- | project2/iterate.cpp | 1 | ||||
-rw-r--r-- | project2/rowSet.cpp | 21 | ||||
-rw-r--r-- | project2/rowSet.h | 5 | ||||
-rw-r--r-- | project2/rowUser.cpp | 10 | ||||
-rw-r--r-- | project2/rowUser.h | 13 | ||||
-rw-r--r-- | project2/rowView.cpp | 1 | ||||
-rw-r--r-- | project2/variables-modconfig.cpp | 8 | ||||
-rw-r--r-- | project2/variables-modlookup.cpp | 5 | ||||
-rw-r--r-- | project2/variables-modparam.cpp | 20 | ||||
-rw-r--r-- | project2/variables-modsession.cpp | 7 | ||||
-rw-r--r-- | project2/variables-moduri.cpp | 20 | ||||
-rw-r--r-- | project2/variables.cpp | 105 | ||||
-rw-r--r-- | project2/variables.h | 13 | ||||
-rw-r--r-- | project2/xslRows.cpp | 5 |
15 files changed, 65 insertions, 171 deletions
diff --git a/project2/Jamfile.jam b/project2/Jamfile.jam index 035609b..5eb1c27 100644 --- a/project2/Jamfile.jam +++ b/project2/Jamfile.jam @@ -58,7 +58,7 @@ lib p2common : iterate.cpp paramChecker.cpp presenter.cpp rawView.cpp logger.cpp if.cpp xmlScriptParser.cpp viewHost.cpp sourceObject.cpp task.cpp variables.cpp variableConvert.cpp view.cpp xmlObjectLoader.cpp exceptions.cpp sessionClearTask.cpp session.cpp sessionSetTask.cpp commonObjects.cpp xmlPresenter.cpp taskHost.cpp checkHost.cpp - rowView.cpp rowSet.cpp rowUser.cpp rowProcessor.cpp config.cpp fileStrmVarWriter.cpp noOutputExecute.cpp + rowView.cpp rowSet.cpp rowProcessor.cpp config.cpp fileStrmVarWriter.cpp noOutputExecute.cpp transform.cpp transformHtml.cpp transformText.cpp definedColumns.cpp structExceptHandling.cpp validDateCheck.cpp variables-modconfig.cpp variables-modlookup.cpp diff --git a/project2/iterate.cpp b/project2/iterate.cpp index 1f2b12f..795b356 100644 --- a/project2/iterate.cpp +++ b/project2/iterate.cpp @@ -29,7 +29,6 @@ void Iterate::rowReady() const { executeChildren(); - source->rowChanged(); } void diff --git a/project2/rowSet.cpp b/project2/rowSet.cpp index 1be3547..cfbb9cf 100644 --- a/project2/rowSet.cpp +++ b/project2/rowSet.cpp @@ -1,5 +1,4 @@ #include "rowSet.h" -#include "rowUser.h" #include "commonObjects.h" #include "logger.h" #include "variables.h" @@ -19,18 +18,6 @@ RowSet::~RowSet() } void -RowSet::use(const RowUser * r) const -{ - rowUsers.insert(r); -} - -void -RowSet::finish(const RowUser * r) const -{ - rowUsers.erase(r); -} - -void RowSet::beginRow(const RowSet * r) { stack.push_back(r); @@ -46,14 +33,6 @@ RowSet::endRow(const RowSet * r) stack.pop_back(); } -void -RowSet::rowChanged() const -{ - BOOST_FOREACH(const RowUser * ru, rowUsers) { - ru->rowChanged(); - } -} - VariableType RowSet::getRowNum() const { diff --git a/project2/rowSet.h b/project2/rowSet.h index 52edd76..a907cd2 100644 --- a/project2/rowSet.h +++ b/project2/rowSet.h @@ -9,7 +9,6 @@ class RowProcessor; class RowSet; -class RowUser; class VariableType; typedef boost::intrusive_ptr<RowSet> RowSetPtr; typedef boost::intrusive_ptr<const RowSet> ConstRowSetPtr; @@ -35,21 +34,17 @@ class RowSet : public SourceObject { virtual bool isNull(const Glib::ustring & id) const = 0; VariableType getRowNum() const; virtual void execute(const RowProcessor *) const = 0; - void use(const RowUser * r) const; - void finish(const RowUser * r) const; virtual RowAttribute resolveAttr(const Glib::ustring & attrName) const; static const RowValuesStack & Stack() { return stack; } static void beginRow(const RowSet * r); static void endRow(const RowSet * r); - void rowChanged() const; protected: mutable unsigned long int rowNum; private: static RowValuesStack stack; - mutable std::set<const RowUser *> rowUsers; }; #endif diff --git a/project2/rowUser.cpp b/project2/rowUser.cpp deleted file mode 100644 index 2557af1..0000000 --- a/project2/rowUser.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "rowUser.h" - -RowUser::RowUser() -{ -} - -RowUser::~RowUser() -{ -} - diff --git a/project2/rowUser.h b/project2/rowUser.h deleted file mode 100644 index 9597807..0000000 --- a/project2/rowUser.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef ROWUSER_H -#define ROWUSER_H - -class RowUser { - public: - RowUser(); - virtual ~RowUser() = 0; - - virtual void rowChanged() const = 0; -}; - -#endif - diff --git a/project2/rowView.cpp b/project2/rowView.cpp index cdbe071..8e22c4b 100644 --- a/project2/rowView.cpp +++ b/project2/rowView.cpp @@ -51,7 +51,6 @@ RowView::rowReady() const } } executeChildren(); - source->rowChanged(); presenter->popSub(); } diff --git a/project2/variables-modconfig.cpp b/project2/variables-modconfig.cpp index 935e2d6..88fddd4 100644 --- a/project2/variables-modconfig.cpp +++ b/project2/variables-modconfig.cpp @@ -11,13 +11,9 @@ class VariableConfig : public VariableImplDyn { name(e->get_attribute_value("name")) { } - const VariableType & value() const + VariableType value() const { - if (!cacheValid) { - cache = ApplicationEngine::getCurrent()->getCurrentConfig()->getValue(name); - cacheValid = true; - } - return cache; + return ApplicationEngine::getCurrent()->getCurrentConfig()->getValue(name); } private: const Glib::ustring name; diff --git a/project2/variables-modlookup.cpp b/project2/variables-modlookup.cpp index e020d9a..24c4167 100644 --- a/project2/variables-modlookup.cpp +++ b/project2/variables-modlookup.cpp @@ -64,7 +64,7 @@ class VariableLookup : public VariableImplDyn, public RowProcessor { loader.supportedStorers.insert(Storer::into(&rowSets)); loader.collectAll(e, false); } - const VariableType & value() const + VariableType value() const { if (map.empty()) { fillCache(); @@ -76,8 +76,7 @@ class VariableLookup : public VariableImplDyn, public RowProcessor { } Map::const_iterator i = map.find(k); if (i != map.end()) { - cache = i->second; - return cache; + return i->second; } throw NotFound(); } diff --git a/project2/variables-modparam.cpp b/project2/variables-modparam.cpp index a932412..0b205db 100644 --- a/project2/variables-modparam.cpp +++ b/project2/variables-modparam.cpp @@ -11,21 +11,17 @@ class VariableParam : public VariableImplDyn { name(e->get_attribute_value("name")) { } - const VariableType & value() const + VariableType value() const { - if (!cacheValid) { - try { - cache = ApplicationEngine::getCurrent()->env()->getParamQuery(name); - } - catch (ParamNotFound) { - if (!defaultValue) { - throw; - } - cache = (*defaultValue)(); + try { + return ApplicationEngine::getCurrent()->env()->getParamQuery(name); + } + catch (ParamNotFound) { + if (!defaultValue) { + throw; } - cacheValid = true; + return (*defaultValue)(); } - return cache; } private: const Glib::ustring name; diff --git a/project2/variables-modsession.cpp b/project2/variables-modsession.cpp index 0d39695..963a105 100644 --- a/project2/variables-modsession.cpp +++ b/project2/variables-modsession.cpp @@ -11,18 +11,17 @@ class VariableSession : public VariableImplDyn { name(e->get_attribute_value("name")) { } - const VariableType & value() const + VariableType value() const { try { - cache = ApplicationEngine::getCurrent()->session()->GetValue(name); + return ApplicationEngine::getCurrent()->session()->GetValue(name); } catch (Session::VariableNotFound) { if (!defaultValue) { throw; } - cache = (*defaultValue)(); + return (*defaultValue)(); } - return cache; } private: const Glib::ustring name; diff --git a/project2/variables-moduri.cpp b/project2/variables-moduri.cpp index f6793e1..00fb7bf 100644 --- a/project2/variables-moduri.cpp +++ b/project2/variables-moduri.cpp @@ -11,21 +11,17 @@ class VariableUri : public VariableImplDyn { index(atoi(e->get_attribute_value("index").c_str())) { } - const VariableType & value() const + VariableType value() const { - if (!cacheValid) { - try { - cache = ApplicationEngine::getCurrent()->env()->getParamUri(index); - } - catch (UriElementOutOfRange) { - if (!defaultValue) { - throw; - } - cache = (*defaultValue)(); + try { + return ApplicationEngine::getCurrent()->env()->getParamUri(index); + } + catch (UriElementOutOfRange) { + if (!defaultValue) { + throw; } - cacheValid = true; + return (*defaultValue)(); } - return cache; } private: unsigned int index; diff --git a/project2/variables.cpp b/project2/variables.cpp index 4e18fc0..516e187 100644 --- a/project2/variables.cpp +++ b/project2/variables.cpp @@ -4,7 +4,6 @@ #include "exceptions.h" #include "appEngine.h" #include "session.h" -#include "rowUser.h" #include "rowSet.h" #include <libxml++/nodes/textnode.h> #include <stdexcept> @@ -132,117 +131,79 @@ class VariableLiteral : public VariableImpl { } } - virtual const VariableType & value() const { return val; } + virtual VariableType value() const { return val; } private: VariableType val; }; DECLARE_COMPONENT_LOADER("literal", VariableLiteral, VariableLoader); DECLARE_CUSTOM_COMPONENT_LOADER("", VariableLiteralDef, VariableLoaderImpl<VariableLiteral>, VariableLoader); -VariableImplDyn::VariableImplDyn(const xmlpp::Element * e) : - cacheValid(false) +VariableImplDyn::VariableImplDyn(const xmlpp::Element * e) { - try { - if (e) { - defaultValue = Variable(e, "default"); - } - } - catch (NoVariableDefinition) { - // That's cool... no default + if (e) { + defaultValue = Variable(e, "default", false); } } -static void assignHelper(VariableType & dest, const VariableType & src) { - dest = src; -} - /// Variable implementation to access fields in row sets -class VariableParent : public VariableImplDyn, public RowUser { +class VariableParent : public VariableImplDyn { public: - VariableParent(const xmlpp::Element * e, const RowUser * d = NULL) : + VariableParent(const xmlpp::Element * e) : VariableImplDyn(e), - row(NULL), depth(atoi(e->get_attribute_value("depth").c_str())), attr(e->get_attribute("attribute")), - name(attr ? e->get_attribute_value("attribute") : e->get_attribute_value("name")), - dep(d) + name(attr ? e->get_attribute_value("attribute") : e->get_attribute_value("name")) { } VariableParent(const Glib::ustring & n, bool a, unsigned int d) : VariableImplDyn(NULL), - row(NULL), depth(d), attr(a), - name(n), - dep(NULL) + name(n) { } - ~VariableParent() - { - if (row) { - row->finish(this); - if (dep) { - row->finish(dep); - } - } - } - const VariableType & value() const + VariableType value() const { - if (!cacheValid) { - try { - if (!row) { - RowSet::RowValuesStack::const_reverse_iterator r = RowSet::Stack().rbegin(); - for (size_t p = depth; p--; r++) ; - if (r == RowSet::Stack().rend()) { - throw RowSet::ParentOutOfRange(depth); - } - row = *r; - row->use(this); - if (dep) { - row->use(dep); - } - bind(); + try { + if (!getValue) { + RowSet::RowValuesStack::const_reverse_iterator r = RowSet::Stack().rbegin(); + for (size_t p = depth; p--; r++) ; + if (r == RowSet::Stack().rend()) { + throw RowSet::ParentOutOfRange(depth); } - getValue(cache, row); + ; + bind(*r); } - catch (RowSet::ParentOutOfRange) { - if (!defaultValue) { - throw; - } - cache = (*defaultValue)(); + return getValue(); + } + catch (RowSet::ParentOutOfRange) { + if (!defaultValue) { + throw; } - catch (RowSet::FieldDoesNotExist) { - if (!defaultValue) { - throw; - } - cache = (*defaultValue)(); + return (*defaultValue)(); + } + catch (RowSet::FieldDoesNotExist) { + if (!defaultValue) { + throw; } - cacheValid = true; + return (*defaultValue)(); } - return cache; - } - void rowChanged() const - { - cacheValid = false; } protected: - void bind() const + void bind(ConstRowSetPtr row) const { if (attr) { - getValue = boost::bind(&assignHelper, _1, boost::bind(row->resolveAttr(name))); + getValue = boost::bind(row->resolveAttr(name)); } else { typedef VariableType (RowSet::*gCV)(const Glib::ustring &) const; - getValue = boost::bind(&assignHelper, _1, - boost::bind((gCV)&RowSet::getCurrentValue, _2, name)); + getValue = boost::bind((gCV)&RowSet::getCurrentValue, row, name); } } - mutable ConstRowSetPtr row; const size_t depth; const bool attr; const Glib::ustring name; - const RowUser * dep; - mutable boost::function2<void, VariableType &, ConstRowSetPtr> getValue; + mutable boost::function0<VariableType> getValue; }; DECLARE_COMPONENT_LOADER("parent", VariableParent, VariableLoader); @@ -253,7 +214,7 @@ class VariableFixed : public VariableImpl { var(v) { } - const VariableType & value() const + VariableType value() const { return var; } diff --git a/project2/variables.h b/project2/variables.h index 92aac4b..a22ebf4 100644 --- a/project2/variables.h +++ b/project2/variables.h @@ -13,7 +13,6 @@ #include <boost/variant.hpp> #include <boost/shared_ptr.hpp> -class RowUser; class Null { }; typedef boost::variant< Null, @@ -63,7 +62,7 @@ class VariableType : public _VT { /// Base class for Project2 variable accessors class VariableImpl : public IntrusivePtrBase { public: - virtual const VariableType & value() const = 0; + virtual VariableType value() const = 0; protected: virtual ~VariableImpl() = 0; @@ -79,13 +78,13 @@ class Variable { static Variable makeFromCode(const Glib::ustring & s); static Variable makeParent(const Glib::ustring & name, bool attr, unsigned int depth); - operator const VariableType & () const { return var->value(); } - const VariableType & operator()() const { return var->value(); } + operator VariableType () const { return var->value(); } + VariableType operator()() const { return var->value(); } private: Variable(VariableImpl *); friend class VariableParse; - static VariableImplPtr create(const Glib::ustring & s, RowUser * dep = NULL); + static VariableImplPtr create(const Glib::ustring & s); VariableImplPtr var; }; @@ -93,11 +92,9 @@ class Variable { class VariableImplDyn : public VariableImpl { public: VariableImplDyn(const xmlpp::Element * e); - virtual const VariableType & value() const = 0; + virtual VariableType value() const = 0; protected: - mutable VariableType cache; - mutable bool cacheValid; boost::optional<Variable> defaultValue; }; diff --git a/project2/xslRows.cpp b/project2/xslRows.cpp index 9c4ce98..999f196 100644 --- a/project2/xslRows.cpp +++ b/project2/xslRows.cpp @@ -98,11 +98,12 @@ XslRows::execute(const RowProcessor * rp) const xpathCtx->node = rowRoot; values.clear(); BOOST_FOREACH(const FilterView::XPaths::value_type & xp, fv->xpaths) { - if (boost::get<Null>(&xp.second())) { + VariableType path(xp.second()); + if (boost::get<Null>(&path)) { values[xp.first] = Null(); continue; } - xmlXPathObjectSPtr xpathObjI = xmlXPathObjectSPtr(xmlXPathEvalExpression(xp.second(), xpathCtx.get()), xmlXPathFreeObject); + xmlXPathObjectSPtr xpathObjI = xmlXPathObjectSPtr(xmlXPathEvalExpression(path, xpathCtx.get()), xmlXPathFreeObject); if (!xpathObjI) { throw XpathEvalError(xmlGetLastError()->message); } |