poolslotref.inc

Go to the documentation of this file.
00001 
00029 #ifndef ABA_POOLSLOTREF_INC
00030 #define ABA_POOLSLOTREF_INC
00031 
00032 #include "abacus/poolslotref.h"
00033 #include "abacus/master.h"
00034 #include "abacus/constraint.h"
00035 #include "abacus/variable.h"
00036 #include "abacus/poolslot.h"
00037 
00038   template<class BaseType, class CoType>
00039   inline ABA_POOLSLOTREF<BaseType, CoType>::ABA_POOLSLOTREF(ABA_MASTER *master)
00040   :  
00041     master_(master),  
00042     slot_(0),  
00043     version_(0)
00044   {  }
00045 
00046   template<class BaseType, class CoType>
00047   ABA_POOLSLOTREF<BaseType, CoType>::ABA_POOLSLOTREF(
00048                                          ABA_POOLSLOT<BaseType, CoType> *slot)
00049   :  
00050     master_(slot->master()),  
00051     slot_(slot),  
00052     version_(slot->version())
00053     {
00054       ABA_CONVAR *cv = slot_->conVar();
00055 
00056       if(cv) cv->addReference();
00057     }
00058 
00059   template<class BaseType, class CoType>
00060   ABA_POOLSLOTREF<BaseType, CoType>::ABA_POOLSLOTREF(const ABA_POOLSLOTREF &rhs) 
00061   :  
00062     master_(rhs.master_),  
00063     slot_(rhs.slot_),  
00064     version_(rhs.version_)
00065     {
00066       ABA_CONVAR *cv = slot_->conVar();
00067 
00068       if (version_ == slot_->version() && cv)
00069         cv->addReference();
00070     }
00071 
00072   template<class BaseType, class CoType>
00073   ABA_POOLSLOTREF<BaseType, CoType>::~ABA_POOLSLOTREF()
00074   {
00075     if(slot_) {
00076       ABA_CONVAR *cv = slot_->conVar();
00077       if (cv && version_ == slot_->version())
00078         cv->removeReference();
00079     }
00080   }
00081 
00082   template <class BaseType, class CoType>
00083   ostream &operator<<(ostream &out, const ABA_POOLSLOTREF<BaseType, CoType> &rhs)
00084   {
00085     if (rhs.conVar()) rhs.conVar()->print(out);
00086     return out;
00087   }
00088 
00089   template<class BaseType, class CoType>
00090   inline BaseType* ABA_POOLSLOTREF<BaseType, CoType>::conVar() const
00091   {
00092     if(version_ == slot_->version()) return slot_->conVar();
00093     printDifferentVersionError();
00094     
00095     return 0;
00096   }
00097 
00098   template<class BaseType, class CoType>
00099   void ABA_POOLSLOTREF<BaseType, CoType>::printDifferentVersionError() const
00100   {
00101      ABA_POOLSLOTREF<BaseType, CoType>::master_->out() << "ABA_POOLSLOTREF::con: Version of reference to slot " << version_;
00102     ABA_POOLSLOTREF<BaseType, CoType>::master_->out() << " and version of slot " << slot_->version() << " differ." << endl;
00103   }
00104 
00105   template<class BaseType, class CoType>
00106   inline unsigned long ABA_POOLSLOTREF<BaseType, CoType>::version() const
00107   {
00108     return version_;
00109   }
00110 
00111   template<class BaseType, class CoType>
00112   inline ABA_POOLSLOT<BaseType, CoType>* ABA_POOLSLOTREF<BaseType, CoType>::slot() const 
00113   {
00114     return slot_;
00115   }
00116 
00117   template<class BaseType, class CoType>
00118   void ABA_POOLSLOTREF<BaseType, CoType>::slot(ABA_POOLSLOT<BaseType, CoType> *s)
00119   {
00120     ABA_CONVAR *cv;
00121 
00122     if(slot_) {
00123       cv = slot_->conVar();
00124       if (cv && version_ == slot_->version())
00125         cv->removeReference();
00126     }
00127 
00128     slot_    = s;
00129     version_ = s->version();
00130     cv       = slot_->conVar();
00131     if(cv) cv->addReference();
00132   }
00133 
00134 #endif // ABA_POOLSLOTREF_INC

Generated on Tue Aug 14 18:09:54 2007 for ABACUS by  doxygen 1.5.1