Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

poolslot.inc
Go to the documentation of this file.
1 
29 #pragma once
30 
32 #include <ogdf/lib/abacus/pool.h>
33 #include <ogdf/lib/abacus/convar.h>
34 
35 namespace abacus {
36 
37 template<class BaseType, class CoType>
39  Master *master,
40  Pool<BaseType, CoType> *pool,
41  BaseType *convar) : master_(master), conVar_(convar), pool_(pool)
42 {
43  version_ = (convar) ? 1 : 0;
44 }
45 
46 
47 template<class BaseType, class CoType>
48 PoolSlot<BaseType, CoType>::~PoolSlot()
49 {
50 #ifdef OGDF_DEBUG
51  if (conVar_ && conVar_->nReferences()) {
52  Logger::ifout() << "~PoolSlot(): it is not allowed to destruct objects of class PoolSlot with a constraint/variable with positive reference counter = " << conVar_->nReferences() << ".\n";
53  }
54 
55 #ifndef OGDF_USE_ASSERT_EXCEPTIONS // do not throw exceptions in destructor
56  OGDF_ASSERT((conVar_ && conVar_->nReferences()) == false);
57 #endif
58 #endif
59 
60  delete conVar_;
61 }
62 
63 
64 template<class BaseType, class CoType>
65 void PoolSlot<BaseType, CoType>::insert(BaseType *convar)
66 {
67  if (conVar_ != nullptr) {
68  Logger::ifout() << "PoolSlot::insert(): insertion failed, the slot is not void\n";
69  OGDF_THROW_PARAM(AlgorithmFailureException, ogdf::AlgorithmFailureCode::Poolslot);
70  }
71 
72  if (version_ == numeric_limits<unsigned long>::max()) {
73  Logger::ifout() << "PoolSlot::insert(): insertion failed, maximum version number ULONG_MAX reached\n";
74  OGDF_THROW_PARAM(AlgorithmFailureException, ogdf::AlgorithmFailureCode::Poolslot);
75  }
76 
77  conVar_ = convar;
78  ++version_;
79 }
80 
81 } //namespace abacus
PoolSlot(Master *master, Pool< BaseType, CoType > *pool, BaseType *convar=0)
Creates a pool slot and inserts convar.
constraints and variables.
#define OGDF_THROW_PARAM(CLASS, PARAM)
Replacement for throw.
Definition: exceptions.h:51
poolslot.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:41