# 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 #pragma once
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 : "std::vector<Element>*".
469
470
471 template<typename Element>
472 inline std::string getString ( std::vector<Element>* v )
473 {
474 std::string name = "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 // -------------------------------------------------------------------
497 // Inspector Support for : "std::vector<Element*>*".
498
499
500 template<typename Element>
501 inline std::string getString ( std::vector<Element*>* v )
502 {
503 std::string name = "std::vector<Element*>*:";
504 return name + getString<size_t>(v->size());
505 }
506
507
508 template<typename Element>
509 inline Hurricane::Record* getRecord ( std::vector<Element*>* v )
510 {
511 Hurricane::Record* record = NULL;
512 if ( !v->empty() ) {
513 record = new Hurricane::Record ( "std::vector<Element*>*" );
514 unsigned n = 0;
515 typename std::vector<Element>::iterator iterator = v->begin();
516 while ( iterator != v->end() ) {
517 record->add ( getSlot<Element>(getString(n++), *iterator) );
518 ++iterator;
519 }
520 }
521 return record;
522 }
523
524
525 // -------------------------------------------------------------------
526 // Inspector Support for : "const std::vector<Element>*".
527
528
529 template<typename Element>
530 inline std::string getString ( const std::vector<Element>* v )
531 {
532 std::string name = "const std::vector<Element>*:";
533 return name + getString<size_t>(v->size());
534 }
535
536
537 template<typename Element>
538 inline Hurricane::Record* getRecord ( const std::vector<Element>* v )
539 {
540 Hurricane::Record* record = NULL;
541 if ( !v->empty() ) {
542 record = new Hurricane::Record ( "const std::vector<Element>*" );
543 unsigned n = 0;
544 typename std::vector<Element>::const_iterator iterator = v->begin();
545 while ( iterator != v->end() ) {
546 record->add ( getSlot<const Element>(getString(n++), &(*iterator)) );
547 ++iterator;
548 }
549 }
550 return record;
551 }
552
553
554 // -------------------------------------------------------------------
555 // Inspector Support for : "const std::vector<Element*>*".
556
557
558 template<typename Element>
559 inline std::string getString ( const std::vector<Element*>* v )
560 {
561 std::string name = "const std::vector<Element*>*:";
562 return name + getString<size_t>(v->size());
563 }
564
565
566 template<typename Element>
567 inline Hurricane::Record* getRecord ( const std::vector<Element*>* v )
568 {
569 Hurricane::Record* record = NULL;
570 if (not v->empty()) {
571 record = new Hurricane::Record ( "const std::vector<Element*>*" );
572 size_t n = 0;
573 typename std::vector<Element*>::const_iterator iterator = v->begin();
574 while (iterator != v->end()) {
575 record->add ( getSlot<const Element*>(getString(n++), *iterator) );
576 ++iterator;
577 }
578 }
579 return record;
580 }
581
582
583 // -------------------------------------------------------------------
584 // Inspector Support for : "const std::list<Element>*".
585
586
587 template<typename Element>
588 inline std::string getString ( const std::list<Element>* l )
589 {
590 std::string name = "const std::list<Element>:";
591 return name + getString<size_t>(l->size());
592 }
593
594
595 template<typename Element>
596 inline Hurricane::Record* getRecord ( const std::list<Element>* l )
597 {
598 Hurricane::Record* record = NULL;
599 if ( !l->empty() ) {
600 record = new Hurricane::Record ( "const std::list<Element>" );
601 unsigned n = 1;
602 typename std::list<Element>::const_iterator iterator = l->begin();
603 while ( iterator != l->end() ) {
604 record->add ( getSlot<const Element>(getString(n++), *iterator) );
605 ++iterator;
606 }
607 }
608 return record;
609 }
610
611
612 template<typename Element>
613 inline std::string getString ( std::list<Element>* l )
614 {
615 std::string name = "std::list<Element>:";
616 return name + getString<size_t>(l->size());
617 }
618
619
620 template<typename Element>
621 inline Hurricane::Record* getRecord ( std::list<Element>* l )
622 {
623 Hurricane::Record* record = NULL;
624 if ( !l->empty() ) {
625 record = new Hurricane::Record ( "std::list<Element>" );
626 unsigned n = 1;
627 typename std::list<Element>::iterator iterator = l->begin();
628 while ( iterator != l->end() ) {
629 record->add ( getSlot<Element>(getString(n++), *iterator) );
630 ++iterator;
631 }
632 }
633 return record;
634 }
635
636
637 // -------------------------------------------------------------------
638 // Inspector Support for : "[const] std::map<Key,Element,Compare>*.
639
640
641 template<typename Key, typename Element>
642 inline std::string getString ( std::map<Key,Element>* m )
643 {
644 std::string name = "std::map<Element>:";
645 return name + getString<size_t>(m->size());
646 }
647
648
649 template<typename Key, typename Element>
650 inline Hurricane::Record* getRecord ( std::map<Key,Element>* m )
651 {
652 Hurricane::Record* record = NULL;
653 if ( !m->empty() ) {
654 record = new Hurricane::Record ( "std::map<Element>" );
655 typename std::map<Key,Element>::iterator iterator = m->begin();
656 while ( iterator != m->end() ) {
657 record->add ( getSlot<Element>(getString(iterator->first), iterator->second) );
658 ++iterator;
659 }
660 }
661 return record;
662 }
663
664
665 template<typename Key, typename Element>
666 inline std::string getString ( const std::map<Key,Element>* m )
667 {
668 std::string name = "const std::map<Element>:";
669 return name + getString<size_t>(m->size());
670 }
671
672
673 template<typename Key, typename Element>
674 inline Hurricane::Record* getRecord ( const std::map<Key,Element>* m )
675 {
676 Hurricane::Record* record = NULL;
677 if ( !m->empty() ) {
678 record = new Hurricane::Record ( "const std::map<Element>" );
679 typename std::map<Key,Element>::const_iterator iterator = m->begin();
680 while ( iterator != m->end() ) {
681 record->add ( getSlot<const Element>(getString(iterator->first), iterator->second) );
682 ++iterator;
683 }
684 }
685 return record;
686 }
687
688
689 // -------------------------------------------------------------------
690 // Inspector Support for : "[const] std::map<Key,Element,Compare>*.
691
692
693 template<typename Key, typename Element, typename Compare>
694 inline std::string getString ( std::map<Key,Element,Compare>* m )
695 {
696 std::string name = "std::map<Element>:";
697 return name + getString<size_t>(m->size());
698 }
699
700
701 template<typename Key, typename Element, typename Compare>
702 inline Hurricane::Record* getRecord ( std::map<Key,Element,Compare>* m )
703 {
704 Hurricane::Record* record = NULL;
705 if ( !m->empty() ) {
706 record = new Hurricane::Record ( "std::map<Element>" );
707 typename std::map<Key,Element,Compare>::iterator iterator = m->begin();
708 while ( iterator != m->end() ) {
709 record->add ( getSlot<Element>(getString(iterator->first), iterator->second) );
710 ++iterator;
711 }
712 }
713 return record;
714 }
715
716
717 template<typename Key, typename Element, typename Compare>
718 inline std::string getString ( const std::map<Key,Element,Compare>* m )
719 {
720 std::string name = "const std::map<Element>:";
721 return name + getString<size_t>(m->size());
722 }
723
724
725 template<typename Key, typename Element, typename Compare>
726 inline Hurricane::Record* getRecord ( const std::map<Key,Element,Compare>* m )
727 {
728 Hurricane::Record* record = NULL;
729 if ( !m->empty() ) {
730 record = new Hurricane::Record ( "const std::map<Element>" );
731 typename std::map<Key,Element,Compare>::const_iterator iterator = m->begin();
732 while ( iterator != m->end() ) {
733 record->add ( getSlot<const Element>(getString(iterator->first), iterator->second) );
734 ++iterator;
735 }
736 }
737 return record;
738 }
739
740
741 // -------------------------------------------------------------------
742 // Inspector Support for : "const std::multimap<Key,Element,Compare>*".
743
744
745 template<typename Key, typename Element, typename Compare>
746 inline std::string getString ( const std::multimap<Key,Element,Compare>* m )
747 {
748 std::string name = "const std::multimap<Element>:";
749 return name + getString<size_t>(m->size());
750 }
751
752
753 template<typename Key, typename Element, typename Compare>
754 inline Hurricane::Record* getRecord ( const std::multimap<Key,Element,Compare>* m )
755 {
756 Hurricane::Record* record = NULL;
757 if ( !m->empty() ) {
758 record = new Hurricane::Record ( "const std::multimap<Element>" );
759 typename std::multimap<Key,Element,Compare>::const_iterator iterator = m->begin();
760 while ( iterator != m->end() ) {
761 record->add ( getSlot<const Element>(getString(iterator->first), iterator->second) );
762 ++iterator;
763 }
764 }
765 return record;
766 }
767
768
769 template<typename Key, typename Element, typename Compare>
770 inline std::string getString ( std::multimap<Key,Element,Compare>* m )
771 {
772 std::string name = "std::multimap<Element>:";
773 return name + getString<size_t>(m->size());
774 }
775
776
777 template<typename Key, typename Element, typename Compare>
778 inline Hurricane::Record* getRecord ( std::multimap<Key,Element,Compare>* m )
779 {
780 Hurricane::Record* record = NULL;
781 if ( !m->empty() ) {
782 record = new Hurricane::Record ( "std::multimap<Element>" );
783 typename std::multimap<Key,Element,Compare>::iterator iterator = m->begin();
784 while ( iterator != m->end() ) {
785 record->add ( getSlot<Element>(getString(iterator->first), iterator->second) );
786 ++iterator;
787 }
788 }
789 return record;
790 }
791
792
793 // -------------------------------------------------------------------
794 // Inspector Support for : "[const] std::set<Element,Compare>*".
795
796
797 template<typename Element, typename Compare>
798 inline std::string getString ( const std::set<Element,Compare>* s )
799 {
800 std::string name = "const std::set<Element>:";
801 return name + getString<size_t>(s->size());
802 }
803
804
805 template<typename Element, typename Compare>
806 inline Hurricane::Record* getRecord ( const std::set<Element,Compare>* s )
807 {
808 Hurricane::Record* record = NULL;
809 if ( !s->empty() ) {
810 record = new Hurricane::Record ( "const std::set<Element>" );
811 unsigned n = 1;
812 typename std::set<Element,Compare>::const_iterator iterator = s->begin();
813 while ( iterator != s->end() ) {
814 record->add ( getSlot<const Element>(getString(n++), *iterator) );
815 ++iterator;
816 }
817 }
818 return record;
819 }
820
821
822 template< typename Element, typename Compare, typename Allocator >
823 inline std::string getString ( std::set<Element,Compare,Allocator>* s )
824 {
825 std::string name = "std::set<Element>:";
826 return name + getString<size_t>(s->size());
827 }
828
829
830 template< typename Element, typename Compare, typename Allocator >
831 inline Hurricane::Record* getRecord ( std::set<Element,Compare,Allocator>* s )
832 {
833 Hurricane::Record* record = NULL;
834 if ( !s->empty() ) {
835 record = new Hurricane::Record ( "std::set<Element>" );
836 unsigned n = 1;
837 typename std::set<Element,Compare,Allocator>::iterator iterator = s->begin();
838 while ( iterator != s->end() ) {
839 record->add ( getSlot<Element>(getString(n++), *iterator) );
840 ++iterator;
841 }
842 }
843 return record;
844 }
845
846 // -------------------------------------------------------------------
847 // Inspector Support for : "[const] std::set<Element,Compare>&".
848
849
850 template<typename Element, typename Compare>
851 inline std::string getString ( const std::set<Element,Compare>& s )
852 {
853 std::string name = "const std::set<Element>:";
854 return name + getString<size_t>(s.size());
855 }
856
857
858 template<typename Element, typename Compare>
859 inline Hurricane::Record* getRecord ( const std::set<Element,Compare>& s )
860 {
861 Hurricane::Record* record = NULL;
862 if ( !s.empty() ) {
863 record = new Hurricane::Record ( "const std::set<Element>" );
864 unsigned n = 1;
865 typename std::set<Element,Compare>::const_iterator iterator = s.begin();
866 while ( iterator != s.end() ) {
867 record->add ( getSlot<Element>(getString(n++), *iterator) );
868 ++iterator;
869 }
870 }
871 return record;
872 }
873
874 // -------------------------------------------------------------------
875 // Inspector Support for : "const std::multiset<Element,Compare>*".
876
877
878 template<typename Element, typename Compare>
879 inline std::string getString ( const std::multiset<Element,Compare>* s )
880 {
881 std::string name = "std::multiset<Element>:";
882 return name + getString<size_t>(s->size());
883 }
884
885
886 template<typename Element, typename Compare>
887 inline Hurricane::Record* getRecord ( const std::multiset<Element,Compare>* s )
888 {
889 Hurricane::Record* record = NULL;
890 if ( !s->empty() ) {
891 record = new Hurricane::Record ( "std::multiset<Element>" );
892 unsigned n = 1;
893 typename std::multiset<Element,Compare>::const_iterator iterator = s->begin();
894 while ( iterator != s->end() ) {
895 record->add ( getSlot<Element>(getString(n++), *iterator) );
896 ++iterator;
897 }
898 }
899 return record;
900 }
901
902
903 # define GETSTRING_POINTER_SUPPORT(Data) \
904 template<> inline std::string getString<Data*>( Data* data ) \
905 { \
906 if (!data) return "NULL [" #Data "]"; \
907 return data->_getString(); \
908 } \
909 \
910 template<> inline std::string getString<const Data*>( const Data* data ) \
911 { if (!data) return "NULL [const " #Data "]"; return data->_getString(); }
912
913
914 # define IOSTREAM_POINTER_SUPPORT(Data) \
915 inline std::ostream& operator<< ( std::ostream& o, Data* d ) \
916 { \
917 if (!d) return o << "NULL [" #Data "]"; \
918 return o << "&" << getString<const Data*>(d); \
919 } \
920 inline std::ostream& operator<< ( std::ostream& o, const Data* d ) \
921 { \
922 if (!d) return o << "NULL [const " #Data "]"; \
923 return o << "&" << getString<const Data*>(d); \
924 } \
925
926
927 # define GETRECORD_POINTER_SUPPORT(Data) \
928 template<> inline Hurricane::Record* getRecord<Data*>( Data* data ) \
929 { if (!data) return NULL; return data->_getRecord(); } \
930 \
931 template<> inline Hurricane::Record* getRecord<const Data*>( const Data* data ) \
932 { if (!data) return NULL; return data->_getRecord(); }
933
934
935 # define GETSTRING_REFERENCE_SUPPORT(Data) \
936 template<> inline std::string getString<Data&>( Data& data ) \
937 { return data._getString(); } \
938 \
939 template<> inline std::string getString<const Data&>( const Data& data ) \
940 { return data._getString(); }
941
942
943 # define IOSTREAM_REFERENCE_SUPPORT(Data) \
944 inline std::ostream& operator<< ( std::ostream& o, Data& d ) \
945 { return o << getString<Data&>(d); } \
946 \
947 inline std::ostream& operator<< ( std::ostream& o, const Data& d ) \
948 { return o << getString<const Data&>(d); } \
949 \
950
951 # define GETRECORD_REFERENCE_SUPPORT(Data) \
952 template<> inline Hurricane::Record* getRecord<Data&>( Data& data ) \
953 { return data._getRecord(); } \
954 \
955 template<> inline Hurricane::Record* getRecord<const Data&>( const Data& data ) \
956 { return data._getRecord(); }
957
958
959 # define GETSTRING_VALUE_SUPPORT(Data) \
960 template<> inline std::string getString<Data>( Data data ) \
961 { return data._getString(); }
962
963
964 # define IOSTREAM_VALUE_SUPPORT(Data) \
965 inline std::ostream& operator<< ( std::ostream& o, Data d ) \
966 { return o << getString<Data>(d); }
967
968
969 # define GETRECORD_VALUE_SUPPORT(Data) \
970 template<> inline Hurricane::Record* getRecord<Data>( Data data ) \
971 { return data._getRecord(); }
972
973
974 # define INSPECTOR_P_SUPPORT(Data) \
975 GETRECORD_POINTER_SUPPORT(Data) \
976 GETSTRING_POINTER_SUPPORT(Data) \
977 IOSTREAM_POINTER_SUPPORT(Data)
978
979
980 # define INSPECTOR_R_SUPPORT(Data) \
981 GETRECORD_REFERENCE_SUPPORT(Data) \
982 GETSTRING_REFERENCE_SUPPORT(Data) \
983 IOSTREAM_REFERENCE_SUPPORT(Data)
984
985
986 # define INSPECTOR_PR_SUPPORT(Data) \
987 GETSTRING_POINTER_SUPPORT(Data) \
988 GETSTRING_REFERENCE_SUPPORT(Data) \
989 GETSTRING_VALUE_SUPPORT(Data) \
990 IOSTREAM_POINTER_SUPPORT(Data) \
991 IOSTREAM_REFERENCE_SUPPORT(Data) \
992 GETRECORD_POINTER_SUPPORT(Data) \
993 GETRECORD_REFERENCE_SUPPORT(Data)
994
995
996 #include "hurricane/Tabulation.h"
997
998
999 // -------------------------------------------------------------------
1000 // Class : "::cdebug()".
1001 //
1002 // Wrapper around the STL ostream which to print debugging messages.
1003
1004 class tstream : public std::ostream {
1005 public:
1006 inline int getMinLevel () const;
1007 inline int getMaxLevel () const;
1008 inline int setMinLevel ( int );
1009 inline int setMaxLevel ( int );
1010 inline int getLevel () const;
1011 inline int setLevel ( int );
1012 inline bool enabled () const;
1013 inline bool enabled ( int ) const;
1014 inline tstream& log ( int level, int count=0 );
1015 inline tstream& tabw ( int level, int count );
1016 inline tstream ( std::ostream & );
1017 inline tstream& put ( char c );
1018 inline tstream& flush ();
1019 private:
1020 inline tstream& _tab ();
1021 inline tstream& _tabw ( int count );
1022 public:
1023 // Overload for manipulators.
1024 inline tstream& operator<< ( std::ostream& (*pf)(std::ostream &) );
1025 private:
1026 int _minLevel;
1027 int _maxLevel;
1028 int _level;
1029 Hurricane::Tabulation _tabulation;
1030 };
1031
1032
1033 inline tstream::tstream ( std::ostream& s )
1034 : std::ostream(s.rdbuf())
1035 , _minLevel (100000)
1036 , _maxLevel (0)
1037 , _level (0)
1038 , _tabulation(" ")
1039 { }
1040
1041 inline int tstream::getMinLevel () const { return _minLevel; }
1042 inline int tstream::getMaxLevel () const { return _maxLevel; }
1043 inline int tstream::setMinLevel ( int l ) { int pl=_minLevel; _minLevel=l; return pl; }
1044 inline int tstream::setMaxLevel ( int l ) { int pl=_maxLevel; _maxLevel=l; return pl; }
1045 inline int tstream::getLevel () const { return _level; }
1046 inline int tstream::setLevel ( int l ) { int pl=_level; _level=l; return pl; }
1047 inline bool tstream::enabled () const { return (_level >= _minLevel) and (_level < _maxLevel); }
1048 inline bool tstream::enabled ( int l ) const { return (l >= _minLevel) and (l < _maxLevel); }
1049 inline tstream& tstream::tabw ( int level, int count ) { setLevel(level); return _tabw(count); }
1050 inline tstream& tstream::put ( char c ) { if (enabled()) static_cast<std::ostream*>(this)->put(c); return *this; }
1051 inline tstream& tstream::flush () { if (enabled()) static_cast<std::ostream*>(this)->flush(); return *this; }
1052 inline tstream& tstream::operator<< ( std::ostream& (*pf)(std::ostream&) ) { if (enabled()) (*pf)(*this); return *this; }
1053
1054
1055 inline tstream& tstream::_tab () { if (enabled()) (*this) << _tabulation; return *this; }
1056 inline tstream& tstream::_tabw ( int count )
1057 {
1058 if (enabled()) {
1059 if (count > 0) while(count--) _tabulation++;
1060 else if (count < 0) while(count++) _tabulation--;
1061 }
1062 return *this;
1063 }
1064
1065 inline tstream& tstream::log ( int level, int count )
1066 { setLevel(level); _tab(); return _tabw(count); }
1067
1068 // For STL Types.
1069 inline tstream& operator<< ( tstream& o, const std::string s )
1070 { if (o.enabled()) { static_cast<std::ostream&>(o) << s; } return o; };
1071
1072 // For POD Types.
1073 // template<typename T>
1074 // inline tstream& operator<< ( tstream& o, T& t )
1075 // { if (o.enabled()) { static_cast<std::ostream&>(o) << getString<T&>(t); } return o; };
1076
1077 template<typename T>
1078 inline tstream& operator<< ( tstream& o, T* t )
1079 { if (o.enabled()) { static_cast<std::ostream&>(o) << getString<T*>(t); } return o; };
1080
1081 // template<typename T>
1082 // inline tstream& operator<< ( tstream& o, const T& t )
1083 // { if (o.enabled()) { static_cast<std::ostream&>(o) << getString<const T&>(t); } return o; };
1084
1085 template<typename T>
1086 inline tstream& operator<< ( tstream& o, T t )
1087 { if (o.enabled()) { static_cast<std::ostream&>(o) << getString<T>(t); } return o; };
1088
1089 template<typename T>
1090 inline tstream& operator<< ( tstream& o, const T* t )
1091 { if (o.enabled()) { static_cast<std::ostream&>(o) << getString<const T*>(t); } return o; };
1092
1093 template<>
1094 inline tstream& operator<< ( tstream& o, std::ios_base& (*pf)(std::ios_base&) )
1095 { if (o.enabled()) { static_cast<std::ostream&>(o) << pf; } return o; };
1096
1097 struct _Tsetw { int n_; };
1098 inline _Tsetw tsetw ( int n ) { return { n }; }
1099
1100 struct _Tsetf { int n_; };
1101 inline _Tsetf tsetf ( int n ) { return { n }; }
1102
1103 template<>
1104 inline tstream& operator<< ( tstream& o, _Tsetw manip )
1105 { if (o.enabled()) { static_cast<std::ostream&>(o) << std::setw(manip.n_); } return o; }
1106
1107 extern tstream cdebug;
1108
1109
1110 #define cdebug_log(level,indent) if (cdebug.enabled(level)) cdebug.log(level,indent)
1111 #define cdebug_tabw(level,indent) cdebug.tabw(level,indent)
1112
1113
1114 // x-----------------------------------------------------------------x
1115 // | Classes Neededs in All Hurricane Modules |
1116 // x-----------------------------------------------------------------x
1117
1118 #include "hurricane/Slot.h"
1119 #include "hurricane/Initializer.h"
1120 #include "hurricane/JsonWriter.h"
1121 #include "hurricane/JsonObject.h"
tstream::getLevel
int getLevel() const
Definition: Commons.h:1045
std
Definition: JsonObject.h:213
Hurricane::demangle
string demangle(const char *symbol)
tstream::setMaxLevel
int setMaxLevel(int)
Definition: Commons.h:1044
tstream::tabw
tstream & tabw(int level, int count)
Definition: Commons.h:1049
tstream::log
tstream & log(int level, int count=0)
Definition: Commons.h:1065
tstream::setMinLevel
int setMinLevel(int)
Definition: Commons.h:1043
Hurricane::Tabulation
Tabulation description (API)
Definition: Tabulation.h:35
tstream::getMinLevel
int getMinLevel() const
Definition: Commons.h:1041
tstream
Trace & indentation enabled stream.
Definition: Commons.h:1004
tstream::setLevel
int setLevel(int)
Definition: Commons.h:1046
Hurricane
The namespace dedicated to Hurricane.
Definition: Generalities.dox:5
tstream::enabled
bool enabled() const
Definition: Commons.h:1047
tstream::getMaxLevel
int getMaxLevel() const
Definition: Commons.h:1042

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