Hurricane VLSI Database


SetCollection.h
1 // ****************************************************************************************************
2 // File: ./hurricane/SetCollection.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_SET_COLLECTION
21 #define HURRICANE_SET_COLLECTION
22 
23 #include "hurricane/Commons.h"
24 
25 #include "hurricane/Tabulation.h"
26 
27 
28 namespace Hurricane {
29 
30 
31 
32 // ****************************************************************************************************
33 // SetCollection declaration
34 // ****************************************************************************************************
35 
36 template<class Element, class Compare = less<Element> >
37  class SetCollection : public Collection<Element> {
38 // ************************************************
39 
40 // Types
41 // *****
42 
43  public: typedef Collection<Element> Inherit;
44 
45  public: typedef set<Element, Compare> ElementSet;
46 
47  public: class Locator : public Hurricane::Locator<Element> {
48  // *******************************************************
49 
50  public: typedef Hurricane::Locator<Element> Inherit;
51 
52  private: const ElementSet* _elementSet;
53  private: typename ElementSet::const_iterator _iterator; // AD
54 
55  public: Locator(const ElementSet* elementSet)
56  // ******************************************
57  : Inherit(),
58  _elementSet(elementSet),
59  _iterator()
60  {
61  if (_elementSet) _iterator = _elementSet->begin();
62  };
63 
64  public: virtual Element getElement() const
65  // ***************************************
66  {
67  return (isValid()) ? *_iterator : Element();
68  };
69 
70  public: virtual Hurricane::Locator<Element>* getClone() const
71  // **********************************************************
72  {
73  return new Locator(_elementSet);
74  };
75 
76  public: virtual bool isValid() const
77  // *********************************
78  {
79  return (_elementSet && (_iterator != _elementSet->end()));
80  };
81 
82  public: virtual void progress()
83  // ****************************
84  {
85  ++_iterator;
86  };
87 
88  };
89 
90 // Attributes
91 // **********
92 
93  private: const ElementSet* _elementSet;
94 
95 // Constructors
96 // ************
97 
98  public: SetCollection(const ElementSet* elementSet = NULL)
99  // *******************************************************
100  : Inherit(),
101  _elementSet(elementSet)
102  {
103  };
104 
105  public: SetCollection(const ElementSet& elementSet)
106  // ************************************************
107  : Inherit(),
108  _elementSet(&elementSet)
109  {
110  };
111 
112  public: SetCollection(const SetCollection& setCollection)
113  // ******************************************************
114  : Inherit(),
115  _elementSet(setCollection._elementSet)
116  {
117  };
118 
119 // Operators
120 // *********
121 
122  public: SetCollection& operator=(const SetCollection& setCollection)
123  // *****************************************************************
124  {
125  _elementSet = setCollection._elementSet;
126  return *this;
127  };
128 
129 // Accessors
130 // *********
131 
132  public: virtual Collection<Element>* getClone() const
133  // **************************************************
134  {
135  return new SetCollection(*this);
136  }
137 
138  public: virtual Hurricane::Locator<Element>* getLocator() const
139  // ************************************************************
140  {
141  // return (_elementSet) ? new Locator<Element, Compare>(_elementSet) : NULL;
142  // V3
143  return (_elementSet) ? new Locator(_elementSet) : NULL;
144  }
145 
146  public: virtual unsigned getSize() const
147  // *************************************
148  {
149  return (_elementSet) ? _elementSet->size() : 0;
150  };
151 
152 // Others
153 // ******
154 
155  public: virtual string _getTypeName() const
156  // **************************************
157  {
158  return _TName("SetCollection");
159  };
160 
161  public: virtual string _getString() const
162  // **************************************
163  {
164  if (!_elementSet)
165  return "<" + _getTypeName() + " unbound>";
166  else {
167  if (_elementSet->empty())
168  return "<" + _getTypeName() + " empty>";
169  else
170  return "<" + _getTypeName() + " " + getString(_elementSet->size()) + ">";
171  }
172  };
173 
174  Record* _getRecord() const
175  // *****************
176  {
177  Record* record = NULL;
178  if (!_elementSet->empty()) {
179  record = new Record(_getString());
180  unsigned n = 1;
181  typename set<Element, Compare>::const_iterator iterator = _elementSet->begin(); // AD
182  while (iterator != _elementSet->end()) {
183  record->add(getSlot(getString(n++), *iterator));
184  ++iterator;
185  }
186  }
187  return record;
188  }
189 
190 };
191 
192 
193 
194 // ****************************************************************************************************
195 // Generic functions
196 // ****************************************************************************************************
197 
198 template<class Element, class Compare>
199  inline GenericCollection<Element> getCollection(const set<Element, Compare>& elementSet)
200 // ****************************************************************************************
201 {
202  return SetCollection<Element, Compare>(elementSet);
203 }
204 
205 template<class Element, class Compare>
206  inline GenericCollection<Element> getCollection(const set<Element, Compare>* elementSet)
207 // ****************************************************************************************
208 {
209  return SetCollection<Element, Compare>(elementSet);
210 }
211 
212 
213 
214 } // End of Hurricane namespace.
215 
216 
217 
218 // ****************************************************************************************************
219 // Generic functions
220 // ****************************************************************************************************
221 
222 #endif // HURRICANE_SET_COLLECTION
223 
224 
225 // ****************************************************************************************************
226 // Copyright (c) BULL S.A. 2000-2018, All Rights Reserved
227 // ****************************************************************************************************
Collection description (API)
Definition: Collection.h:39
Locator description (API)
Definition: Locator.h:33
Hurricane Collection wrapper around a std::set.
Definition: SetCollection.h:37
SetCollection(const ElementSet *elementSet=NULL)
Definition: SetCollection.h:98
The namespace dedicated to Hurricane.
Definition: Generalities.dox:5


Generated by doxygen 1.9.1 on Thu Aug 11 2022 Return to top of page
Hurricane VLSI Database Copyright © 2000-2020 Bull S.A. All rights reserved