# Hurricane Documentation

# Hurricane VLSI Database

MapCollection.h
1 // ****************************************************************************************************
2 // File: ./hurricane/MapCollection.h
3 // Authors: R. Escassut
4 // Copyright (c) BULL S.A. 2000-2018, All Rights Reserved
5 //
6 // This file is part of Hurricane.
7 //
8 // Hurricane is free software: you can redistribute it and/or modify it under the terms of the GNU
9 // Lesser General Public License as published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
11 //
12 // Hurricane is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
13 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU
14 // General Public License for more details.
15 //
16 // You should have received a copy of the Lesser GNU General Public License along with Hurricane. If
17 // not, see <http://www.gnu.org/licenses/>.
18 // ****************************************************************************************************
19
20 #ifndef HURRICANE_MAP_COLLECTION
21 #define HURRICANE_MAP_COLLECTION
22
23 #include "hurricane/Commons.h"
24
25 namespace Hurricane {
26
27
28
29 // ****************************************************************************************************
30 // MapCollection declaration
31 // ****************************************************************************************************
32
33 template<class Key, class Element, class Compare = less<Key> >
34 class MapCollection : public Collection<Element> {
35 // ************************************************
36
37 // Types
38 // *****
39
40 public: typedef Collection<Element> Inherit;
41
42 public: typedef map<Key, Element, Compare> ElementMap;
43
44 public: class Locator : public Hurricane::Locator<Element> {
45 // *******************************************************
46
47 public: typedef Hurricane::Locator<Element> Inherit;
48
49 private: const ElementMap* _elementMap;
50 private: typename ElementMap::const_iterator _iterator; // AD
51
52 public: Locator(const ElementMap* elementMap)
53 // ******************************************
54 : Inherit(),
55 _elementMap(elementMap),
56 _iterator()
57 {
58 if (_elementMap) _iterator = _elementMap->begin();
59 };
60
61 public: virtual Element getElement() const
62 // ***************************************
63 {
64 return (isValid()) ? (*_iterator).second : Element();
65 };
66
67 public: virtual Hurricane::Locator<Element>* getClone() const
68 // **********************************************************
69 {
70 return new Locator(_elementMap);
71 };
72
73 public: virtual bool isValid() const
74 // *********************************
75 {
76 return (_elementMap && (_iterator != _elementMap->end()));
77 };
78
79 public: virtual void progress()
80 // ****************************
81 {
82 ++_iterator;
83 };
84
85 };
86
87 // Attributes
88 // **********
89
90 private: const ElementMap* _elementMap;
91
92 // Constructors
93 // ************
94
95 public: MapCollection(const ElementMap* elementMap = NULL)
96 // *******************************************************
97 : Inherit(),
98 _elementMap(elementMap)
99 {
100 };
101
102 public: MapCollection(const ElementMap& elementMap)
103 // ************************************************
104 : Inherit(),
105 _elementMap(&elementMap)
106 {
107 };
108
109 public: MapCollection(const MapCollection& mapCollection)
110 // ******************************************************
111 : Inherit(),
112 _elementMap(mapCollection._elementMap)
113 {
114 };
115
116 // Operators
117 // *********
118
119 public: MapCollection& operator=(const MapCollection& mapCollection)
120 // *****************************************************************
121 {
122 _elementMap = mapCollection._elementMap;
123 return *this;
124 };
125
126 // Accessors
127 // *********
128
129 public: virtual Collection<Element>* getClone() const
130 // **************************************************
131 {
132 return new MapCollection(*this);
133 }
134
135 public: virtual Hurricane::Locator<Element>* getLocator() const
136 // ************************************************************
137 {
138 // return (_elementMap) ? new Locator<Key, Element, Compare>(_elementMap) : NULL;
139 // V3
140 return (_elementMap) ? new Locator(_elementMap) : NULL;
141 }
142
143 public: virtual unsigned getSize() const
144 // *************************************
145 {
146 return (_elementMap) ? _elementMap->size() : 0;
147 };
148
149 // Others
150 // ******
151
152 public: virtual string _getTypeName() const
153 // **************************************
154 {
155 return _TName("MapCollection");
156 };
157
158 public: virtual string _getString() const
159 // **************************************
160 {
161 if (!_elementMap)
162 return "<" + _getTypeName() + " unbound>";
163 else {
164 if (_elementMap->empty())
165 return "<" + _getTypeName() + " empty>";
166 else
167 return "<" + _getTypeName() + " " + getString(_elementMap->size()) + ">";
168 }
169 };
170
171 Record* _getRecord() const
172 // ********************
173 {
174 Record* record = NULL;
175 if (!_elementMap->empty()) {
176 record = new Record(_getString());
177 typename map<Key, Element, Compare>::const_iterator iterator = _elementMap->begin(); // AD
178 while (iterator != _elementMap->end()) {
179 record->add(getSlot<Element>(getString((*iterator).first), (*iterator).second));
180 ++iterator;
181 }
182 }
183 return record;
184 }
185
186 };
187
188
189
190 // ****************************************************************************************************
191 // Generic functions
192 // ****************************************************************************************************
193
194 template<class Key, class Element, class Compare>
195 inline GenericCollection<Element> getCollection(const map<Key, Element, Compare>& elementMap)
196 // *********************************************************************************************
197 {
198 return MapCollection<Key, Element, Compare>(elementMap);
199 }
200
201 template<class Key, class Element, class Compare>
202 inline GenericCollection<Element> getCollection(const map<Key, Element, Compare>* elementMap)
203 // *********************************************************************************************
204 {
205 return MapCollection<Key, Element, Compare>(elementMap);
206 }
207
208
209
210 } // End of Hurricane namespace.
211
212 #endif // HURRICANE_MAP_COLLECTION
213
214
215 // ****************************************************************************************************
216 // Copyright (c) BULL S.A. 2000-2018, All Rights Reserved
217 // ****************************************************************************************************
Hurricane::Collection
Collection description (API)
Definition: Collection.h:39
Hurricane::Locator
Locator description (API)
Definition: Locator.h:33
Hurricane::MapCollection::MapCollection
MapCollection(const ElementMap *elementMap=NULL)
Definition: MapCollection.h:95
Hurricane::MapCollection
Hurricane Collection wrapper around a std::map.
Definition: MapCollection.h:34
Hurricane
The namespace dedicated to Hurricane.
Definition: Generalities.dox:5