20 #ifndef _TLPMUTABLECONTAINER_
21 #define _TLPMUTABLECONTAINER_
29 #include <tulip/tulipconf.h>
30 #include <tulip/tuliphash.h>
31 #include <tulip/StoredType.h>
32 #include <tulip/DataSet.h>
33 #include <tulip/Iterator.h>
42 class IteratorValue :
public Iterator<unsigned int> {
45 ~IteratorValue()
override {}
46 virtual unsigned int nextValue(DataMem &) = 0;
50 template <
typename TYPE>
51 class MutableContainer {
52 friend class MutableContainerTest;
53 friend class GraphUpdatesRecorder;
62 void setDefault(
typename StoredType<TYPE>::ReturnedConstValue value);
66 void setAll(
typename StoredType<TYPE>::ReturnedConstValue value);
70 void set(
const unsigned int i,
typename StoredType<TYPE>::ReturnedConstValue value,
71 bool forceDefaultValueRemoval =
false);
75 void add(
const unsigned int i, TYPE val);
79 typename StoredType<TYPE>::ReturnedConstValue get(
const unsigned int i)
const;
83 typename StoredType<TYPE>::ReturnedValue get(
const unsigned int i,
bool &isNotDefault)
const;
87 typename StoredType<TYPE>::ReturnedValue getDefault()
const;
91 bool hasNonDefaultValue(
const unsigned int i)
const;
98 Iterator<unsigned int> *findAll(
typename StoredType<TYPE>::ReturnedConstValue value,
99 bool equal =
true)
const;
103 unsigned int numberOfNonDefaultValues()
const;
108 bool hasNonDefaultValues()
const {
109 return numberOfNonDefaultValues() != 0;
115 void invertBooleanValue(
const unsigned int i);
118 MutableContainer(
const MutableContainer<TYPE> &) {}
119 void operator=(
const MutableContainer<TYPE> &) {}
120 typename StoredType<TYPE>::ReturnedConstValue operator[](
const unsigned int i)
const;
123 void compress(
unsigned int min,
unsigned int max,
unsigned int nbElements);
124 inline void vectset(
const unsigned int i,
typename StoredType<TYPE>::Value value);
125 IteratorValue *findAllValues(
typename StoredType<TYPE>::ReturnedConstValue value,
126 bool equal =
true)
const;
129 std::deque<typename StoredType<TYPE>::Value> *vData;
130 tlp_hash_map<unsigned int, typename StoredType<TYPE>::Value> *hData;
131 unsigned int minIndex, maxIndex;
132 typename StoredType<TYPE>::Value defaultValue;
133 enum State { VECT = 0, HASH = 1 };
135 unsigned int elementInserted;
144 template <
typename TYPE>
145 class IteratorVect :
public tlp::IteratorValue {
147 IteratorVect(
const TYPE &value,
bool equal, std::deque<
typename StoredType<TYPE>::Value> *vData,
148 unsigned int minIndex)
149 : _value(value), _equal(equal), _pos(minIndex), vData(vData), it(vData->begin()) {
150 while (it != (*vData).end() && StoredType<TYPE>::equal((*it), _value) != _equal) {
155 bool hasNext()
override {
156 return (_pos < UINT_MAX && it != (*vData).end());
158 unsigned int next()
override {
159 unsigned int tmp = _pos;
164 }
while (it != (*vData).end() && StoredType<TYPE>::equal((*it), _value) != _equal);
168 unsigned int nextValue(DataMem &val)
override {
169 static_cast<TypedValueContainer<TYPE> &
>(val).value = StoredType<TYPE>::get(*it);
170 unsigned int pos = _pos;
175 }
while (it != (*vData).end() && StoredType<TYPE>::equal((*it), _value) != _equal);
184 std::deque<typename StoredType<TYPE>::Value> *vData;
185 typename std::deque<typename StoredType<TYPE>::Value>::const_iterator it;
190 template <
typename TYPE>
191 class IteratorHash :
public IteratorValue {
193 IteratorHash(
const TYPE &value,
bool equal,
194 tlp_hash_map<
unsigned int,
typename StoredType<TYPE>::Value> *hData)
195 : _value(value), _equal(equal), hData(hData) {
196 it = (*hData).begin();
198 while (it != (*hData).end() && StoredType<TYPE>::equal((*it).second, _value) != _equal)
201 bool hasNext()
override {
202 return (it != (*hData).end());
204 unsigned int next()
override {
205 unsigned int tmp = (*it).first;
209 }
while (it != (*hData).end() && StoredType<TYPE>::equal((*it).second, _value) != _equal);
213 unsigned int nextValue(DataMem &val)
override {
214 static_cast<TypedValueContainer<TYPE> &
>(val).value = StoredType<TYPE>::get((*it).second);
215 unsigned int pos = (*it).first;
219 }
while (it != (*hData).end() && StoredType<TYPE>::equal((*it).second, _value) != _equal);
227 tlp_hash_map<unsigned int, typename StoredType<TYPE>::Value> *hData;
228 typename tlp_hash_map<unsigned int, typename StoredType<TYPE>::Value>::const_iterator it;
234 #include "cxx/MutableContainer.cxx"