# Hurricane VLSI Database

Collection.h
1 // ****************************************************************************************************
2 // File: ./hurricane/Collection.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_COLLECTION
21 #define HURRICANE_COLLECTION
22
23 #include "hurricane/Locator.h"
24 #include "hurricane/Filter.h"
25
26 namespace Hurricane {
27
28 template<class Type> class GenericCollection;
29 template<class Type, class SubType> class SubTypeCollection;
30 template<class Type, class SubType> class NotSubTypeCollection;
31 template<class Type> class SubSetCollection;
32
33
34
35 // ****************************************************************************************************
36 // Collection declaration
37 // ****************************************************************************************************
38
39 template<class Type> class Collection {
40 // ************************************
41
42 // Constructors
43 // ************
44
45 protected: Collection()
46 // ********************
47 {
48 }
49
50 private: Collection(const Collection& collection);
51 // ***********************************************
52 // not implemented to forbid copy construction
53 // ***********************************************
54
55 // Destructor
56 // **********
57
58 public: virtual ~Collection()
59 // **************************
60 {
61 }
62
63 // Operators
64 // *********
65
66 private: Collection& operator=(const Collection& collection);
67 // **********************************************************
68 // not implemented to forbid assignment
69 // **********************************************************
70
71 // Accessors
72 // *********
73
74 public: virtual Collection<Type>* getClone() const = 0;
75
76 public: virtual Locator<Type>* getLocator() const = 0;
77
78 public: virtual unsigned getSize() const
79 // *************************************
80 {
81 unsigned size = 0;
82 // we use a GenericLocator to delete the locator allocated by getLocator()
83 GenericLocator<Type> locator = getLocator();
84 while (locator.isValid()) {
85 size++;
86 locator.progress();
87 }
88 return size;
89 }
90
91 public: Type getFirst() const
92 // **************************
93 {
94 // we use a GenericLocator to delete the locator allocated by getLocator()
95 return GenericLocator<Type>(getLocator()).getElement();
96 }
97
98 public: GenericCollection<Type> getSubSet(const Filter<Type>& filter) const
99 // ************************************************************************
100 {
101 return SubSetCollection<Type>(*this, filter);
102 }
103
104 public: template<class SubType> GenericCollection<SubType> getSubSet() const
105 // *************************************************************************
106 {
107 return SubTypeCollection<Type, SubType>(this);
108 }
109
110 public: template<class SubType>
111 GenericCollection<SubType> getSubSet(const Filter<SubType>& filter) const
112 // ******************************************************************************
113 {
114 return getSubSet<SubType>().getSubSet(filter);
115 }
116
117 public: template<class SubType> GenericCollection<SubType> getNotSubSet() const
118 // ****************************************************************************
119 {
120 return NotSubTypeCollection<Type, SubType>(this);
121 }
122
123 // Predicates
124 // **********
125
126 public: bool isEmpty() const
127 // *************************
128 {
129 // we use a GenericLocator to delete the locator allocated by getLocator()
130 return !GenericLocator<Type>(getLocator()).isValid();
131 }
132
133 // Utilitarians
134 // ************
135
136 public: void fill(list<Type>& list) const
137 // **************************************
138 {
139 GenericLocator<Type> locator = getLocator();
140 while (locator.isValid()) {
141 list.push_back(locator.getElement());
142 locator.progress();
143 }
144 }
145
146 public: void fill(set<Type>& set) const
147 // ************************************
148 {
149 GenericLocator<Type> locator = getLocator();
150 while (locator.isValid()) {
151 set.insert(locator.getElement());
152 locator.progress();
153 }
154 }
155
156 public: template<class Compare> void fill(set<Type, Compare>& set) const
157 // *********************************************************************
158 {
159 GenericLocator<Type> locator = getLocator();
160 while (locator.isValid()) {
161 set.insert(locator.getElement());
162 locator.progress();
163 }
164 }
165
166 public: void fill(vector<Type>& vector) const
167 // ******************************************
168 {
169 GenericLocator<Type> locator = getLocator();
170 while (locator.isValid()) {
171 vector.push_back(locator.getElement());
172 locator.progress();
173 }
174 }
175
176 // Others
177 // ******
178
179 public: virtual string _getTypeName() const
180 // **************************************
181 {
182 return _TName("Collection<Type>");
183 };
184
185 public: virtual string _getString() const = 0;
186
187 public: Record* _getRecord() const
188 // *************************
189 {
190 Record* record = NULL;
191 if (!isEmpty()) {
192 record = new Record(getString(this));
193 unsigned n = 1;
194 GenericLocator<Type> locator = getLocator();
195 while (locator.isValid()) {
196 string slotName = getString(n++);
197 Type slotRecord = locator.getElement();
198 record->add(getSlot(slotName, slotRecord));
199 locator.progress();
200 }
201 }
202 return record;
203 }
204
205 public:
206 class iterator {
207 public:
208 iterator ( Locator<Type>* l ) : _locator(l) {}
209 ~iterator () { delete _locator; }
210 bool operator== ( const iterator& o) const { return not (*this != o); }
211 iterator& operator++ () { _locator->progress(); return *this; }
212 Type operator* () { return _locator->getElement(); }
213 bool operator!= ( const iterator& o ) const
214 {
215 bool invalidA = ( _locator == NULL) or not ( _locator->isValid());
216 bool invalidB = (o._locator == NULL) or not (o._locator->isValid());
217 return invalidA != invalidB or (not invalidA and not invalidB and _locator != o._locator);
218 }
219 private:
220 Locator<Type>* _locator;
221 };
222
223 public:
224 iterator begin() { return iterator(getLocator()); }
225 iterator end() { return iterator(NULL); }
226 bool empty() { return begin() == end(); }
227 };
228
229
230
231 // ****************************************************************************************************
232 // GenericCollection declaration
233 // ****************************************************************************************************
234
235 template<class Type> class GenericCollection : public Collection<Type> {
236 // *******************************************************************
237
238 // Types
239 // *****
240
241 public: typedef Collection<Type> Inherit;
242
243 // Attributes
244 // **********
245
246 private: Collection<Type>* _collection;
247
248 // Constructors
249 // ************
250
251 public: GenericCollection()
252 // ***********************
253 : Inherit(),
254 _collection(NULL)
255 {
256 }
257
258 public: GenericCollection(const Collection<Type>& collection)
259 // **********************************************************
260 : Inherit(),
261 _collection(collection.getClone())
262 {
263 }
264
265 public: GenericCollection(const GenericCollection<Type>& genericCollection)
266 // ************************************************************************
267 : Inherit(),
268 _collection(genericCollection.getClone())
269 {
270 }
271
272 public: GenericCollection(Collection<Type>* collection)
273 // *************************************************************
274 // CAUTION : collection will be deleted by the GenericCollection
275 // *************************************************************
276 : Inherit(),
277 _collection(collection)
278 {
279 }
280
281 // Destructor
282 // **********
283
284 public: virtual ~GenericCollection()
285 // *********************************
286 {
287 if (_collection) delete _collection;
288 }
289
290 // Operators
291 // *********
292
293 public: GenericCollection& operator=(const Collection<Type>& collection)
294 // *********************************************************************
295 {
296 if (_collection) delete _collection;
297 _collection = collection.getClone();
298 return *this;
299 }
300
301 public: GenericCollection& operator=(const GenericCollection& genericCollection)
302 // *****************************************************************************
303 {
304 if (_collection) delete _collection;
305 _collection = genericCollection.getClone();
306 return *this;
307 }
308
309 public: GenericCollection& operator=(Collection<Type>* collection)
310 // ***************************************************************
311 // CAUTION : collection will be deleted by the GenericCollection
312 // ***************************************************************
313 {
314 if (_collection) delete _collection;
315 _collection = collection;
316 return *this;
317 }
318
319 // Accessors
320 // *********
321
322 public: virtual Collection<Type>* getClone() const
323 // ***********************************************
324 {
325 return (_collection) ? _collection->getClone() : NULL;
326 }
327
328 public: virtual Locator<Type>* getLocator() const
329 // **********************************************
330 {
331 return (_collection) ? _collection->getLocator() : NULL;
332 }
333
334 public: virtual unsigned getSize() const
335 // *************************************
336 {
337 return (_collection) ? _collection->getSize() : 0;
338 }
339
340 // Others
341 // ******
342
343 public: virtual string _getTypeName() const
344 // **************************************
345 {
346 return _TName("GenericCollection");
347 };
348
349 public: virtual string _getString() const
350 // **************************************
351 {
352 if (!_collection)
353 return "<" + _getTypeName() + " unbound>";
354 else
355 return "<" + _getTypeName()+ " " + getString(_collection) + ">";
356 }
357
358 };
359
360
361
362 // ****************************************************************************************************
363 // ElementCollection declaration
364 // ****************************************************************************************************
365
366 template<class Type> class ElementCollection : public Collection<Type> {
367 // *********************************************************************
368
369 // -----------------------------------------------------------------
370 // Sub-Class : "::ElementCollection::Locator".
371 public: template<class ElType> class Locator : public Hurricane::Locator<ElType> {
372
373 // Attributes
374 // **********
375 protected: const ElType _element;
376 protected: bool _done;
377
378 // Constructors
379 // ************
380 public: Locator ( const ElType _element ) : _element(_element), _done(false) {};
381 public: Locator ( const Locator &locator ) : _element(locator._element), _done(locator._done) {};
382
383 // Accessors
384 // *********
385 public: virtual ElType getElement () const { return const_cast<ElType>(_element); };
386 public: virtual Locator<ElType>* getClone () const { return new Locator(*this); };
387 public: virtual bool isValid () const { return !_done; };
388 public: virtual void progress () { _done = true; };
389
390 // Hurricane Management
391 // ********************
392 public: virtual string _getString () const {
393 if (!_element)
394 return "<" + _TName("ElementCollection::Locator") + " unbound>";
395 else
396 return "<" + _TName("ElementCollection::Locator") + " " + getString(_element) + ">";
397 }
398
399 };
400
401 // Types
402 // *****
403
404 public: typedef Collection<Type> Inherit;
405
406 // Attributes
407 // **********
408
409 private: Type _element;
410
411 // Constructors
412 // ************
413
414 public: ElementCollection()
415 // ***********************
416 : Inherit(),
417 _element(NULL)
418 {
419 }
420
421 public: ElementCollection(const Type element)
422 // **********************************************************
423 : Inherit(),
424 _element(element)
425 {
426 }
427
428 public: ElementCollection(const ElementCollection<Type>& elementCollection)
429 // ************************************************************************
430 : Inherit(),
431 _element(elementCollection._element)
432 {
433 }
434
435 // Accessors
436 // *********
437
438 public: virtual Collection<Type>* getClone() const
439 // ***********************************************
440 {
441 return ( new ElementCollection (*this) );
442 }
443
444 public: virtual Locator<Type>* getLocator() const
445 // **********************************************
446 {
447 return ( new Locator<Type> (_element) );
448 }
449
450 public: virtual unsigned getSize() const
451 // *************************************
452 {
453 return (_element) ? 1 : 0;
454 }
455
456 // Others
457 // ******
458
459 public: virtual string _getString() const
460 // **************************************
461 {
462 if (!_element)
463 return "<" + _TName("ElementCollection") + " unbound>";
464 else
465 return "<" + _TName("ElementCollection") + " " + getString(_element) + ">";
466 }
467
468 };
469
470
471
472 // ****************************************************************************************************
473 // SubTypeCollection declaration
474 // ****************************************************************************************************
475
476 template<class Type, class SubType> class SubTypeCollection : public Collection<SubType> {
477 // *************************************************************************************
478
479 // Types
480 // *****
481
482 public: typedef Collection<SubType> Inherit;
483
484 public: class Locator : public Hurricane::Locator<SubType> {
485 // *******************************************************
486
487 // Types
488 // *****
489
490 public: typedef Hurricane::Locator<SubType> Inherit;
491
492 // Attributes
493 // **********
494
495 private: GenericLocator<Type> _locator;
496
497 // Constructors
498 // ************
499
500 public: Locator(const GenericCollection<Type>& collection)
501 // ********************************************************
502 : Inherit(),
503 _locator(collection.getLocator())
504 {
505 while (_locator.isValid() && !dynamic_cast<SubType>(_locator.getElement()))
506 _locator.progress();
507 }
508
509 public: Locator(const GenericLocator<Type>& genericLocator)
510 // ********************************************************
511 : Inherit(),
512 _locator(genericLocator.getClone())
513 {
514 while (_locator.isValid() && !dynamic_cast<SubType>(_locator.getElement()))
515 _locator.progress();
516 }
517
518 // Accessors
519 // *********
520
521 public: virtual SubType getElement() const
522 // ***************************************
523 {
524 return (_locator.isValid()) ? (SubType)_locator.getElement() : SubType();
525 }
526
527 public: virtual Hurricane::Locator<SubType>* getClone() const
528 // **********************************************************
529 {
530 return new Locator(_locator);
531 }
532
533 public: virtual Hurricane::Locator<SubType>* getLocator() // 21-10-03
534 // *************************************************
535 {
536 return dynamic_cast<Hurricane::Locator<SubType>*> (
537 _locator.getLocator()->getLocator() );
538 }
539
540
541 // Predicates
542 // **********
543
544 public: virtual bool isValid() const
545 // *********************************
546 {
547 return _locator.isValid();
548 }
549
550 // Updators
551 // ********
552
553 public: virtual void progress()
554 // ****************************
555 {
556 if (_locator.isValid()) {
557 do {
558 _locator.progress();
559 } while (_locator.isValid() && !dynamic_cast<SubType>(_locator.getElement()));
560 }
561 }
562
563 };
564
565 // Attributes
566 // **********
567
568 private: GenericCollection<Type> _collection;
569
570 // Constructors
571 // ************
572
573 public: SubTypeCollection()
574 // ********************
575 : Inherit(),
576 _collection()
577 {
578 }
579
580 public: SubTypeCollection(const Collection<Type>* collection)
581 // **********************************************************
582 : Inherit(),
583 _collection(collection->getClone())
584 {
585 }
586
587 public: SubTypeCollection(const GenericCollection<Type>& collection)
588 // *****************************************************************
589 : Inherit(),
590 _collection(collection)
591 {
592 }
593
594 public: SubTypeCollection(const SubTypeCollection& subTypeCollection)
595 // ******************************************************************
596 : Inherit(),
597 _collection(subTypeCollection._collection)
598 {
599 }
600
601 // Operators
602 // *********
603
604 public: SubTypeCollection& operator=(const SubTypeCollection& subTypeCollection)
605 // *****************************************************************************
606 {
607 _collection = subTypeCollection._collection;
608 return *this;
609 }
610
611 // Accessors
612 // *********
613
614 public: virtual Collection<SubType>* getClone() const
615 // **************************************************
616 {
617 return new SubTypeCollection(_collection);
618 }
619
620 public: virtual Hurricane::Locator<SubType>* getLocator() const
621 // ************************************************************
622 {
623 return new Locator(_collection);
624 }
625
626 // Accessors
627 // *********
628
629 public: virtual string _getString() const
630 // **************************************
631 {
632 return "<" + _TName("SubTypeCollection") + " " + getString(_collection) + ">";
633 }
634
635 };
636
637
638 // ****************************************************************************************************
639 // NotSubTypeCollection declaration
640 // ****************************************************************************************************
641
642 template<class Type, class SubType> class NotSubTypeCollection : public Collection<SubType> {
643 // ******************************************************************************************
644
645 // Types
646 // *****
647
648 public: typedef Collection<SubType> Inherit;
649
650 public: class Locator : public Hurricane::Locator<SubType> {
651 // *******************************************************
652
653 // Types
654 // *****
655
656 public: typedef Hurricane::Locator<SubType> Inherit;
657
658 // Attributes
659 // **********
660
661 private: GenericLocator<Type> _locator;
662
663 // Constructors
664 // ************
665
666 public: Locator(const GenericCollection<Type>& collection)
667 // ********************************************************
668 : Inherit(),
669 _locator(collection.getLocator())
670 {
671 while (_locator.isValid() && dynamic_cast<SubType>(_locator.getElement()))
672 _locator.progress();
673 }
674
675 public: Locator(const GenericLocator<Type>& genericLocator)
676 // ********************************************************
677 : Inherit(),
678 _locator(genericLocator.getClone())
679 {
680 while (_locator.isValid() && !dynamic_cast<SubType>(_locator.getElement()))
681 _locator.progress();
682 }
683
684 // Accessors
685 // *********
686
687 public: virtual SubType getElement() const
688 // ***************************************
689 {
690 return (_locator.isValid()) ? (SubType)_locator.getElement() : SubType();
691 }
692
693 public: virtual Hurricane::Locator<SubType>* getClone() const
694 // **********************************************************
695 {
696 return new Locator(_locator);
697 }
698
699 public: virtual Hurricane::Locator<SubType>* getLocator() // 21-10-03
700 // *************************************************
701 {
702 return dynamic_cast<Hurricane::Locator<SubType>*> (
703 _locator.getLocator()->getLocator() );
704 }
705
706
707 // Predicates
708 // **********
709
710 public: virtual bool isValid() const
711 // *********************************
712 {
713 return _locator.isValid();
714 }
715
716 // Updators
717 // ********
718
719 public: virtual void progress()
720 // ****************************
721 {
722 if (_locator.isValid()) {
723 do {
724 _locator.progress();
725 } while (_locator.isValid() && !dynamic_cast<SubType>(_locator.getElement()));
726 }
727 }
728
729 };
730
731 // Attributes
732 // **********
733
734 private: GenericCollection<Type> _collection;
735
736 // Constructors
737 // ************
738
739 public: NotSubTypeCollection()
740 // ********************
741 : Inherit(),
742 _collection()
743 {
744 }
745
746 public: NotSubTypeCollection(const Collection<Type>* collection)
747 // **********************************************************
748 : Inherit(),
749 _collection(collection->getClone())
750 {
751 }
752
753 public: NotSubTypeCollection(const GenericCollection<Type>& collection)
754 // *****************************************************************
755 : Inherit(),
756 _collection(collection)
757 {
758 }
759
760 public: NotSubTypeCollection(const NotSubTypeCollection& subTypeCollection)
761 // ******************************************************************
762 : Inherit(),
763 _collection(subTypeCollection._collection)
764 {
765 }
766
767 // Operators
768 // *********
769
770 public: NotSubTypeCollection& operator=(const NotSubTypeCollection& subTypeCollection)
771 // *****************************************************************************
772 {
773 _collection = subTypeCollection._collection;
774 return *this;
775 }
776
777 // Accessors
778 // *********
779
780 public: virtual Collection<SubType>* getClone() const
781 // **************************************************
782 {
783 return new NotSubTypeCollection(_collection);
784 }
785
786 public: virtual Hurricane::Locator<SubType>* getLocator() const
787 // ************************************************************
788 {
789 return new Locator(_collection);
790 }
791
792 // Accessors
793 // *********
794
795 public: virtual string _getString() const
796 // **************************************
797 {
798 return "<" + _TName("NotSubTypeCollection") + " " + getString(_collection) + ">";
799 }
800
801 };
802
803
804 // ****************************************************************************************************
805 // SubSetCollection implementation
806 // ****************************************************************************************************
807
808 template<class Type> class SubSetCollection : public Collection<Type> {
809 // ******************************************************************
810
811 // Types
812 // *****
813
814 public: typedef Collection<Type> Inherit;
815
816 public: class Locator : public Hurricane::Locator<Type> {
817 // ****************************************************
818
819 // Types
820 // *****
821
822 public: typedef Hurricane::Locator<Type> Inherit;
823
824 // Attributes
825 // **********
826
827 private: GenericLocator<Type> _locator;
828 private: GenericFilter<Type> _filter;
829
830 // Constructors
831 // ************
832
833 public: Locator(const SubSetCollection<Type>& collection, const Filter<Type>& filter)
834 // **********************************************************************************
835 : Inherit(),
836 _locator(collection.getLocator()),
837 _filter(filter)
838 {
839 while (_locator.isValid() && !_filter.accept(_locator.getElement()))
840 _locator.progress();
841 }
842
843 public: Locator(const Collection<Type>& collection, const Filter<Type>& filter)
844 // ****************************************************************************
845 : Inherit(),
846 _locator(collection.getLocator()),
847 _filter(filter)
848 {
849 while (_locator.isValid() && !_filter.accept(_locator.getElement()))
850 _locator.progress();
851 }
852
853 public: Locator(const GenericCollection<Type>& genericCollection, const Filter<Type>& filter)
854 // ******************************************************************************************
855 : Inherit(),
856 _locator(genericCollection.getLocator()),
857 _filter(filter)
858 {
859 while (_locator.isValid() && !_filter.accept(_locator.getElement()))
860 _locator.progress();
861 }
862
863 public: Locator(const GenericLocator<Type>& genericLocator, const Filter<Type>& filter)
864 // ************************************************************************************
865 : Inherit(),
866 _locator(genericLocator),
867 _filter(filter)
868 {
869 while (_locator.isValid() && !_filter.accept(_locator.getElement()))
870 _locator.progress();
871 }
872
873 // Accessors
874 // *********
875
876 public: virtual Type getElement() const
877 // ************************************
878 {
879 return (_locator.isValid()) ? _locator.getElement() : Type();
880 }
881
882 public: virtual Hurricane::Locator<Type>* getClone() const
883 // *******************************************************
884 {
885 return new Locator(_locator, _filter);
886 }
887
888 public: virtual Hurricane::Locator<Type>* getLocator() // 21-10-03
889 // ***************************************************
890 {
891 return ( _locator.getLocator()->getLocator() );
892 }
893
894 // Predicates
895 // **********
896
897 public: virtual bool isValid() const
898 // *********************************
899 {
900 return _locator.isValid();
901 }
902
903 // Updators
904 // ********
905
906 public: virtual void progress()
907 // ****************************
908 {
909 if (_locator.isValid()) {
910 do {
911 _locator.progress();
912 } while (_locator.isValid() && !_filter.accept(_locator.getElement()));
913 }
914 }
915
916 };
917
918 // Attributes
919 // **********
920
921 private: GenericCollection<Type> _collection;
922 private: GenericFilter<Type> _filter;
923
924 // Constructors
925 // ************
926
927 public: SubSetCollection()
928 // ***********************
929 : Inherit(),
930 _collection(),
931 _filter()
932 {
933 }
934
935 public: SubSetCollection(const Collection<Type>& collection, const Filter<Type>& filter)
936 // *************************************************************************************
937 : Inherit(),
938 _collection(collection),
939 _filter(filter)
940 {
941 }
942
943 public: SubSetCollection(const SubSetCollection& subSetCollection)
944 // ***************************************************************
945 : Inherit(),
946 _collection(subSetCollection._collection),
947 _filter(subSetCollection._filter)
948 {
949 }
950
951 // Operators
952 // *********
953
954 public: SubSetCollection& operator=(const SubSetCollection& subSetCollection)
955 // **************************************************************************
956 {
957 _collection = subSetCollection._collection;
958 _filter = subSetCollection._filter;
959 return *this;
960 }
961
962 // Accessors
963 // *********
964
965 public: virtual Collection<Type>* getClone() const
966 // ***********************************************
967 {
968 return new SubSetCollection(_collection, _filter);
969 }
970
971 public: virtual Hurricane::Locator<Type>* getLocator() const
972 // *********************************************************
973 {
974 return new Locator(_collection, _filter);
975 }
976
977 // Accessors
978 // *********
979
980 public: virtual string _getString() const
981 // **************************************
982 {
983 return "<" + _TName("SubSetCollection") + " " + getString(_collection) + ">";
984 }
985
986 };
987
988
989
990 // ****************************************************************************************************
991 // Generic functions
992 // ****************************************************************************************************
993
994
995
996 // ****************************************************************************************************
997 // Macros declaration
998 // ****************************************************************************************************
999
1000 #define end_for\
1001 /**************/\
1002 }\
1003 }
1004
1005 #define for_each_object(Type, element, collection)\
1006 /*************************************************/\
1007 {\
1008 GenericLocator<Type> _locator = collection.getLocator();\
1009 while (_locator.isValid()) {\
1010 Type element = _locator.getElement();\
1011 _locator.progress();
1012
1013 #define for_each_element(Type, element, collection)\
1014 /*************************************************/\
1015 {\
1016 ElementCollection<Type>::Locator<Type>* _locator = collection.getLocator();\
1017 while (_locator->isValid()) {\
1018 Type element = _locator->getElement();\
1019 _locator->progress();
1020
1021
1022 // -------------------------------------------------------------------
1023 // Template Class : "ForEachIterator"
1024
1025
1026 template<typename Element>
1027 class ForEachIterator {
1028 public:
1029 inline ForEachIterator ( GenericCollection<Element> coll );
1030 inline bool isValid ();
1031 inline Element operator* ();
1032 inline Element operator-> ();
1033 inline ForEachIterator& operator++ (int);
1034 public:
1035 GenericCollection<Element> collection;
1036 GenericLocator<Element> locator;
1037 Element element;
1038 };
1039
1040
1041 template<typename Element>
1042 inline ForEachIterator<Element>::ForEachIterator ( GenericCollection<Element> coll )
1043 : collection(coll)
1044 , locator(collection.getLocator())
1045 , element()
1046 {
1047 if ( locator.isValid() ) element = locator.getElement();
1048 }
1049
1050
1051 template< typename Element >
1052 inline bool ForEachIterator<Element>::isValid ()
1053 {
1054 if ( locator.isValid() ) element = locator.getElement();
1055 return locator.isValid();
1056 }
1057
1058
1059 template< typename Element >
1060 inline Element ForEachIterator<Element>::operator* ()
1061 {
1062 return element;
1063 }
1064
1065
1066 template< typename Element >
1067 inline Element ForEachIterator<Element>::operator-> ()
1068 {
1069 return element;
1070 }
1071
1072
1073 template< typename Element >
1074 inline ForEachIterator<Element>& ForEachIterator<Element>::operator++ (int)
1075 {
1076 locator.progress ();
1077 return *this;
1078 }
1079
1080
1081 #define forEach(type,iterator,collection) \
1082 for ( ForEachIterator<type> iterator(collection); iterator.isValid() ; iterator++ )
1083
1084
1085 } // End of Hurricane namespace.
1086
1087
1088 template<typename Type> inline std::string getString ( Hurricane::Collection<Type>& collection )
1089 { return collection._getString(); }
1090
1091 template<typename Type> inline std::string getString ( Hurricane::Collection<Type>* collection )
1092 { return collection->_getString(); }
1093
1094 template<typename Type> inline std::string getString ( const Hurricane::Collection<Type>* collection )
1095 { return collection->_getString(); }
1096
1097 template<typename Type> inline Hurricane::Record* getRecord ( Hurricane::Collection<Type>& collection )
1098 { return collection._getRecord(); }
1099
1100 template<typename Type> inline Hurricane::Record* getRecord ( Hurricane::Collection<Type>* collection )
1101 { return collection->_getRecord(); }
1102
1103 template<typename Type> inline Hurricane::Record* getRecord ( const Hurricane::Collection<Type>* collection )
1104 { return collection->_getRecord(); }
1105
1106
1107 template<typename Type>
1108 inline void jsonWrite ( JsonWriter* w, const std::string& key, Hurricane::GenericCollection<Type> collection )
1109 {
1110 if (cdebug.enabled(19))
1111 cdebug_log(19,0) << "jsonWrite< GenericCollection<" << Hurricane::demangle(typeid(Type).name())
1112 << "> >(w,key,coll)" << " key:\"" << key << "\"" << std::endl;
1113 cdebug_tabw(19,1);
1114
1115 w->key( key );
1116 w->startArray();
1117 for ( Type element : collection ) jsonWrite( w, element );
1118 w->endArray();
1119
1120 cdebug_tabw(19,-1);
1121 }
1122
1123
1124 #include "hurricane/MultisetCollection.h"
1125 #include "hurricane/SetCollection.h"
1126 #include "hurricane/MapCollection.h"
1127 #include "hurricane/MultimapCollection.h"
1128 #include "hurricane/ListCollection.h"
1129 #include "hurricane/VectorCollection.h"
1130
1131
1132
1133
1134 #endif // HURRICANE_COLLECTION
1135
1136
1137 // ****************************************************************************************************
1138 // Copyright (c) BULL S.A. 2000-2018, All Rights Reserved
1139 // ****************************************************************************************************
Hurricane::Collection
Collection description (API)
Definition: Collection.h:39
Hurricane::Locator::isValid
virtual bool isValid() const =0
Hurricane::SubTypeCollection
Applies a Type Filter to a Collection.
Definition: Collection.h:29
Hurricane::Collection::getFirst
Type getFirst() const
Definition: Collection.h:91
Hurricane::GenericLocator
Generic Locator auto-pointer.
Definition: Locator.h:113
Hurricane::demangle
string demangle(const char *symbol)
Hurricane::SubSetCollection
Applies a Filter to a Collection.
Definition: Collection.h:31
Hurricane::SubSetCollection::SubSetCollection
SubSetCollection(const SubSetCollection &subSetCollection)
Definition: Collection.h:943
Hurricane::Collection::getLocator
virtual Locator< Type > * getLocator() const =0
Hurricane::SubTypeCollection::SubTypeCollection
SubTypeCollection(const SubTypeCollection &subTypeCollection)
Definition: Collection.h:594
Hurricane::Collection::getSubSet
GenericCollection< SubType > getSubSet(const Filter< SubType > &filter) const
Definition: Collection.h:111
Hurricane::GenericCollection
Generic Collection auto-pointer.
Definition: Collection.h:28
Hurricane::Collection::~Collection
virtual ~Collection()
Definition: Collection.h:58
Hurricane::SubTypeCollection::SubTypeCollection
SubTypeCollection(const Collection< Type > *collection)
Definition: Collection.h:580
Hurricane::Collection::getSize
virtual unsigned getSize() const
Definition: Collection.h:78
Hurricane::Locator
Locator description (API)
Definition: Locator.h:33
Hurricane::Collection::getSubSet
GenericCollection< Type > getSubSet(const Filter< Type > &filter) const
Definition: Collection.h:98
Hurricane::Collection::getSubSet
GenericCollection< SubType > getSubSet() const
Definition: Collection.h:104
Hurricane::GenericCollection::GenericCollection
GenericCollection(Collection< Type > *collection)
Definition: Collection.h:272
Hurricane::GenericCollection::GenericCollection
GenericCollection(const GenericCollection< Type > &genericCollection)
Definition: Collection.h:265
Hurricane::GenericCollection::GenericCollection
GenericCollection(const Collection< Type > &collection)
Definition: Collection.h:258
Hurricane::Filter
Filter description (API)
Definition: Filter.h:36
Hurricane::Collection::getClone
virtual Collection< Type > * getClone() const =0
Hurricane
The namespace dedicated to Hurricane.
Definition: Generalities.dox:5
Hurricane::SubSetCollection::SubSetCollection
SubSetCollection(const Collection< Type > &collection, const Filter< Type > &filter)
Definition: Collection.h:935
Hurricane::SubTypeCollection::SubTypeCollection
SubTypeCollection(const GenericCollection< Type > &collection)
Definition: Collection.h:587
tstream::enabled
bool enabled() const
Definition: Commons.h:1047

Generated by doxygen 1.8.14 on Tue Jul 21 2020 | Return to top of page

Hurricane VLSI Database | Copyright © 2000-2016 Bull S.A. All rights reserved