# Hurricane VLSI Database

Commons.h
1 // -*- C++ -*-
2 //
3 // Copyright (c) BULL S.A. 2000-2018, All Rights Reserved
4 //
5 // This file is part of Hurricane.
6 //
7 // Hurricane is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Lesser General Public License as
9 // 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
13 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-
14 // TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the Lesser GNU General Public
18 // License along with Hurricane. If not, see
19 // <http://www.gnu.org/licenses/>.
20 //
21 // +-----------------------------------------------------------------+
22 // | H U R R I C A N E |
23 // | V L S I B a c k e n d D a t a - B a s e |
24 // | |
25 // | Author : Remy Escassut |
26 // | E-mail : Jean-Paul.Chaput@lip6.fr |
27 // | =============================================================== |
28 // | C++ Header : "./hurricane/Commons.h" |
29 // +-----------------------------------------------------------------+
30
31
32 #ifndef HURRICANE_COMMONS_H
33 #define HURRICANE_COMMONS_H
34
35 #include <cstdio>
36 #include <cassert>
37 #include <cmath>
38 #include <memory>
39 #include <string>
40 #include <list>
41 #include <set>
42 #include <map>
43 #include <stack>
44 #include <array>
45 #include <vector>
46 #include <iostream>
47 #include <iomanip>
48 #include <fstream>
49 #include <sstream>
50
51
52 // +-----------------------------------------------------------------+
53 // | Macros Definition |
54 // +-----------------------------------------------------------------+
55
56
57 namespace Hurricane {
58
59 using namespace std;
60
61 class Slot;
62
63
64 // +-------------------------------------------------------------+
65 // | shared_ptr<> support for DBo |
66 // +-------------------------------------------------------------+
67
68
69 template<typename DboType>
70 class DboDestroy {
71 public:
72 inline void operator() ( DboType* dbo ) { dbo->destroy(); }
73 };
74
75
76 template<typename DboType>
77 class dbo_ptr : public std::shared_ptr<DboType> {
78 public:
79 dbo_ptr ( DboType* dbo ) : std::shared_ptr<DboType>(dbo,DboDestroy<DboType>()) { }
80 };
81
82
83
84
85 // +-------------------------------------------------------------+
86 // | Miscellaneous Utilites |
87 // +-------------------------------------------------------------+
88
89
90 inline string _TName ( const string& s ) { return s; }
91 inline string _PName ( const string& s ) { return "Hurricane::" + s; }
92
93 template<class Type>
94 inline Type abs ( const Type& value ) { return (value<0) ? -value : value; }
95
96 string demangle ( const char* symbol );
97 inline string demangle ( string symbol ) { return demangle(symbol.c_str()); }
98 inline string demangle ( const type_info& info ) { return demangle(info.name()); }
99
100 template<typename Element>
101 inline void erase_element ( vector<Element*>& v, const Element* e )
102 {
103 for ( auto ielement = v.begin() ; ielement != v.end() ; ++ielement )
104 if (*ielement == e) { v.erase( ielement ); return; }
105 }
106
107
108 #if DEPRECATED
109 // For a complete explanation of this function, please look at :
110 // http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
111
112 inline int floatCompare ( float a, float b )
113 {
114 assert ( sizeof(float) == sizeof(int) );
115
116 if ( a == b ) return 0;
117 return *(int*)&a - *(int*)&b;
118 }
119
120 inline int floatDifference ( float a, float b, int threshold )
121 {
122 int difference = floatCompare(a,b);
123 if ( abs(difference) < threshold ) return 0;
124
125 return (difference<0) ? -1 : 1;
126 }
127
128
129 inline void floatRound ( float& value, float precision )
130 {
131 float rounded = roundf ( value*precision );
132 value = rounded / precision;
133 }
134 #endif
135
136 inline float roundfp ( float value, float precision=100.0 ) { return roundf(value*precision)/precision; }
137
138
139 template<typename Type> inline void order ( Type& a, Type& b ) { if (a>b) std::swap(a,b); }
140
141 template<typename Type> inline Type setInBound ( Type lower, Type upper, Type& value )
142 {
143 if (value < lower) value = lower;
144 else if (value > upper) value = upper;
145 return value;
146 }
147
148
149 } // End of Hurricane namespace.
150
151
152 #include "hurricane/Record.h"
153
154
155 // +-----------------------------------------------------------------+
156 // | Functions for Inspector Support |
157 // +-----------------------------------------------------------------+
158
159 // Note 1: Theses are specialized templates for "getString<>()" & "getRecord<>()".
160 // Note 2: we are outside the Hurricane namespace.
161 // Note 3: thoses templates manage all POD & STL types.
162
163
164 // Forward declaration of "getSlot<>()" template.
165
166 template<typename Data> inline Hurricane::Slot* getSlot ( std::string name, Data );
167 template<typename Data> inline Hurricane::Slot* getSlot ( std::string name, Data* );
168
169
170 // -------------------------------------------------------------------
171 // Inspector Support for : "POD types".
172
173 // Default match.
174
175 template<typename Data> inline std::string getString ( Data data )
176 { return std::string("<type ")
177 + Hurricane::demangle(typeid(data).name())
178 + std::string(" unsupported by getString()>"); }
179
180 // "const &" flavors.
181
182 template<> inline std::string getString<const bool> ( const bool b )
183 { return (b)?"True":"False" ; }
184
185 template<> inline std::string getString<const int> ( const int i )
186 { std::ostringstream os (""); os << i; return os.str(); }
187
188 template<> inline std::string getString<const long> ( const long l )
189 { std::ostringstream os (""); os << l; return os.str(); }
190
191 template<> inline std::string getString<const unsigned int> ( const unsigned int u )
192 { std::ostringstream os (""); os << u; return os.str(); }
193
194 template<> inline std::string getString<const unsigned long> ( const unsigned long ul )
195 { std::ostringstream os (""); os << ul; return os.str(); }
196
197 template<> inline std::string getString<const unsigned long long> ( const unsigned long long ull )
198 { std::ostringstream os (""); os << ull; return os.str(); }
199
200 template<> inline std::string getString<const unsigned short int> ( const unsigned short int us )
201 { std::ostringstream os (""); os << us; return os.str(); }
202
203 template<> inline std::string getString<const float> ( const float f )
204 { std::ostringstream os (""); os << f; return os.str(); }
205
206 template<> inline std::string getString<const double> ( const double d )
207 { std::ostringstream os; os << d; return os.str(); }
208
209 template<> inline std::string getString<const std::string> ( const std::string s )
210 { return s; }
211
212 // "const *" flavors.
213
214 template<> inline std::string getString<const bool*> ( const bool* b )
215 { return (*b)?"True":"False" ; }
216
217 template<> inline std::string getString<const char*> ( const char* c )
218 { return c; }
219
220 template<> inline std::string getString<const int*> ( const int* i )
221 { std::ostringstream os (""); os << *i; return os.str(); }
222
223 template<> inline std::string getString<const long*> ( const long* l )
224 { std::ostringstream os (""); os << *l; return os.str(); }
225
226 template<> inline std::string getString<const unsigned int*> ( const unsigned int* u )
227 { std::ostringstream os (""); os << *u; return os.str(); }
228
229 template<> inline std::string getString<const unsigned long*> ( const unsigned long* ul )
230 { std::ostringstream os (""); os << *ul; return os.str(); }
231
232 template<> inline std::string getString<const unsigned long long*> ( const unsigned long long* ull )
233 { std::ostringstream os (""); os << *ull; return os.str(); }
234
235 template<> inline std::string getString<const unsigned short int*> ( const unsigned short int* us )
236 { std::ostringstream os (""); os << *us; return os.str(); }
237
238 template<> inline std::string getString<const float*> ( const float* f )
239 { std::ostringstream os (""); os << *f; return os.str(); }
240
241 template<> inline std::string getString<const double*> ( const double* d )
242 { std::ostringstream os; os << *d; return os.str(); }
243
244 template<> inline std::string getString<const void*> ( const void* p )
245 { std::ostringstream os ("0x"); os << std::hex << p; return os.str(); }
246
247 template<> inline std::string getString<const std::string*> ( const std::string* s )
248 { return *s; }
249
250
251 // "*" flavors.
252
253 template<> inline std::string getString<bool*> ( bool* b )
254 { return (*b)?"True":"False" ; }
255
256 template<> inline std::string getString<char*> ( char* c )
257 { return c; }
258
259 template<> inline std::string getString<int*> ( int* i )
260 { std::ostringstream os (""); os << *i; return os.str(); }
261
262 template<> inline std::string getString<long*> ( long* l )
263 { std::ostringstream os (""); os << *l; return os.str(); }
264
265 template<> inline std::string getString<unsigned int*> ( unsigned int* u )
266 { std::ostringstream os (""); os << *u; return os.str(); }
267
268 template<> inline std::string getString<unsigned long*> ( unsigned long* ul )
269 { std::ostringstream os (""); os << *ul; return os.str(); }
270
271 template<> inline std::string getString<unsigned long long*> ( unsigned long long* ull )
272 { std::ostringstream os (""); os << *ull; return os.str(); }
273
274 template<> inline std::string getString<unsigned short int*> ( unsigned short int* us )
275 { std::ostringstream os (""); os << *us; return os.str(); }
276
277 template<> inline std::string getString<float*> ( float* f )
278 { std::ostringstream os (""); os << *f; return os.str(); }
279
280 template<> inline std::string getString<double*> ( double* d )
281 { std::ostringstream os; os << *d; return os.str(); }
282
283 template<> inline std::string getString<void*> ( void* p )
284 { std::ostringstream os ("0x"); os << std::hex << p; return os.str(); }
285
286 template<> inline std::string getString<std::string*> ( std::string* s )
287 { return *s; }
288
289
290 // "by value" flavors.
291
292 template<> inline std::string getString<bool> ( bool b )
293 { return (b)?"True":"False" ; }
294
295 template<> inline std::string getString<char> ( char c )
296 { return std::string(1,c); }
297
298 template<> inline std::string getString<int> ( int i )
299 { std::ostringstream os (""); os << i; return os.str(); }
300
301 template<> inline std::string getString<long> ( long l )
302 { std::ostringstream os (""); os << l; return os.str(); }
303
304 template<> inline std::string getString<unsigned int> ( unsigned int u )
305 { std::ostringstream os (""); os << u; return os.str(); }
306
307 template<> inline std::string getString<unsigned long> ( unsigned long ul )
308 { std::ostringstream os (""); os << ul; return os.str(); }
309
310 template<> inline std::string getString<unsigned long long> ( unsigned long long ull )
311 { std::ostringstream os (""); os << ull; return os.str(); }
312
313 template<> inline std::string getString<unsigned short int> ( unsigned short int us )
314 { std::ostringstream os (""); os << us; return os.str(); }
315
316 template<> inline std::string getString<float> ( float f )
317 { std::ostringstream os (""); os << f; return os.str(); }
318
319 template<> inline std::string getString<double> ( double d )
320 { std::ostringstream os; os << d; return os.str(); }
321
322 template<> inline std::string getString<std::string> ( std::string s )
323 { return s; }
324
325
326 template<typename Data> inline Hurricane::Record* getRecord ( Data data )
327 { return NULL; }
328
329
330 // -------------------------------------------------------------------
331 // Inspector Support for : "[const] std::pair<T,U>&".
332
333 template<typename T, typename U>
334 inline std::string getString ( const std::pair<T,U>& p )
335 {
336 return "const std::pair<T,U>";
337 }
338
339
340 template<typename T, typename U>
341 inline Hurricane::Record* getRecord ( const std::pair<T,U>& p )
342 {
343 Hurricane::Record* record = NULL;
344 record = new Hurricane::Record ( "const std::pair<T,U>" );
345 record->add( getSlot<const T>(std::string("first" ), &p.first ) );
346 record->add( getSlot<const U>(std::string("second"), &p.second) );
347 return record;
348 }
349
350
351 template<typename T, typename U>
352 inline std::string getString ( std::pair<T,U>& p )
353 {
354 return "std::pair<T,U>";
355 }
356
357
358 template<typename T, typename U>
359 inline Hurricane::Record* getRecord ( std::pair<T,U>& p )
360 {
361 Hurricane::Record* record = NULL;
362 record = new Hurricane::Record ( "std::pair<T,U>" );
363 record->add( getSlot<T>(std::string("first" ), &p.first ) );
364 record->add( getSlot<U>(std::string("second"), &p.second) );
365 return record;
366 }
367
368
369 // -------------------------------------------------------------------
370 // Inspector Support for : "[const] std::array<Element>*".
371
372
373 template<typename Element,size_t N>
374 inline std::string getString ( std::array<Element,N>* v )
375 {
376 std::string name = "const std::array<Element,N>:";
377 return name + getString<size_t>(v->size());
378 }
379
380
381 template<typename Element,size_t N>
382 inline Hurricane::Record* getRecord ( std::array<Element,N>* v )
383 {
384 Hurricane::Record* record = NULL;
385 if ( !v->empty() ) {
386 record = new Hurricane::Record ( "std::array<Element,N>" );
387 unsigned n = 0;
388 typename std::array<Element,N>::iterator iterator = v->begin();
389 while ( iterator != v->end() ) {
390 record->add ( getSlot<Element>(getString(n++), *iterator) );
391 ++iterator;
392 }
393 }
394 return record;
395 }
396
397
398 template<typename Element,size_t N>
399 inline std::string getString ( const std::array<Element,N>* v )
400 {
401 std::string name = "const std::array<Element,N>:";
402 return name + getString<size_t>(v->size());
403 }
404
405
406 template<typename Element,size_t N>
407 inline Hurricane::Record* getRecord ( const std::array<Element,N>* v )
408 {
409 Hurricane::Record* record = NULL;
410 if ( !v->empty() ) {
411 record = new Hurricane::Record ( "const std::array<Element,N>" );
412 unsigned n = 0;
413 typename std::array<Element,N>::const_iterator iterator = v->begin();
414 while ( iterator != v->end() ) {
415 record->add ( getSlot<const Element>(getString(n++), *iterator) );
416 ++iterator;
417 }
418 }
419 return record;
420 }
421
422
423 template<typename Element,size_t N>
424 inline std::string getString ( std::array<Element,N>& v )
425 {
426 std::string name = "std::array<Element,N>&:";
427 return name + getString<size_t>(v.size());
428 }
429
430
431 template<typename Element,size_t N>
432 inline Hurricane::Record* getRecord ( std::array<Element,N>& v )
433 {
434 Hurricane::Record* record = NULL;
435 if (not v.empty()) {
436 record = new Hurricane::Record ( "std::array<Element,N>&" );
437 unsigned n = 0;
438 for ( auto element : v )
439 record->add( getSlot<Element>(getString(n++), element) );
440 }
441 return record;
442 }
443
444
445 template<typename Element,size_t N>
446 inline std::string getString ( const std::array<Element,N>& v )
447 {
448 std::string name = "const std::array<Element,N>&:";
449 return name + getString<size_t>(v.size());
450 }
451
452
453 template<typename Element,size_t N>
454 inline Hurricane::Record* getRecord ( const std::array<Element,N>& v )
455 {
456 Hurricane::Record* record = NULL;
457 if (not v.empty()) {
458 record = new Hurricane::Record ( "const std::array<Element,N>&" );
459 unsigned n = 0;
460 for ( auto element : v )
461 record->add( getSlot<Element>(getString(n++), element) );
462 }
463 return record;
464 }
465
466
467 // -------------------------------------------------------------------
468 // Inspector Support for : "[const] std::vector<Element>*".
469
470
471 template<typename Element>
472 inline std::string getString ( std::vector<Element>* v )
473 {
474 std::string name = "const std::vector<Element>:";
475 return name + getString<size_t>(v->size());
476 }
477
478
479 template<typename Element>
480 inline Hurricane::Record* getRecord ( std::vector<Element>* v )
481 {
482 Hurricane::Record* record = NULL;
483 if ( !v->empty() ) {
484 record = new Hurricane::Record ( "std::vector<Element>" );
485 unsigned n = 0;
486 typename std::vector<Element>::iterator iterator = v->begin();
487 while ( iterator != v->end() ) {
488 record->add ( getSlot<Element>(getString(n++), *iterator) );
489 ++iterator;
490 }
491 }
492 return record;
493 }
494
495
496 template<typename Element>
497 inline std::string getString ( const std::vector<Element>* v )
498 {
499 std::string name = "const std::vector<Element>:";
500 return name + getString<size_t>(v->size());
501 }
502
503
504 template<typename Element>
505 inline Hurricane::Record* getRecord ( const std::vector<Element>* v )
506 {
507 Hurricane::Record* record = NULL;
508 if ( !v->empty() ) {
509 record = new Hurricane::Record ( "const std::vector<Element>" );
510 unsigned n = 0;
511 typename std::vector<Element>::const_iterator iterator = v->begin();
512 while ( iterator != v->end() ) {
513 record->add ( getSlot<const Element>(getString(n++), *iterator) );
514 ++iterator;
515 }
516 }
517 return record;
518 }
519
520
521 // -------------------------------------------------------------------
522 // Inspector Support for : "const std::list<Element>*".
523
524
525 template<typename Element>
526 inline std::string getString ( const std::list<Element>* l )
527 {
528 std::string name = "const std::list<Element>:";
529 return name + getString<size_t>(l->size());
530 }
531
532
533 template<typename Element>
534 inline Hurricane::Record* getRecord ( const std::list<Element>* l )
535 {
536 Hurricane::Record* record = NULL;
537 if ( !l->empty() ) {
538 record = new Hurricane::Record ( "const std::list<Element>" );
539 unsigned n = 1;
540 typename std::list<Element>::const_iterator iterator = l->begin();
541 while ( iterator != l->end() ) {
542 record->add ( getSlot<const Element>(getString(n++), *iterator) );
543 ++iterator;
544 }
545 }
546 return record;
547 }
548
549
550 template<typename Element>
551 inline std::string getString ( std::list<Element>* l )
552 {
553 std::string name = "std::list<Element>:";
554 return name + getString<size_t>(l->size());
555 }
556
557
558 template<typename Element>
559 inline Hurricane::Record* getRecord ( std::list<Element>* l )
560 {
561 Hurricane::Record* record = NULL;
562 if ( !l->empty() ) {
563 record = new Hurricane::Record ( "std::list<Element>" );
564 unsigned n = 1;
565 typename std::list<Element>::iterator iterator = l->begin();
566 while ( iterator != l->end() ) {
567 record->add ( getSlot<Element>(getString(n++), *iterator) );
568 ++iterator;
569 }
570 }
571 return record;
572 }
573
574
575 // -------------------------------------------------------------------
576 // Inspector Support for : "[const] std::map<Key,Element,Compare>*.
577
578
579 template<typename Key, typename Element>
580 inline std::string getString ( std::map<Key,Element>* m )
581 {
582 std::string name = "std::map<Element>:";
583 return name + getString<size_t>(m->size());
584 }
585
586
587 template<typename Key, typename Element>
588 inline Hurricane::Record* getRecord ( std::map<Key,Element>* m )
589 {
590 Hurricane::Record* record = NULL;
591 if ( !m->empty() ) {
592 record = new Hurricane::Record ( "std::map<Element>" );
593 typename std::map<Key,Element>::iterator iterator = m->begin();
594 while ( iterator != m->end() ) {
595 record->add ( getSlot<Element>(getString(iterator->first), iterator->second) );
596 ++iterator;
597 }
598 }
599 return record;
600 }
601
602
603 template<typename Key, typename Element>
604 inline std::string getString ( const std::map<Key,Element>* m )
605 {
606 std::string name = "const std::map<Element>:";
607 return name + getString<size_t>(m->size());
608 }
609
610
611 template<typename Key, typename Element>
612 inline Hurricane::Record* getRecord ( const std::map<Key,Element>* m )
613 {
614 Hurricane::Record* record = NULL;
615 if ( !m->empty() ) {
616 record = new Hurricane::Record ( "const std::map<Element>" );
617 typename std::map<Key,Element>::const_iterator iterator = m->begin();
618 while ( iterator != m->end() ) {
619 record->add ( getSlot<const Element>(getString(iterator->first), iterator->second) );
620 ++iterator;
621 }
622 }
623 return record;
624 }
625
626
627 // -------------------------------------------------------------------
628 // Inspector Support for : "[const] std::map<Key,Element,Compare>*.
629
630
631 template<typename Key, typename Element, typename Compare>
632 inline std::string getString ( std::map<Key,Element,Compare>* m )
633 {
634 std::string name = "std::map<Element>:";
635 return name + getString<size_t>(m->size());
636 }
637
638
639 template<typename Key, typename Element, typename Compare>
640 inline Hurricane::Record* getRecord ( std::map<Key,Element,Compare>* m )
641 {
642 Hurricane::Record* record = NULL;
643 if ( !m->empty() ) {
644 record = new Hurricane::Record ( "std::map<Element>" );
645 typename std::map<Key,Element,Compare>::iterator iterator = m->begin();
646 while ( iterator != m->end() ) {
647 record->add ( getSlot<Element>(getString(iterator->first), iterator->second) );
648 ++iterator;
649 }
650 }
651 return record;
652 }
653
654
655 template<typename Key, typename Element, typename Compare>
656 inline std::string getString ( const std::map<Key,Element,Compare>* m )
657 {
658 std::string name = "const std::map<Element>:";
659 return name + getString<size_t>(m->size());
660 }
661
662
663 template<typename Key, typename Element, typename Compare>
664 inline Hurricane::Record* getRecord ( const std::map<Key,Element,Compare>* m )
665 {
666 Hurricane::Record* record = NULL;
667 if ( !m->empty() ) {
668 record = new Hurricane::Record ( "const std::map<Element>" );
669 typename std::map<Key,Element,Compare>::const_iterator iterator = m->begin();
670 while ( iterator != m->end() ) {
671 record->add ( getSlot<const Element>(getString(iterator->first), iterator->second) );
672 ++iterator;
673 }
674 }
675 return record;
676 }
677
678
679 // -------------------------------------------------------------------
680 // Inspector Support for : "const std::multimap<Key,Element,Compare>*".
681
682
683 template<typename Key, typename Element, typename Compare>
684 inline std::string getString ( const std::multimap<Key,Element,Compare>* m )
685 {
686 std::string name = "const std::multimap<Element>:";
687 return name + getString<size_t>(m->size());
688 }
689
690
691 template<typename Key, typename Element, typename Compare>
692 inline Hurricane::Record* getRecord ( const std::multimap<Key,Element,Compare>* m )
693 {
694 Hurricane::Record* record = NULL;
695 if ( !m->empty() ) {
696 record = new Hurricane::Record ( "const std::multimap<Element>" );
697 typename std::multimap<Key,Element,Compare>::const_iterator iterator = m->begin();
698 while ( iterator != m->end() ) {
699 record->add ( getSlot<const Element>(getString(iterator->first), iterator->second) );
700 ++iterator;
701 }
702 }
703 return record;
704 }
705
706
707 template<typename Key, typename Element, typename Compare>
708 inline std::string getString ( std::multimap<Key,Element,Compare>* m )
709 {
710 std::string name = "std::multimap<Element>:";
711 return name + getString<size_t>(m->size());
712 }
713
714
715 template<typename Key, typename Element, typename Compare>
716 inline Hurricane::Record* getRecord ( std::multimap<Key,Element,Compare>* m )
717 {
718 Hurricane::Record* record = NULL;
719 if ( !m->empty() ) {
720 record = new Hurricane::Record ( "std::multimap<Element>" );
721 typename std::multimap<Key,Element,Compare>::iterator iterator = m->begin();
722 while ( iterator != m->end() ) {
723 record->add ( getSlot<Element>(getString(iterator->first), iterator->second) );
724 ++iterator;
725 }
726 }
727 return record;
728 }
729
730
731 // -------------------------------------------------------------------
732 // Inspector Support for : "[const] std::set<Element,Compare>*".
733
734
735 template<typename Element, typename Compare>
736 inline std::string getString ( const std::set<Element,Compare>* s )
737 {
738 std::string name = "const std::set<Element>:";
739 return name + getString<size_t>(s->size());
740 }
741
742
743 template<typename Element, typename Compare>
744 inline Hurricane::Record* getRecord ( const std::set<Element,Compare>* s )
745 {
746 Hurricane::Record* record = NULL;
747 if ( !s->empty() ) {
748 record = new Hurricane::Record ( "const std::set<Element>" );
749 unsigned n = 1;
750 typename std::set<Element,Compare>::const_iterator iterator = s->begin();
751 while ( iterator != s->end() ) {
752 record->add ( getSlot<const Element>(getString(n++), *iterator) );
753 ++iterator;
754 }
755 }
756 return record;
757 }
758
759
760 template< typename Element, typename Compare, typename Allocator >
761 inline std::string getString ( std::set<Element,Compare,Allocator>* s )
762 {
763 std::string name = "std::set<Element>:";
764 return name + getString<size_t>(s->size());
765 }
766
767
768 template< typename Element, typename Compare, typename Allocator >
769 inline Hurricane::Record* getRecord ( std::set<Element,Compare,Allocator>* s )
770 {
771 Hurricane::Record* record = NULL;
772 if ( !s->empty() ) {
773 record = new Hurricane::Record ( "std::set<Element>" );
774 unsigned n = 1;
775 typename std::set<Element,Compare,Allocator>::iterator iterator = s->begin();
776 while ( iterator != s->end() ) {
777 record->add ( getSlot<Element>(getString(n++), *iterator) );
778 ++iterator;
779 }
780 }
781 return record;
782 }
783
784 // -------------------------------------------------------------------
785 // Inspector Support for : "[const] std::set<Element,Compare>&".
786
787
788 template<typename Element, typename Compare>
789 inline std::string getString ( const std::set<Element,Compare>& s )
790 {
791 std::string name = "const std::set<Element>:";
792 return name + getString<size_t>(s.size());
793 }
794
795
796 template<typename Element, typename Compare>
797 inline Hurricane::Record* getRecord ( const std::set<Element,Compare>& s )
798 {
799 Hurricane::Record* record = NULL;
800 if ( !s.empty() ) {
801 record = new Hurricane::Record ( "const std::set<Element>" );
802 unsigned n = 1;
803 typename std::set<Element,Compare>::const_iterator iterator = s.begin();
804 while ( iterator != s.end() ) {
805 record->add ( getSlot<Element>(getString(n++), *iterator) );
806 ++iterator;
807 }
808 }
809 return record;
810 }
811
812 // -------------------------------------------------------------------
813 // Inspector Support for : "const std::multiset<Element,Compare>*".
814
815
816 template<typename Element, typename Compare>
817 inline std::string getString ( const std::multiset<Element,Compare>* s )
818 {
819 std::string name = "std::multiset<Element>:";
820 return name + getString<size_t>(s->size());
821 }
822
823
824 template<typename Element, typename Compare>
825 inline Hurricane::Record* getRecord ( const std::multiset<Element,Compare>* s )
826 {
827 Hurricane::Record* record = NULL;
828 if ( !s->empty() ) {
829 record = new Hurricane::Record ( "std::multiset<Element>" );
830 unsigned n = 1;
831 typename std::multiset<Element,Compare>::const_iterator iterator = s->begin();
832 while ( iterator != s->end() ) {
833 record->add ( getSlot<Element>(getString(n++), *iterator) );
834 ++iterator;
835 }
836 }
837 return record;
838 }
839
840
841 # define GETSTRING_POINTER_SUPPORT(Data) \
842 template<> inline std::string getString<Data*>( Data* data ) \
843 { \
844 if (!data) return "NULL [" #Data "]"; \
845 return data->_getString(); \
846 } \
847 \
848 template<> inline std::string getString<const Data*>( const Data* data ) \
849 { if (!data) return "NULL [const " #Data "]"; return data->_getString(); }
850
851
852 # define IOSTREAM_POINTER_SUPPORT(Data) \
853 inline std::ostream& operator<< ( std::ostream& o, Data* d ) \
854 { \
855 if (!d) return o << "NULL [" #Data "]"; \
856 return o << "&" << getString<const Data*>(d); \
857 } \
858 inline std::ostream& operator<< ( std::ostream& o, const Data* d ) \
859 { \
860 if (!d) return o << "NULL [const " #Data "]"; \
861 return o << "&" << getString<const Data*>(d); \
862 } \
863
864
865 # define GETRECORD_POINTER_SUPPORT(Data) \
866 template<> inline Hurricane::Record* getRecord<Data*>( Data* data ) \
867 { if (!data) return NULL; return data->_getRecord(); } \
868 \
869 template<> inline Hurricane::Record* getRecord<const Data*>( const Data* data ) \
870 { if (!data) return NULL; return data->_getRecord(); }
871
872
873 # define GETSTRING_REFERENCE_SUPPORT(Data) \
874 template<> inline std::string getString<Data&>( Data& data ) \
875 { return data._getString(); } \
876 \
877 template<> inline std::string getString<const Data&>( const Data& data ) \
878 { return data._getString(); }
879
880
881 # define IOSTREAM_REFERENCE_SUPPORT(Data) \
882 inline std::ostream& operator<< ( std::ostream& o, Data& d ) \
883 { return o << getString<Data&>(d); } \
884 \
885 inline std::ostream& operator<< ( std::ostream& o, const Data& d ) \
886 { return o << getString<const Data&>(d); } \
887 \
888
889 # define GETRECORD_REFERENCE_SUPPORT(Data) \
890 template<> inline Hurricane::Record* getRecord<Data&>( Data& data ) \
891 { return data._getRecord(); } \
892 \
893 template<> inline Hurricane::Record* getRecord<const Data&>( const Data& data ) \
894 { return data._getRecord(); }
895
896
897 # define GETSTRING_VALUE_SUPPORT(Data) \
898 template<> inline std::string getString<Data>( Data data ) \
899 { return data._getString(); }
900
901
902 # define IOSTREAM_VALUE_SUPPORT(Data) \
903 inline std::ostream& operator<< ( std::ostream& o, Data d ) \
904 { return o << getString<Data>(d); }
905
906
907 # define GETRECORD_VALUE_SUPPORT(Data) \
908 template<> inline Hurricane::Record* getRecord<Data>( Data data ) \
909 { return data._getRecord(); }
910
911
912 # define INSPECTOR_P_SUPPORT(Data) \
913 GETRECORD_POINTER_SUPPORT(Data) \
914 GETSTRING_POINTER_SUPPORT(Data) \
915 IOSTREAM_POINTER_SUPPORT(Data)
916
917
918 # define INSPECTOR_R_SUPPORT(Data) \
919 GETRECORD_REFERENCE_SUPPORT(Data) \
920 GETSTRING_REFERENCE_SUPPORT(Data) \
921 IOSTREAM_REFERENCE_SUPPORT(Data)
922
923
924 # define INSPECTOR_V_SUPPORT(Data) \
925 GETRECORD_VALUE_SUPPORT(Data) \
926 GETSTRING_VALUE_SUPPORT(Data) \
927 IOSTREAM_VALUE_SUPPORT(Data)
928
929
930 # define INSPECTOR_PR_SUPPORT(Data) \
931 GETRECORD_POINTER_SUPPORT(Data) \
932 GETSTRING_POINTER_SUPPORT(Data) \
933 GETRECORD_REFERENCE_SUPPORT(Data) \
934 GETSTRING_REFERENCE_SUPPORT(Data) \
935 IOSTREAM_POINTER_SUPPORT(Data) \
936 IOSTREAM_REFERENCE_SUPPORT(Data)
937
938
939 # define INSPECTOR_PV_SUPPORT(Data) \
940 GETRECORD_POINTER_SUPPORT(Data) \
941 GETSTRING_POINTER_SUPPORT(Data) \
942 GETRECORD_VALUE_SUPPORT(Data) \
943 GETSTRING_VALUE_SUPPORT(Data) \
944 IOSTREAM_POINTER_SUPPORT(Data) \
945 IOSTREAM_VALUE_SUPPORT(Data)
946
947
948 #include "hurricane/Tabulation.h"
949
950
951 // -------------------------------------------------------------------
952 // Class : "::cdebug()".
953 //
954 // Wrapper around the STL ostream which to print debugging messages.
955
956 class tstream : public std::ostream {
957 public:
958 inline int getMinLevel () const;
959 inline int getMaxLevel () const;
960 inline int setMinLevel ( int );
961 inline int setMaxLevel ( int );
962 inline int getLevel () const;
963 inline int setLevel ( int );
964 inline bool enabled () const;
965 inline bool enabled ( int ) const;
966 inline tstream& log ( int level, int count=0 );
967 inline tstream& tabw ( int level, int count );
968 inline tstream ( std::ostream & );
969 inline tstream& put ( char c );
970 inline tstream& flush ();
971 private:
972 inline tstream& _tab ();
973 inline tstream& _tabw ( int count );
974 public:
975 // Overload for manipulators.
976 inline tstream& operator<< ( std::ostream& (*pf)(std::ostream &) );
977 private:
978 int _minLevel;
979 int _maxLevel;
980 int _level;
981 Hurricane::Tabulation _tabulation;
982 };
983
984
985 inline tstream::tstream ( std::ostream& s )
986 : std::ostream(s.rdbuf())
987 , _minLevel (100000)
988 , _maxLevel (0)
989 , _level (0)
990 , _tabulation(" ")
991 { }
992
993 inline int tstream::getMinLevel () const { return _minLevel; }
994 inline int tstream::getMaxLevel () const { return _maxLevel; }
995 inline int tstream::setMinLevel ( int l ) { int pl=_minLevel; _minLevel=l; return pl; }
996 inline int tstream::setMaxLevel ( int l ) { int pl=_maxLevel; _maxLevel=l; return pl; }
997 inline int tstream::getLevel () const { return _level; }
998 inline int tstream::setLevel ( int l ) { int pl=_level; _level=l; return pl; }
999 inline bool tstream::enabled () const { return (_level >= _minLevel) and (_level < _maxLevel); }
1000 inline bool tstream::enabled ( int l ) const { return (l >= _minLevel) and (l < _maxLevel); }
1001 inline tstream& tstream::tabw ( int level, int count ) { setLevel(level); return _tabw(count); }
1002 inline tstream& tstream::put ( char c ) { if (enabled()) static_cast<std::ostream*>(this)->put(c); return *this; }
1003 inline tstream& tstream::flush () { if (enabled()) static_cast<std::ostream*>(this)->flush(); return *this; }
1004 inline tstream& tstream::operator<< ( std::ostream& (*pf)(std::ostream&) ) { if (enabled()) (*pf)(*this); return *this; }
1005
1006
1007 inline tstream& tstream::_tab () { if (enabled()) (*this) << _tabulation; return *this; }
1008 inline tstream& tstream::_tabw ( int count )
1009 {
1010 if (enabled()) {
1011 if (count > 0) while(count--) _tabulation++;
1012 else if (count < 0) while(count++) _tabulation--;
1013 }
1014 return *this;
1015 }
1016
1017 inline tstream& tstream::log ( int level, int count )
1018 { setLevel(level); _tab(); return _tabw(count); }
1019
1020 // For STL Types.
1021 inline tstream& operator<< ( tstream& o, const std::string s )
1022 { if (o.enabled()) { static_cast<std::ostream&>(o) << s; } return o; };
1023
1024 // For POD Types.
1025 // template<typename T>
1026 // inline tstream& operator<< ( tstream& o, T& t )
1027 // { if (o.enabled()) { static_cast<std::ostream&>(o) << getString<T&>(t); } return o; };
1028
1029 template<typename T>
1030 inline tstream& operator<< ( tstream& o, T* t )
1031 { if (o.enabled()) { static_cast<std::ostream&>(o) << getString<T*>(t); } return o; };
1032
1033 // template<typename T>
1034 // inline tstream& operator<< ( tstream& o, const T& t )
1035 // { if (o.enabled()) { static_cast<std::ostream&>(o) << getString<const T&>(t); } return o; };
1036
1037 template<typename T>
1038 inline tstream& operator<< ( tstream& o, T t )
1039 { if (o.enabled()) { static_cast<std::ostream&>(o) << getString<T>(t); } return o; };
1040
1041 template<typename T>
1042 inline tstream& operator<< ( tstream& o, const T* t )
1043 { if (o.enabled()) { static_cast<std::ostream&>(o) << getString<const T*>(t); } return o; };
1044
1045 template<>
1046 inline tstream& operator<< ( tstream& o, std::ios_base& (*pf)(std::ios_base&) )
1047 { if (o.enabled()) { static_cast<std::ostream&>(o) << pf; } return o; };
1048
1049 struct _Tsetw { int n_; };
1050 inline _Tsetw tsetw ( int n ) { return { n }; }
1051
1052 struct _Tsetf { int n_; };
1053 inline _Tsetf tsetf ( int n ) { return { n }; }
1054
1055 template<>
1056 inline tstream& operator<< ( tstream& o, _Tsetw manip )
1057 { if (o.enabled()) { static_cast<std::ostream&>(o) << std::setw(manip.n_); } return o; }
1058
1059 extern tstream cdebug;
1060
1061
1062 #define cdebug_log(level,indent) if (cdebug.enabled(level)) cdebug.log(level,indent)
1063 #define cdebug_tabw(level,indent) cdebug.tabw(level,indent)
1064
1065
1066 // x-----------------------------------------------------------------x
1067 // | Classes Neededs in All Hurricane Modules |
1068 // x-----------------------------------------------------------------x
1069
1070 #include "hurricane/Slot.h"
1071 #include "hurricane/Initializer.h"
1072 #include "hurricane/JsonWriter.h"
1073 #include "hurricane/JsonObject.h"
1074
1075
1076 #endif // HURRICANE_COMMONS_H
tstream::getLevel
int getLevel() const
Definition: Commons.h:997
std
Definition: JsonObject.h:213
Hurricane::demangle
string demangle(const char *symbol)
tstream::setMaxLevel
int setMaxLevel(int)
Definition: Commons.h:996
tstream::tabw
tstream & tabw(int level, int count)
Definition: Commons.h:1001
tstream::log
tstream & log(int level, int count=0)
Definition: Commons.h:1017
tstream::setMinLevel
int setMinLevel(int)
Definition: Commons.h:995
Hurricane::Tabulation
Tabulation description (API)
Definition: Tabulation.h:35
tstream::getMinLevel
int getMinLevel() const
Definition: Commons.h:993
tstream
Trace & indentation enabled stream.
Definition: Commons.h:956
tstream::setLevel
int setLevel(int)
Definition: Commons.h:998
Hurricane
The namespace dedicated to Hurricane.
Definition: Generalities.dox:5
tstream::enabled
bool enabled() const
Definition: Commons.h:999
tstream::getMaxLevel
int getMaxLevel() const
Definition: Commons.h:994

Generated by doxygen 1.8.14 on Sun Mar 8 2020 | Return to top of page

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