Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

poolslotref.h
Go to the documentation of this file.
1 
30 #pragma once
31 
33 #include <ogdf/lib/abacus/master.h>
36 
37 namespace abacus {
38 
39 template<class BaseType, class CoType>
40 class PoolSlotRef;
41 
42 template<class BaseType, class CoType>
43 std::ostream &operator<< (std::ostream &out, const PoolSlotRef<BaseType, CoType> &slot);
44 
45 
47 
53 template<class BaseType, class CoType>
54 class PoolSlotRef : public AbacusRoot {
55 public:
56 
58 
61  PoolSlotRef(Master *master) : master_(master), slot_(0), version_(0) { }
62 
64 
71  {
72  ConVar *cv = slot_->conVar();
73  if(cv) cv->addReference();
74  }
75 
77 
86  {
87  ConVar *cv = slot_->conVar();
88  if (version_ == slot_->version() && cv)
89  cv->addReference();
90  }
91 
93 
103  if(slot_) {
104  ConVar *cv = slot_->conVar();
105  if (cv && version_ == slot_->version())
106  cv->removeReference();
107  }
108  }
109 
111 
120  friend std::ostream &operator<< <> (std::ostream &out, const PoolSlotRef<BaseType, CoType> &slot);
121 
123 
127  BaseType *conVar() const {
128  if(version_ == slot_->version())
129  return slot_->conVar();
131 
132  return nullptr;
133  }
134 
136  unsigned long version() const { return version_; }
137 
139  PoolSlot<BaseType, CoType> *slot() const { return slot_; }
140 
141 
143 
152 
153 private:
154 
156 
158 
160  unsigned long version_;
161 
162  void printDifferentVersionError() const;
163 
164 
167 
169 };
170 
171 }
172 
abacus::ConVar::addReference
void addReference()
Indicates that there is a new reference to the pool slot storing this constraint/variable.
Definition: convar.h:358
abacus::PoolSlotRef
Stores a pointer to a pool slot with version number.
Definition: active.h:40
abacus::ConVar::removeReference
void removeReference()
Is the counterpart of the function addReference() and indicates the removal of a reference to this co...
Definition: convar.h:419
constraint.h
constraint.
abacus::PoolSlotRef::PoolSlotRef
PoolSlotRef(PoolSlot< BaseType, CoType > *slot)
Creates an object referencing a pool slot slot.
Definition: poolslotref.h:70
abacus::operator<<
std::ostream & operator<<(std::ostream &out, const Active< BaseType, CoType > &rhs)
abacus::PoolSlotRef::version
unsigned long version() const
Returns the version number of the constraint/variable stored in the referenced slot at construction t...
Definition: poolslotref.h:136
abacus::PoolSlotRef::~PoolSlotRef
~PoolSlotRef()
The destructor.
Definition: poolslotref.h:102
abacus
Definition: abacusroot.h:48
abacus::PoolSlotRef::conVar
BaseType * conVar() const
Returns a pointer to the constraint/variable stored in the referenced slot.
Definition: poolslotref.h:127
poolslotref.inc
abacus::PoolSlotRef::slot_
PoolSlot< BaseType, CoType > * slot_
A pointer to the referenced pool slot.
Definition: poolslotref.h:157
OGDF_NEW_DELETE
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
Definition: memory.h:84
abacus::PoolSlotRef::PoolSlotRef
PoolSlotRef(const PoolSlotRef< BaseType, CoType > &rhs)
Copy constructor.
Definition: poolslotref.h:85
abacus::PoolSlotRef::version_
unsigned long version_
The version number of the slot at construction/initialization time of this reference.
Definition: poolslotref.h:160
abacus::ConVar
Common base class for constraints (Constraint) and variables (Variable).
Definition: convar.h:65
abacus::PoolSlotRef::operator=
const PoolSlotRef< BaseType, CoType > & operator=(const PoolSlotRef< BaseType, CoType > &rhs)
variable.h
variable.
abacus::PoolSlotRef::master_
Master * master_
A pointer to the corresponding master of the optimization.
Definition: poolslotref.h:155
master.h
the master of the optimization.
poolslot.h
poolslot.
abacus::PoolSlot
Stores constraints and variables.
Definition: active.h:39
abacus::PoolSlotRef::printDifferentVersionError
void printDifferentVersionError() const
abacus::PoolSlotRef::slot
PoolSlot< BaseType, CoType > * slot() const
Returns a pointer to the referenced slot.
Definition: poolslotref.h:139
abacus::Master
The master of the optimization.
Definition: master.h:69
abacus::PoolSlotRef::PoolSlotRef
PoolSlotRef(Master *master)
Creates an object referencing no pool slot.
Definition: poolslotref.h:61