Hurricane VLSI Database


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