88 /// \brief Constructor to attach the new map into the notifier. |
88 /// \brief Constructor to attach the new map into the notifier. |
89 /// |
89 /// |
90 /// It constructs a map and attachs it into the notifier. |
90 /// It constructs a map and attachs it into the notifier. |
91 /// It adds all the items of the graph to the map. |
91 /// It adds all the items of the graph to the map. |
92 VectorMap(const Graph& graph) { |
92 VectorMap(const Graph& graph) { |
93 Parent::attach(graph.getNotifier(Item())); |
93 Parent::attach(graph.notifier(Item())); |
94 container.resize(Parent::getNotifier()->maxId() + 1); |
94 container.resize(Parent::notifier()->maxId() + 1); |
95 } |
95 } |
96 |
96 |
97 /// \brief Constructor uses given value to initialize the map. |
97 /// \brief Constructor uses given value to initialize the map. |
98 /// |
98 /// |
99 /// It constructs a map uses a given value to initialize the map. |
99 /// It constructs a map uses a given value to initialize the map. |
100 /// It adds all the items of the graph to the map. |
100 /// It adds all the items of the graph to the map. |
101 VectorMap(const Graph& graph, const Value& value) { |
101 VectorMap(const Graph& graph, const Value& value) { |
102 Parent::attach(graph.getNotifier(Item())); |
102 Parent::attach(graph.notifier(Item())); |
103 container.resize(Parent::getNotifier()->maxId() + 1, value); |
103 container.resize(Parent::notifier()->maxId() + 1, value); |
104 } |
104 } |
105 |
105 |
106 /// \brief Copy constructor |
106 /// \brief Copy constructor |
107 /// |
107 /// |
108 /// Copy constructor. |
108 /// Copy constructor. |
109 VectorMap(const VectorMap& _copy) : Parent() { |
109 VectorMap(const VectorMap& _copy) : Parent() { |
110 if (_copy.attached()) { |
110 if (_copy.attached()) { |
111 Parent::attach(*_copy.getNotifier()); |
111 Parent::attach(*_copy.notifier()); |
112 container = _copy.container; |
112 container = _copy.container; |
113 } |
113 } |
114 } |
114 } |
115 |
115 |
116 /// \brief Assign operator. |
116 /// \brief Assign operator. |
132 /// the NodeMap. In this case the value for each item |
132 /// the NodeMap. In this case the value for each item |
133 /// is assigned by the value of the given ReadMap. |
133 /// is assigned by the value of the given ReadMap. |
134 template <typename CMap> |
134 template <typename CMap> |
135 VectorMap& operator=(const CMap& cmap) { |
135 VectorMap& operator=(const CMap& cmap) { |
136 checkConcept<concepts::ReadMap<Key, _Value>, CMap>(); |
136 checkConcept<concepts::ReadMap<Key, _Value>, CMap>(); |
137 const typename Parent::Notifier* notifier = Parent::getNotifier(); |
137 const typename Parent::Notifier* notifier = Parent::notifier(); |
138 Item it; |
138 Item it; |
139 for (notifier->first(it); it != INVALID; notifier->next(it)) { |
139 for (notifier->first(it); it != INVALID; notifier->next(it)) { |
140 set(it, cmap[it]); |
140 set(it, cmap[it]); |
141 } |
141 } |
142 return *this; |
142 return *this; |
147 /// \brief The subcript operator. |
147 /// \brief The subcript operator. |
148 /// |
148 /// |
149 /// The subscript operator. The map can be subscripted by the |
149 /// The subscript operator. The map can be subscripted by the |
150 /// actual items of the graph. |
150 /// actual items of the graph. |
151 Reference operator[](const Key& key) { |
151 Reference operator[](const Key& key) { |
152 return container[Parent::getNotifier()->id(key)]; |
152 return container[Parent::notifier()->id(key)]; |
153 } |
153 } |
154 |
154 |
155 /// \brief The const subcript operator. |
155 /// \brief The const subcript operator. |
156 /// |
156 /// |
157 /// The const subscript operator. The map can be subscripted by the |
157 /// The const subscript operator. The map can be subscripted by the |
158 /// actual items of the graph. |
158 /// actual items of the graph. |
159 ConstReference operator[](const Key& key) const { |
159 ConstReference operator[](const Key& key) const { |
160 return container[Parent::getNotifier()->id(key)]; |
160 return container[Parent::notifier()->id(key)]; |
161 } |
161 } |
162 |
162 |
163 |
163 |
164 /// \brief The setter function of the map. |
164 /// \brief The setter function of the map. |
165 /// |
165 /// |
173 /// \brief Adds a new key to the map. |
173 /// \brief Adds a new key to the map. |
174 /// |
174 /// |
175 /// It adds a new key to the map. It called by the observer notifier |
175 /// It adds a new key to the map. It called by the observer notifier |
176 /// and it overrides the add() member function of the observer base. |
176 /// and it overrides the add() member function of the observer base. |
177 virtual void add(const Key& key) { |
177 virtual void add(const Key& key) { |
178 int id = Parent::getNotifier()->id(key); |
178 int id = Parent::notifier()->id(key); |
179 if (id >= (int)container.size()) { |
179 if (id >= (int)container.size()) { |
180 container.resize(id + 1); |
180 container.resize(id + 1); |
181 } |
181 } |
182 } |
182 } |
183 |
183 |
186 /// It adds more new keys to the map. It called by the observer notifier |
186 /// It adds more new keys to the map. It called by the observer notifier |
187 /// and it overrides the add() member function of the observer base. |
187 /// and it overrides the add() member function of the observer base. |
188 virtual void add(const std::vector<Key>& keys) { |
188 virtual void add(const std::vector<Key>& keys) { |
189 int max = container.size() - 1; |
189 int max = container.size() - 1; |
190 for (int i = 0; i < (int)keys.size(); ++i) { |
190 for (int i = 0; i < (int)keys.size(); ++i) { |
191 int id = Parent::getNotifier()->id(keys[i]); |
191 int id = Parent::notifier()->id(keys[i]); |
192 if (id >= max) { |
192 if (id >= max) { |
193 max = id; |
193 max = id; |
194 } |
194 } |
195 } |
195 } |
196 container.resize(max + 1); |
196 container.resize(max + 1); |
199 /// \brief Erase a key from the map. |
199 /// \brief Erase a key from the map. |
200 /// |
200 /// |
201 /// Erase a key from the map. It called by the observer notifier |
201 /// Erase a key from the map. It called by the observer notifier |
202 /// and it overrides the erase() member function of the observer base. |
202 /// and it overrides the erase() member function of the observer base. |
203 virtual void erase(const Key& key) { |
203 virtual void erase(const Key& key) { |
204 container[Parent::getNotifier()->id(key)] = Value(); |
204 container[Parent::notifier()->id(key)] = Value(); |
205 } |
205 } |
206 |
206 |
207 /// \brief Erase more keys from the map. |
207 /// \brief Erase more keys from the map. |
208 /// |
208 /// |
209 /// Erase more keys from the map. It called by the observer notifier |
209 /// Erase more keys from the map. It called by the observer notifier |
210 /// and it overrides the erase() member function of the observer base. |
210 /// and it overrides the erase() member function of the observer base. |
211 virtual void erase(const std::vector<Key>& keys) { |
211 virtual void erase(const std::vector<Key>& keys) { |
212 for (int i = 0; i < (int)keys.size(); ++i) { |
212 for (int i = 0; i < (int)keys.size(); ++i) { |
213 container[Parent::getNotifier()->id(keys[i])] = Value(); |
213 container[Parent::notifier()->id(keys[i])] = Value(); |
214 } |
214 } |
215 } |
215 } |
216 |
216 |
217 /// \brief Buildes the map. |
217 /// \brief Buildes the map. |
218 /// |
218 /// |
219 /// It buildes the map. It called by the observer notifier |
219 /// It buildes the map. It called by the observer notifier |
220 /// and it overrides the build() member function of the observer base. |
220 /// and it overrides the build() member function of the observer base. |
221 virtual void build() { |
221 virtual void build() { |
222 int size = Parent::getNotifier()->maxId() + 1; |
222 int size = Parent::notifier()->maxId() + 1; |
223 container.reserve(size); |
223 container.reserve(size); |
224 container.resize(size); |
224 container.resize(size); |
225 } |
225 } |
226 |
226 |
227 /// \brief Clear the map. |
227 /// \brief Clear the map. |