21 #ifndef _TLPMUTABLECONTAINER_
22 #define _TLPMUTABLECONTAINER_
30 #include <tulip/tulipconf.h>
31 #include <tulip/tuliphash.h>
32 #include <tulip/StoredType.h>
33 #include <tulip/DataSet.h>
34 #include <tulip/Iterator.h>
38 #ifndef DOXYGEN_NOTFOR_DEVEL
43 class IteratorValue:
public Iterator<unsigned int> {
46 virtual ~IteratorValue() {}
47 virtual unsigned int nextValue(DataMem&) = 0;
49 #endif // DOXYGEN_NOTFOR_DEVEL
51 template <
typename TYPE>
52 class MutableContainer {
53 friend class MutableContainerTest;
54 friend class GraphUpdatesRecorder;
61 void setAll(
const TYPE &value);
65 void set(
const unsigned int i,
const TYPE &value);
69 void add(
const unsigned int i, TYPE val);
73 typename StoredType<TYPE>::ReturnedConstValue
get(
const unsigned int i)
const;
77 typename StoredType<TYPE>::ReturnedValue
get(
const unsigned int i,
bool& isNotDefault)
const;
81 typename StoredType<TYPE>::ReturnedValue getDefault()
const;
85 bool hasNonDefaultValue(
const unsigned int i)
const;
92 Iterator<unsigned int>* findAll(
const TYPE &value,
bool equal =
true)
const;
96 unsigned int numberOfNonDefaultValues()
const;
98 MutableContainer(
const MutableContainer<TYPE> &) {}
99 void operator=(
const MutableContainer<TYPE> &) {}
100 typename StoredType<TYPE>::ReturnedConstValue operator[](
const unsigned int i)
const;
103 void compress(
unsigned int min,
unsigned int max,
unsigned int nbElements);
104 inline void vectset(
const unsigned int i,
typename StoredType<TYPE>::Value value);
105 IteratorValue* findAllValues(
const TYPE &value,
bool equal =
true)
const;
107 std::deque<typename StoredType<TYPE>::Value> *vData;
108 TLP_HASH_MAP<unsigned int, typename StoredType<TYPE>::Value> *hData;
109 unsigned int minIndex,maxIndex;
110 typename StoredType<TYPE>::Value defaultValue;
111 enum State { VECT=0, HASH=1 };
113 unsigned int elementInserted;
122 template <
typename TYPE>
123 class IteratorVect :
public tlp::IteratorValue {
125 IteratorVect(
const TYPE &value,
bool equal, std::deque<
typename StoredType<TYPE>::Value> *vData,
unsigned int minIndex):
131 while (it!=(*vData).end() &&
132 StoredType<TYPE>::equal((*it), _value) != _equal) {
138 return (_pos<UINT_MAX && it!=(*vData).end());
140 unsigned int next() {
141 unsigned int tmp = _pos;
147 while (it!=(*vData).end() &&
148 StoredType<TYPE>::equal((*it), _value) != _equal);
152 unsigned int nextValue(DataMem& val) {
153 ((TypedValueContainer<TYPE>&) val).value = StoredType<TYPE>::get(*it);
154 unsigned int pos = _pos;
160 while (it!=(*vData).end() &&
161 StoredType<TYPE>::equal((*it), _value) != _equal);
169 std::deque<typename StoredType<TYPE>::Value> *vData;
170 typename std::deque<typename StoredType<TYPE>::Value>::const_iterator it;
174 template <
typename TYPE>
175 class IteratorHash :
public IteratorValue {
177 IteratorHash(
const TYPE &value,
bool equal, TLP_HASH_MAP<
unsigned int,
typename StoredType<TYPE>::Value> *hData):
183 while (it!=(*hData).end() &&
184 StoredType<TYPE>::equal((*it).second,_value) != _equal)
188 return (it!=(*hData).end());
190 unsigned int next() {
191 unsigned int tmp = (*it).first;
196 while (it!=(*hData).end() &&
197 StoredType<TYPE>::equal((*it).second,_value) != _equal);
201 unsigned int nextValue(DataMem& val) {
202 ((TypedValueContainer<TYPE>&) val).value =
203 StoredType<TYPE>::get((*it).second);
204 unsigned int pos = (*it).first;
209 while (it!=(*hData).end() &&
210 StoredType<TYPE>::equal((*it).second,_value) != _equal);
217 TLP_HASH_MAP<unsigned int, typename StoredType<TYPE>::Value> *hData;
218 typename TLP_HASH_MAP<unsigned int, typename StoredType<TYPE>::Value>::const_iterator it;
221 #ifndef DOXYGEN_NOTFOR_DEVEL
225 #include "cxx/MutableContainer.cxx"
227 #endif // DOXYGEN_NOTFOR_DEVEL