#ifndef BNPINDEX_HEADER #define BNPINDEX_HEADER 1 /////////////////////////////////////////////////// //! rcsid="$Id: BNPIndex.hh,v 1.9 2000/07/14 14:30:27 ees1cg Exp $" //! file="amma/Logic/Index/BNPIndex.hh" //! lib=VLIndex //! author="Charles Galambos" //! date="14/05/98" //! docentry="Logic.Index" #include "amma/Logic2/BIndex.hh" #include "amma/Logic2/LMinTerm.hh" #include "amma/Logic2/LMinTermPIter.hh" //! userlevel=Normal //: Branching Neg/Pos Index. // This allows values to be mapped to both expressions and // their negations. template class VLBNPIndexC { public: inline VLBNPIndexC(); //: Default constructor. inline VLBNPIndexC(const VLIndexC &ids); //: Construct using a given id Index. // Otherwise creates a new index. inline VLBNPIndexC(const VLBNPIndexC &oth); //: Copy constructor. inline VLBNPIndexC DeepCopy() const; //: Make a deep copy of this class. inline BooleanT Add(BooleanT negate,const VLSymbC &symb,const T &data); //: Add data. // Ret: TRUE = New item. inline BooleanT Add(const VLMinTermC &mt,const T &data); //: Add data. // Ret: TRUE = New item. T &Access(BooleanT negate,const VLSymbC &symb); //: Access data. inline BooleanT IsEmpty() const; //: Is table empty ? const VLIndexC &IdIndex() const { return pos.IdIndex(); } //: Get ID index. protected: inline VLBNPIndexC(const VLBIndexC &npos,const VLBIndexC &nneg); //: Make a new NPIndex from two other indexs. private: VLBIndexC pos; // Index for positive terms. VLBIndexC neg; // Index for negative terms. friend VLBNPIndexIterC; }; //////////////////////////////////////////////////////// template inline VLBNPIndexC::VLBNPIndexC() : pos(aTRUE), neg(aTRUE) { neg.UseIndex(pos.IdIndex()); // Share index. } template inline VLBNPIndexC::VLBNPIndexC(const VLIndexC &ids) : pos(ids), neg(ids) {} template inline VLBNPIndexC::VLBNPIndexC(const VLBIndexC &npos,const VLBIndexC &nneg) : pos(npos), neg(nneg) {} template inline VLBNPIndexC::VLBNPIndexC(const VLBNPIndexC &oth) : pos(oth.pos), neg(oth.neg) {} template inline VLBNPIndexC VLBNPIndexC::DeepCopy() const { return VLBNPIndexC(pos.DeepCopy(),neg.DeepCopy()); } template inline BooleanT VLBNPIndexC::Add(BooleanT negate,const VLSymbC &symb,const T &data) { if(!negate) return pos.Add(symb,data); return neg.Add(symb,data); } template inline BooleanT VLBNPIndexC::Add(const VLMinTermC &mt,const T &data) { BooleanT ret = TRUE; for(VLMinTermPartIter it(mt);it.IsElm();it.Next()) ret &= Add(it.IsDataNeg(),it.Symb(),data); return ret; } template inline T & VLBNPIndexC::Access(BooleanT negate,const VLSymbC &symb) { if(!negate) return pos[symb]; return neg[symb]; } template inline BooleanT VLBNPIndexC::IsEmpty() const { return pos.IsEmpty() && neg.IsEmpty(); } #endif