diff --git a/CEP/BB/BBSKernel/include/BBSKernel/MNS/MeqExpr.h b/CEP/BB/BBSKernel/include/BBSKernel/MNS/MeqExpr.h index fc803763558c811fd7d7f82cd794a03b77324af2..b7c06016002639a1e8cbafe519606025c2feed7f 100644 --- a/CEP/BB/BBSKernel/include/BBSKernel/MNS/MeqExpr.h +++ b/CEP/BB/BBSKernel/include/BBSKernel/MNS/MeqExpr.h @@ -70,17 +70,24 @@ public: static void unlink (MeqExprRep* rep) { if (rep != 0 && --rep->itsCount == 0) delete rep; } - // Increment nr of parents. + // Increment number of parents. void incrNParents() { itsNParents++; } + // Decrement the number of parents. void decrNParents() { itsNParents--; } + // Get the current number of parents + const int getParentCount() const + { + return itsNParents; + } + // Recursively set the lowest and highest level of the node as used // in the tree. // Return the number of levels used so far. @@ -120,6 +127,7 @@ public: MeqResultVec& result) { return itsReqId == request.getId() ? *itsResVec : calcResultVec(request,result); } + virtual MeqResultVec getResultVec (const MeqRequest&); // </group> @@ -134,8 +142,8 @@ public: protected: // Add a child to this node. // It also increases NParents in the child. - void addChild(MeqExpr&); - void removeChild(MeqExpr &child); + void addChild(MeqExpr child); + void removeChild(MeqExpr child); private: // Forbid copy and assignment. @@ -159,7 +167,7 @@ private: int itsLevelDone; //# Level the node is handled by some parent. MeqResult* itsResult; //# Possibly cached result MeqResultVec* itsResVec; //# Possibly cached result vector - std::vector<MeqExprRep*> itsChildren; //# All children + std::vector<MeqExpr> itsChildren; //# All children protected: int itsNParents; //# Nr of parents @@ -188,20 +196,40 @@ public: // Assignment (reference semantics). MeqExpr& operator= (const MeqExpr&); + // Is the node empty? + bool isNull() const + { return itsRep == 0; } + + // A MeqExpr is essentially a reference counted shared + // pointer. Two MeqExpr's can be considered equal if both + // reference the same underlying MeqExprRep. + bool operator ==(const MeqExpr &other) + { + return (itsRep == other.itsRep); + } + + + //# -- DELEGATED METHODS -- + // Get the current number of parents + const int getParentCount() const + { + return itsRep->getParentCount(); + } + // Recursively set the lowest and highest level of the node as used // in the tree. // Return the number of levels used so far. int setLevel (int level) { return itsRep->setLevel (level); } - // Is the node empty? - bool isNull() const - { return itsRep == 0; } - // Clear the done flag recursively. void clearDone() { itsRep->clearDone(); } + // At which level is the node done? + int levelDone() const + { return itsRep->levelDone(); } + // Get the nodes at the given level. // By default only nodes with multiple parents are retrieved. // It is used to find the nodes with results to be cached. @@ -236,7 +264,7 @@ public: } #endif -protected: +private: MeqExprRep* itsRep; }; diff --git a/CEP/BB/BBSKernel/src/MNS/MeqExpr.cc b/CEP/BB/BBSKernel/src/MNS/MeqExpr.cc index 89f07cd712c05a0fb22851c14ffee1146017aa6f..74cd53bcd884a8d34e83f538de85857862a551b7 100644 --- a/CEP/BB/BBSKernel/src/MNS/MeqExpr.cc +++ b/CEP/BB/BBSKernel/src/MNS/MeqExpr.cc @@ -49,32 +49,34 @@ MeqExprRep::MeqExprRep() MeqExprRep::~MeqExprRep() { - for(std::vector<MeqExprRep*>::iterator it = itsChildren.begin(); it != itsChildren.end(); ++it) + for(std::vector<MeqExpr>::iterator it = itsChildren.begin(); it != itsChildren.end(); ++it) { - (*it)->decrNParents(); + MeqExprRep childRep = (*it).itsRep; + ASSERT(childRep); + childRep->decrNParents(); } delete itsResult; delete itsResVec; } -void MeqExprRep::addChild (MeqExpr& child) +void MeqExprRep::addChild (MeqExpr child) { MeqExprRep* childRep = child.itsRep; - ASSERT (childRep != 0); - itsChildren.push_back (childRep); + ASSERT(childRep); childRep->incrNParents(); + itsChildren.push_back(child); } -void MeqExprRep::removeChild(MeqExpr &child) +void MeqExprRep::removeChild(MeqExpr child) { - ASSERT(child.itsRep != NULL); - - std::vector<MeqExprRep*>::iterator it = std::find(itsChildren.begin(), itsChildren.end(), child.itsRep); - + std::vector<MeqExpr>::iterator it = std::find(itsChildren.begin(), itsChildren.end(), child); ASSERT(it != itsChildren.end()); - (*it)->decrNParents(); + MeqExprRep childRep = child.itsRep; + ASSERT(childRep); + + childRep->decrNParents(); itsChildren.erase(it); } @@ -86,7 +88,7 @@ int MeqExprRep::setLevel (int level) nrLev = level; itsMaxLevel = level; for (uint i=0; i<itsChildren.size(); ++i) { - nrLev = std::max(nrLev, itsChildren[i]->setLevel (level+1)); + nrLev = std::max(nrLev, itsChildren[i].setLevel (level+1)); } } return nrLev; @@ -99,8 +101,8 @@ void MeqExprRep::clearDone() itsMinLevel = 100000000; for (uint i=0; i<itsChildren.size(); ++i) { // Avoid that a child is cleared multiple times. - if (itsChildren[i]->levelDone() >= 0) { - itsChildren[i]->clearDone(); + if (itsChildren[i].levelDone() >= 0) { + itsChildren[i].clearDone(); } } } @@ -117,8 +119,8 @@ void MeqExprRep::getCachingNodes (std::vector<MeqExprRep*>& nodes, } else if (itsMaxLevel < level) { // Handling the children is needed. for (uint i=0; i<itsChildren.size(); ++i) { - if (itsChildren[i]->levelDone() != level) { - itsChildren[i]->getCachingNodes (nodes, level, all); + if (itsChildren[i].levelDone() != level) { + itsChildren[i].getCachingNodes (nodes, level, all); } } } @@ -184,7 +186,7 @@ MeqResult MeqExprRep::getResult (const MeqRequest& request) vector<MeqResult> res(nrchild); vector<const MeqMatrix*> mat(nrchild); for (int i=0; i<nrchild; ++i) { - res[i] = itsChildren[i]->getResultSynced (request, res[i]); + res[i] = itsChildren[i].getResultSynced (request, res[i]); mat[i] = &res[i].getValue(); } // Calculate the resulting main value. diff --git a/CEP/BB/BBSKernel/src/MNS/MeqExpr.h b/CEP/BB/BBSKernel/src/MNS/MeqExpr.h index fc803763558c811fd7d7f82cd794a03b77324af2..b7c06016002639a1e8cbafe519606025c2feed7f 100644 --- a/CEP/BB/BBSKernel/src/MNS/MeqExpr.h +++ b/CEP/BB/BBSKernel/src/MNS/MeqExpr.h @@ -70,17 +70,24 @@ public: static void unlink (MeqExprRep* rep) { if (rep != 0 && --rep->itsCount == 0) delete rep; } - // Increment nr of parents. + // Increment number of parents. void incrNParents() { itsNParents++; } + // Decrement the number of parents. void decrNParents() { itsNParents--; } + // Get the current number of parents + const int getParentCount() const + { + return itsNParents; + } + // Recursively set the lowest and highest level of the node as used // in the tree. // Return the number of levels used so far. @@ -120,6 +127,7 @@ public: MeqResultVec& result) { return itsReqId == request.getId() ? *itsResVec : calcResultVec(request,result); } + virtual MeqResultVec getResultVec (const MeqRequest&); // </group> @@ -134,8 +142,8 @@ public: protected: // Add a child to this node. // It also increases NParents in the child. - void addChild(MeqExpr&); - void removeChild(MeqExpr &child); + void addChild(MeqExpr child); + void removeChild(MeqExpr child); private: // Forbid copy and assignment. @@ -159,7 +167,7 @@ private: int itsLevelDone; //# Level the node is handled by some parent. MeqResult* itsResult; //# Possibly cached result MeqResultVec* itsResVec; //# Possibly cached result vector - std::vector<MeqExprRep*> itsChildren; //# All children + std::vector<MeqExpr> itsChildren; //# All children protected: int itsNParents; //# Nr of parents @@ -188,20 +196,40 @@ public: // Assignment (reference semantics). MeqExpr& operator= (const MeqExpr&); + // Is the node empty? + bool isNull() const + { return itsRep == 0; } + + // A MeqExpr is essentially a reference counted shared + // pointer. Two MeqExpr's can be considered equal if both + // reference the same underlying MeqExprRep. + bool operator ==(const MeqExpr &other) + { + return (itsRep == other.itsRep); + } + + + //# -- DELEGATED METHODS -- + // Get the current number of parents + const int getParentCount() const + { + return itsRep->getParentCount(); + } + // Recursively set the lowest and highest level of the node as used // in the tree. // Return the number of levels used so far. int setLevel (int level) { return itsRep->setLevel (level); } - // Is the node empty? - bool isNull() const - { return itsRep == 0; } - // Clear the done flag recursively. void clearDone() { itsRep->clearDone(); } + // At which level is the node done? + int levelDone() const + { return itsRep->levelDone(); } + // Get the nodes at the given level. // By default only nodes with multiple parents are retrieved. // It is used to find the nodes with results to be cached. @@ -236,7 +264,7 @@ public: } #endif -protected: +private: MeqExprRep* itsRep; };