diff --git a/src/lib/advice.hpp b/src/lib/advice.hpp index 8857c2556..78f44b4b0 100644 --- a/src/lib/advice.hpp +++ b/src/lib/advice.hpp @@ -128,31 +128,30 @@ namespace advice { /* == Adapter interface for use within the Index == */ + + void + setSolution (PointOfAdvice* solution =0) + { + resolution_ = solution; + } + const PointOfAdvice* + getSolution () const + { + return resolution_; + } + + Binding::Matcher + getMatcher () const + { + return pattern_; + } + friend HashVal hash_value (PointOfAdvice const& entry) { return hash_value (entry.pattern_); } - - friend const Binding::Matcher - getMatcher (PointOfAdvice const& entry) - { - return entry.pattern_; - } - - friend const PointOfAdvice* - getSolution (PointOfAdvice const& entry) - { - return entry.resolution_; - } - - friend void - setSolution (PointOfAdvice* entry, PointOfAdvice* solution =0) - { - REQUIRE (entry); - entry->resolution_ = solution; - } }; @@ -226,7 +225,7 @@ namespace advice { Provision (Provision const& o) : AdviceLink(o) { - setSolution (this, NULL ); + setSolution ( NULL ); } Provision& @@ -235,7 +234,7 @@ namespace advice { if (!isSameObject(*this, o)) { AdviceLink::operator= (o); - setSolution (this, NULL ); + setSolution ( NULL ); } } @@ -297,7 +296,7 @@ namespace advice { : PointOfAdvice(refPoint) , theAdvice_(advice_given) { - setSolution (this, this); // not used currently (5/10) + this->setSolution (this); // not used currently (5/10) } friend class Provision; @@ -345,7 +344,7 @@ namespace advice { Provision::maybe_rePublish () { typedef const ActiveProvision AdviceProvision; - AdviceProvision* solution = static_cast (getSolution (*this)); + AdviceProvision* solution = static_cast (getSolution()); if (solution) // create copy of the data holder, using the new binding maybe_deallocateOld ( @@ -398,7 +397,7 @@ namespace advice { AD const& getAdvice() const { - AdviceProvision* solution = static_cast (getSolution (*this)); + AdviceProvision* solution = static_cast (this->getSolution()); if (!solution) return this->handleMissingSolution(); else diff --git a/src/lib/advice/advice.cpp b/src/lib/advice/advice.cpp index 538deed41..6d0e32b06 100644 --- a/src/lib/advice/advice.cpp +++ b/src/lib/advice/advice.cpp @@ -171,8 +171,8 @@ namespace advice { const PointOfAdvice* AdviceLink::publishProvision (PointOfAdvice* newProvision) { - const PointOfAdvice* previousProvision (getSolution (*this)); - setSolution (this, newProvision); + const PointOfAdvice* previousProvision (getSolution()); + this->setSolution (newProvision); if (!previousProvision && newProvision) aSys().addProvision (*newProvision); @@ -198,8 +198,8 @@ namespace advice { const PointOfAdvice* AdviceLink::discardSolutions () { - const PointOfAdvice* existingProvision (getSolution (*this)); - setSolution (this, NULL ); + const PointOfAdvice* existingProvision (getSolution()); + this->setSolution ( NULL ); if (existingProvision) aSys().removeProvision (*existingProvision); return existingProvision; diff --git a/src/lib/advice/index.hpp b/src/lib/advice/index.hpp index 610f793a1..7d3b07fc0 100644 --- a/src/lib/advice/index.hpp +++ b/src/lib/advice/index.hpp @@ -31,12 +31,12 @@ ** This header is intended to be incorporated as part of the advice system implementation (advice.cpp). ** It is \em not usable as an external interface. But it is written in a rather self-contained manner, ** in order to be testable in isolation. To this end, the actual PointOfAdvice entities being organised - ** by this index datastructure remain abstract (defined as template parameter). As link for dealing - ** with those entities, we employ free functions to be picked up by ADL + ** by this index datastructure remain abstract (defined as template parameter), and are only manipulated + ** through the following functions: ** - \c hash_value(POA) - ** - \c getMatcher(POA) - ** - \c getSolution(POA) - ** - \c setSolution(POA,solution) + ** - \c POA::getMatcher() + ** - \c POA::getSolution() + ** - \c POA::setSolution(solution*) ** ** \par implementation notes ** The advice binding index is implemented by two hashtables holding Binding::Matcher entries. @@ -129,7 +129,7 @@ namespace advice { * the index allows to add, modify and remove entities of these * two kinds. Each of these mutating operations immediately * re-computes the advice solutions and publishes the results - * by invoking the free function \c setSolution(POA) for the + * by invoking the \c setSolution() function on the * corresponding PointOfAdvice entity. * * @note element \em identity is defined in terms of pointing @@ -159,7 +159,7 @@ namespace advice { { explicit Entry (POA& elm) - : pair (getMatcher(elm), &elm) + : pair (elm.getMatcher(), &elm) { } // using default-copy, thus assuming copy is NO_THROW @@ -263,7 +263,7 @@ namespace advice { find_latest_solution (POA& requestElm) { typedef typename EntryList::reverse_iterator RIter; - Binding::Matcher pattern (getMatcher (requestElm)); + Binding::Matcher pattern (requestElm.getMatcher()); for (RIter ii=this->elms_.rbegin(); ii!=this->elms_.rend(); ++ii ) @@ -280,9 +280,9 @@ namespace advice { if (solution) // found the most recent advice provision satisfying the (new) request // thus publish this new advice solution into the request object - setSolution (&requestElm, solution); + requestElm.setSolution (solution); else - setSolution (&requestElm, NULL ); + requestElm.setSolution ( NULL ); // report "no solution" which causes a default solution to be used } }; @@ -293,20 +293,20 @@ namespace advice { void publish_all_solutions (POA& provisionElm) { - Binding::Matcher pattern (getMatcher (provisionElm)); + Binding::Matcher pattern (provisionElm.getMatcher()); for (EIter ii=this->elms_.begin(); ii!=this->elms_.end(); ++ii ) if (pattern.matches (ii->first)) // the given (new) advice provision satisfies this request // thus publish this new advice solution into the request object - setSolution (ii->second, &provisionElm); + ii->second->setSolution (&provisionElm); } void retract_all_solutions (POA const& oldProv, ProvisionCluster& possibleReplacementSolutions) { - Binding::Matcher pattern (getMatcher (oldProv)); + Binding::Matcher pattern (oldProv.getMatcher()); for (EIter ii=this->elms_.begin(); ii!=this->elms_.end(); ++ii ) @@ -319,13 +319,13 @@ namespace advice { void rewrite_all_solutions (POA const& oldProv, POA& newProv, ProvisionCluster& possibleReplacementSolutions) { - Binding::Matcher oldPattern (getMatcher (oldProv)); - Binding::Matcher newPattern (getMatcher (newProv)); + Binding::Matcher oldPattern (oldProv.getMatcher()); + Binding::Matcher newPattern (newProv.getMatcher ()); for (EIter ii=this->elms_.begin(); ii!=this->elms_.end(); ++ii ) if (newPattern.matches (ii->first)) - setSolution (ii->second, &newProv); + ii->second->setSolution (&newProv); else if (oldPattern.matches (ii->first)) possibleReplacementSolutions.publish_latest_solution (*(ii->second)); @@ -577,11 +577,11 @@ namespace advice { { verify_Entry (e,hash); POA& request = *(e.second); - const POA* solution (getSolution (request)); + const POA* solution (request.getSolution()); if (solution && hasProvision(*solution)) { POA* currentSolution = provisionEntries_[hash].find_latest_solution (request); - VERIFY (e.first.matches (getMatcher(*solution)), "stored advice solution not supported by binding match"); + VERIFY (e.first.matches (solution->getMatcher()),"stored advice solution not supported by binding match"); VERIFY (bool(currentSolution), "unable to reproduce stored solution with the current provisions") VERIFY (solution == currentSolution, "stored advice solution isn't the topmost solution for this request") } diff --git a/tests/lib/advice/advice-index-test.cpp b/tests/lib/advice/advice-index-test.cpp index c098552c7..1e516c958 100644 --- a/tests/lib/advice/advice-index-test.cpp +++ b/tests/lib/advice/advice-index-test.cpp @@ -70,30 +70,15 @@ namespace test { /* == Adapter interface for use within the Index == */ + void setSolution (TestPOA* p) { solution_ = p; } + const TestPOA* getSolution () const { return solution_;} + Binding::Matcher getMatcher () const { return pattern_; } + friend HashVal hash_value (TestPOA const& entry) { return hash_value (entry.pattern_); } - - friend const Binding::Matcher - getMatcher (TestPOA const& entry) - { - return entry.pattern_; - } - - friend const TestPOA* - getSolution (TestPOA const& entry) - { - return entry.solution_; - } - - friend void - setSolution (TestPOA* entry, TestPOA* solution =0) - { - REQUIRE (entry); - entry->solution_ = solution; - } };