Hurricane VLSI Database


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


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