00001 00029 #ifndef ABA_POOLSLOT_INC 00030 #define ABA_POOLSLOT_INC 00031 00032 #include "abacus/poolslot.h" 00033 #include "abacus/pool.h" 00034 #include "abacus/master.h" 00035 #include "abacus/constraint.h" 00036 #include "abacus/variable.h" 00037 00038 #ifdef ABACUS_PARALLEL 00039 #include "abacus/id.h" 00040 #include "abacus/idmap.h" 00041 #endif 00042 00043 template<class BaseType, class CoType> 00044 inline ABA_POOLSLOT<BaseType, CoType>::ABA_POOLSLOT(ABA_MASTER *master, 00045 ABA_POOL<BaseType, CoType> *pool, 00046 BaseType *conVar) 00047 : 00048 master_(master), 00049 conVar_(conVar), 00050 pool_(pool) 00051 { 00052 if (conVar) version_ = 1; 00053 else version_ = 0; 00054 } 00055 00056 template<class BaseType, class CoType> 00057 ABA_POOLSLOT<BaseType, CoType>::~ABA_POOLSLOT() 00058 { 00059 if (conVar_ && conVar_->nReferences()) { 00060 ABA_POOLSLOT<BaseType, CoType>::master_->err() << "~ABA_POOLSLOT(): it is not allowed to destruct objects of "; 00061 ABA_POOLSLOT<BaseType, CoType>::master_->err() << "class ABA_POOLSLOT with a constraint/variable with "; 00062 ABA_POOLSLOT<BaseType, CoType>::master_->err() << "positive reference counter = " << conVar_->nReferences() << "." << endl; 00063 exit(Fatal); 00064 } 00065 00066 delete conVar_; 00067 } 00068 00069 #include <limits.h> 00070 00071 template<class BaseType, class CoType> 00072 void ABA_POOLSLOT<BaseType, CoType>::insert(BaseType *conVar) 00073 { 00074 if (conVar_ != 0) { 00075 ABA_POOLSLOT<BaseType, CoType>::master_->err() << "ABA_POOLSLOT::insert(): insertion failed, the slot is not void" << endl; 00076 exit (Fatal); 00077 } 00078 00079 if (version_ == ULONG_MAX) { 00080 ABA_POOLSLOT<BaseType, CoType>::master_->err() << "ABA_POOLSLOT::insert(): insertion failed, "; 00081 ABA_POOLSLOT<BaseType, CoType>::master_->err() << "maximum version number ULONG_MAX = " << ULONG_MAX; 00082 ABA_POOLSLOT<BaseType, CoType>::master_->err() << " reached"; 00083 exit (Fatal); 00084 } 00085 00086 #ifdef ABACUS_PARALLEL 00087 if (conVar->identification_.isInitialized()) { 00088 master_->err() << "ABA_POOLSLOT::insert(): the constraint/variable" 00089 " must not have an initialized ABA_ID!" << endl; 00090 exit (Fatal); 00091 } 00092 #endif 00093 conVar_ = conVar; 00094 ++version_; 00095 } 00096 00097 template<class BaseType, class CoType> 00098 int ABA_POOLSLOT<BaseType, CoType>::softDelete() 00099 { 00100 if (conVar_ == 0) return 0; 00101 if (conVar_->deletable() == false) return 1; 00102 hardDelete(); 00103 return 0; 00104 } 00105 00106 template<class BaseType, class CoType> 00107 inline void ABA_POOLSLOT<BaseType, CoType>::hardDelete() 00108 { 00109 #ifdef ABACUS_PARALLEL 00110 if (conVar_ && conVar_->identification_.isInitialized()) { 00111 pool_->identificationMap()->remove(conVar_->identification_); 00112 } 00113 #endif 00114 delete conVar_; 00115 conVar_ = 0; 00116 } 00117 00118 template<class BaseType, class CoType> 00119 inline void ABA_POOLSLOT<BaseType, CoType>::removeConVarFromPool() 00120 { 00121 pool_->removeConVar(this); 00122 } 00123 00124 template<class BaseType, class CoType> 00125 inline BaseType * ABA_POOLSLOT<BaseType, CoType>::conVar() const 00126 { 00127 return conVar_; 00128 } 00129 00130 template<class BaseType, class CoType> 00131 inline unsigned long ABA_POOLSLOT<BaseType, CoType>::version() const 00132 { 00133 return version_; 00134 } 00135 00136 template<class BaseType, class CoType> 00137 inline ABA_MASTER * ABA_POOLSLOT<BaseType, CoType>::master() 00138 { 00139 return master_; 00140 } 00141 00142 00143 #ifdef ABACUS_PARALLEL 00144 00145 template<class BaseType, class CoType> 00146 const ABA_ID &ABA_POOLSLOT<BaseType, CoType>::getIdentification(void) const 00147 { 00148 if (conVar_ == 0) { 00149 master_->err() << "ABA_POOLSLOT::getIdentification() : no " 00150 "constraint/variable available in this slot!" << endl; 00151 exit(Fatal); 00152 } 00153 return conVar_->identification_; 00154 } 00155 00156 template<class BaseType, class CoType> 00157 void ABA_POOLSLOT<BaseType, CoType>::setIdentification(const ABA_ID &id) 00158 { 00159 if (conVar_) { 00160 conVar_->identification_ = id; 00161 pool_->identificationMap()->insert(id, this); 00162 } 00163 else { 00164 master_->err() << "ABA_POOLSLOT::setIdentification() : no " 00165 "constraint/variable available in this slot!" << endl; 00166 exit(Fatal); 00167 } 00168 } 00169 00170 template<class BaseType, class CoType> 00171 void ABA_POOLSLOT<BaseType, CoType>::setNewIdentification() 00172 { 00173 if (conVar_) 00174 pool_->identificationMap()->insertWithNewId(conVar_->identification_, this); 00175 else { 00176 master_->err() << "ABA_POOLSLOT::setNewIdentification() : no " 00177 "constraint/variable available in this slot!" << endl; 00178 exit(Fatal); 00179 } 00180 } 00181 00182 #endif 00183 00184 #endif // ABA_POOLSLOT_INC