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
57namespace 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 string& split ( std::string& );
150
151
152} // End of Hurricane namespace.
153
154
155#include "hurricane/Record.h"
156
157
158// +-----------------------------------------------------------------+
159// | Functions for Inspector Support |
160// +-----------------------------------------------------------------+
161
162// Note 1: Theses are specialized templates for "getString<>()" & "getRecord<>()".
163// Note 2: we are outside the Hurricane namespace.
164// Note 3: thoses templates manage all POD & STL types.
165
166
167template<typename Data> inline Hurricane::Slot* getSlot ( std::string name, Data );
168
169
170// -------------------------------------------------------------------
171// Inspector Support for : "POD types".
172
173// Default match.
174
175template<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
180template<> inline std::string getString<std::nullptr_t> ( std::nullptr_t )
181{ return "nullptr" ; }
182
183// "const &" flavors.
184
185template<> inline std::string getString<const bool&> ( const bool& b )
186{ return (b)?"True":"False" ; }
187
188template<> inline std::string getString<const int&> ( const int& i )
189{ std::ostringstream os (""); os << i; return os.str(); }
190
191template<> inline std::string getString<const long&> ( const long& l )
192{ std::ostringstream os (""); os << l; return os.str(); }
193
194template<> inline std::string getString<const unsigned int&> ( const unsigned int& u )
195{ std::ostringstream os (""); os << u; return os.str(); }
196
197template<> inline std::string getString<const unsigned long&> ( const unsigned long& ul )
198{ std::ostringstream os (""); os << ul; return os.str(); }
199
200template<> inline std::string getString<const unsigned long long&> ( const unsigned long long& ull )
201{ std::ostringstream os (""); os << ull; return os.str(); }
202
203template<> inline std::string getString<const unsigned short int&> ( const unsigned short int& us )
204{ std::ostringstream os (""); os << us; return os.str(); }
205
206template<> inline std::string getString<const float&> ( const float& f )
207{ std::ostringstream os (""); os << f; return os.str(); }
208
209template<> inline std::string getString<const double&> ( const double& d )
210{ std::ostringstream os; os << d; return os.str(); }
211
212template<> inline std::string getString<const std::string&> ( const std::string& s )
213{ return s; }
214
215// "const *" flavors.
216
217template<> inline std::string getString<const bool*> ( const bool* b )
218{ return (*b)?"True":"False" ; }
219
220template<> inline std::string getString<const char*> ( const char* c )
221{ return c; }
222
223template<> inline std::string getString<const int*> ( const int* i )
224{ std::ostringstream os (""); os << *i; return os.str(); }
225
226template<> inline std::string getString<const long*> ( const long* l )
227{ std::ostringstream os (""); os << *l; return os.str(); }
228
229template<> inline std::string getString<const unsigned int*> ( const unsigned int* u )
230{ std::ostringstream os (""); os << *u; return os.str(); }
231
232template<> inline std::string getString<const unsigned long*> ( const unsigned long* ul )
233{ std::ostringstream os (""); os << *ul; return os.str(); }
234
235template<> inline std::string getString<const unsigned long long*> ( const unsigned long long* ull )
236{ std::ostringstream os (""); os << *ull; return os.str(); }
237
238template<> inline std::string getString<const unsigned short int*> ( const unsigned short int* us )
239{ std::ostringstream os (""); os << *us; return os.str(); }
240
241template<> inline std::string getString<const float*> ( const float* f )
242{ std::ostringstream os (""); os << *f; return os.str(); }
243
244template<> inline std::string getString<const double*> ( const double* d )
245{ std::ostringstream os; os << *d; return os.str(); }
246
247template<> inline std::string getString<const void*> ( const void* p )
248{ std::ostringstream os ("0x"); os << std::hex << p; return os.str(); }
249
250template<> inline std::string getString<const std::string*> ( const std::string* s )
251{ return *s; }
252
253
254// "*" flavors.
255
256template<> inline std::string getString<bool*> ( bool* b )
257{ return (*b)?"True":"False" ; }
258
259template<> inline std::string getString<char*> ( char* c )
260{ return c; }
261
262template<> inline std::string getString<int*> ( int* i )
263{ std::ostringstream os (""); os << *i; return os.str(); }
264
265template<> inline std::string getString<long*> ( long* l )
266{ std::ostringstream os (""); os << *l; return os.str(); }
267
268template<> inline std::string getString<unsigned int*> ( unsigned int* u )
269{ std::ostringstream os (""); os << *u; return os.str(); }
270
271template<> inline std::string getString<unsigned long*> ( unsigned long* ul )
272{ std::ostringstream os (""); os << *ul; return os.str(); }
273
274template<> inline std::string getString<unsigned long long*> ( unsigned long long* ull )
275{ std::ostringstream os (""); os << *ull; return os.str(); }
276
277template<> inline std::string getString<unsigned short int*> ( unsigned short int* us )
278{ std::ostringstream os (""); os << *us; return os.str(); }
279
280template<> inline std::string getString<float*> ( float* f )
281{ std::ostringstream os (""); os << *f; return os.str(); }
282
283template<> inline std::string getString<double*> ( double* d )
284{ std::ostringstream os; os << *d; return os.str(); }
285
286template<> inline std::string getString<void*> ( void* p )
287{ std::ostringstream os ("0x"); os << std::hex << p; return os.str(); }
288
289template<> inline std::string getString<std::string*> ( std::string* s )
290{ return *s; }
291
292
293// "by value" flavors.
294
295template<> inline std::string getString<bool> ( bool b )
296{ return (b)?"True":"False" ; }
297
298template<> inline std::string getString<char> ( char c )
299{ return std::string(1,c); }
300
301template<> inline std::string getString<int> ( int i )
302{ std::ostringstream os (""); os << i; return os.str(); }
303
304template<> inline std::string getString<long> ( long l )
305{ std::ostringstream os (""); os << l; return os.str(); }
306
307template<> inline std::string getString<unsigned int> ( unsigned int u )
308{ std::ostringstream os (""); os << u; return os.str(); }
309
310template<> inline std::string getString<unsigned long> ( unsigned long ul )
311{ std::ostringstream os (""); os << ul; return os.str(); }
312
313template<> inline std::string getString<unsigned long long> ( unsigned long long ull )
314{ std::ostringstream os (""); os << ull; return os.str(); }
315
316template<> inline std::string getString<unsigned short int> ( unsigned short int us )
317{ std::ostringstream os (""); os << us; return os.str(); }
318
319template<> inline std::string getString<float> ( float f )
320{ std::ostringstream os (""); os << f; return os.str(); }
321
322template<> inline std::string getString<double> ( double d )
323{ std::ostringstream os; os << d; return os.str(); }
324
325template<> inline std::string getString<std::string> ( std::string s )
326{ return s; }
327
328
329template<typename Data> inline Hurricane::Record* getRecord ( Data data )
330{
331//std::cerr << "::getRecord(Data) Data=" << Hurricane::demangle(typeid(data).name()) << std::endl;
332 return NULL;
333}
334
335
336// -------------------------------------------------------------------
337// Inspector Support for : "[const] std::pair<T,U>&".
338
339template<typename T, typename U>
340inline std::string getString ( const std::pair<T,U>& p )
341{
342 return "const std::pair<T,U>";
343}
344
345
346template<typename T, typename U>
347inline Hurricane::Record* getRecord ( const std::pair<T,U>& p )
348{
349 Hurricane::Record* record = NULL;
350 record = new Hurricane::Record ( "const std::pair<T,U>" );
351 record->add( getSlot<const T>(std::string("first" ), &p.first ) );
352 record->add( getSlot<const U>(std::string("second"), &p.second) );
353 return record;
354}
355
356
357template<typename T, typename U>
358inline std::string getString ( std::pair<T,U>& p )
359{
360 return "std::pair<T,U>";
361}
362
363
364template<typename T, typename U>
365inline Hurricane::Record* getRecord ( std::pair<T,U>& p )
366{
367 Hurricane::Record* record = NULL;
368 record = new Hurricane::Record ( "std::pair<T,U>" );
369 record->add( getSlot<T>(std::string("first" ), &p.first ) );
370 record->add( getSlot<U>(std::string("second"), &p.second) );
371 return record;
372}
373
374
375// -------------------------------------------------------------------
376// Inspector Support for : "[const] std::array<Element>*".
377
378
379template<typename Element,size_t N>
380inline std::string getString ( std::array<Element,N>* v )
381{
382 std::string name = "const std::array<Element,N>:";
383 return name + getString<size_t>(v->size());
384}
385
386
387template<typename Element,size_t N>
388inline Hurricane::Record* getRecord ( std::array<Element,N>* v )
389{
390 Hurricane::Record* record = NULL;
391 if ( !v->empty() ) {
392 record = new Hurricane::Record ( "std::array<Element,N>" );
393 unsigned n = 0;
394 typename std::array<Element,N>::iterator iterator = v->begin();
395 while ( iterator != v->end() ) {
396 record->add ( getSlot<Element>(getString(n++), *iterator) );
397 ++iterator;
398 }
399 }
400 return record;
401}
402
403
404template<typename Element,size_t N>
405inline std::string getString ( const std::array<Element,N>* v )
406{
407 std::string name = "const std::array<Element,N>:";
408 return name + getString<size_t>(v->size());
409}
410
411
412template<typename Element,size_t N>
413inline Hurricane::Record* getRecord ( const std::array<Element,N>* v )
414{
415 Hurricane::Record* record = NULL;
416 if ( !v->empty() ) {
417 record = new Hurricane::Record ( "const std::array<Element,N>" );
418 unsigned n = 0;
419 typename std::array<Element,N>::const_iterator iterator = v->begin();
420 while ( iterator != v->end() ) {
421 record->add ( getSlot<const Element>(getString(n++), *iterator) );
422 ++iterator;
423 }
424 }
425 return record;
426}
427
428
429template<typename Element,size_t N>
430inline std::string getString ( std::array<Element,N>& v )
431{
432 std::string name = "std::array<Element,N>&:";
433 return name + getString<size_t>(v.size());
434}
435
436
437template<typename Element,size_t N>
438inline Hurricane::Record* getRecord ( std::array<Element,N>& v )
439{
440 Hurricane::Record* record = NULL;
441 if (not v.empty()) {
442 record = new Hurricane::Record ( "std::array<Element,N>&" );
443 unsigned n = 0;
444 for ( auto element : v )
445 record->add( getSlot<Element>(getString(n++), element) );
446 }
447 return record;
448}
449
450
451template<typename Element,size_t N>
452inline std::string getString ( const std::array<Element,N>& v )
453{
454 std::string name = "const std::array<Element,N>&:";
455 return name + getString<size_t>(v.size());
456}
457
458
459template<typename Element,size_t N>
460inline Hurricane::Record* getRecord ( const std::array<Element,N>& v )
461{
462 Hurricane::Record* record = NULL;
463 if (not v.empty()) {
464 record = new Hurricane::Record ( "const std::array<Element,N>&" );
465 unsigned n = 0;
466 for ( auto element : v )
467 record->add( getSlot<Element>(getString(n++), element) );
468 }
469 return record;
470}
471
472
473// -------------------------------------------------------------------
474// Inspector Support for : "std::vector<Element>*".
475
476
477template<typename Element>
478inline std::string getString ( std::vector<Element>* v )
479{
480 std::string name = "std::vector<Element>*:";
481 return name + getString<size_t>(v->size());
482}
483
484
485template<typename Element>
486inline Hurricane::Record* getRecord ( std::vector<Element>* v )
487{
488 Hurricane::Record* record = NULL;
489 if ( !v->empty() ) {
490 record = new Hurricane::Record ( "std::vector<Element>*" );
491 unsigned n = 0;
492 typename std::vector<Element>::iterator iterator = v->begin();
493 while ( iterator != v->end() ) {
494 record->add ( getSlot<const Element*>(getString(n++), &(*iterator)) );
495 ++iterator;
496 }
497 }
498 return record;
499}
500
501
502// -------------------------------------------------------------------
503// Inspector Support for : "std::vector<Element*>*".
504
505
506template<typename Element>
507inline std::string getString ( std::vector<Element*>* v )
508{
509 std::string name = "std::vector<Element*>*:";
510 return name + getString<size_t>(v->size());
511}
512
513
514template<typename Element>
515inline Hurricane::Record* getRecord ( std::vector<Element*>* v )
516{
517 Hurricane::Record* record = NULL;
518 if ( !v->empty() ) {
519 record = new Hurricane::Record ( "std::vector<Element*>*" );
520 unsigned n = 0;
521 typename std::vector<Element*>::iterator iterator = v->begin();
522 while ( iterator != v->end() ) {
523 record->add ( getSlot<Element*>(getString(n++), *iterator) );
524 ++iterator;
525 }
526 }
527 return record;
528}
529
530
531// -------------------------------------------------------------------
532// Inspector Support for : "const std::vector<Element>*".
533
534
535template<typename Element>
536inline std::string getString ( const std::vector<Element>* v )
537{
538 std::string name = "const std::vector<Element>*:";
539 return name + getString<size_t>(v->size());
540}
541
542
543template<typename Element>
544inline Hurricane::Record* getRecord ( const std::vector<Element>* v )
545{
546 Hurricane::Record* record = NULL;
547 if ( !v->empty() ) {
548 record = new Hurricane::Record ( "const std::vector<Element>*" );
549 unsigned n = 0;
550 typename std::vector<Element>::const_iterator iterator = v->begin();
551 while ( iterator != v->end() ) {
552 record->add ( getSlot<const Element*>(getString(n++), &(*iterator)) );
553 ++iterator;
554 }
555 }
556 return record;
557}
558
559
560// -------------------------------------------------------------------
561// Inspector Support for : "const std::vector<Element*>*".
562
563
564template<typename Element>
565inline std::string getString ( const std::vector<Element*>* v )
566{
567 std::string name = "const std::vector<Element*>*:";
568 return name + getString<size_t>(v->size());
569}
570
571
572template<typename Element>
573inline Hurricane::Record* getRecord ( const std::vector<Element*>* v )
574{
575 Hurricane::Record* record = NULL;
576 if (not v->empty()) {
577 record = new Hurricane::Record ( "const std::vector<Element*>*" );
578 size_t n = 0;
579 typename std::vector<Element*>::const_iterator iterator = v->begin();
580 while (iterator != v->end()) {
581 record->add ( getSlot<const Element*>(getString(n++), *iterator) );
582 ++iterator;
583 }
584 }
585 return record;
586}
587
588
589// -------------------------------------------------------------------
590// Inspector Support for : "const std::list<Element>*".
591
592
593template<typename Element>
594inline std::string getString ( const std::list<Element>* l )
595{
596 std::string name = "const std::list<Element>*:";
597 return name + getString<size_t>(l->size());
598}
599
600
601template<typename Element>
602inline Hurricane::Record* getRecord ( const std::list<Element>* l )
603{
604 Hurricane::Record* record = NULL;
605 if ( !l->empty() ) {
606 record = new Hurricane::Record ( "const std::list<Element>" );
607 unsigned n = 1;
608 typename std::list<Element>::const_iterator iterator = l->begin();
609 while ( iterator != l->end() ) {
610 record->add ( getSlot<const Element*>(getString(n++), &(*iterator)) );
611 ++iterator;
612 }
613 }
614 return record;
615}
616
617
618template<typename Element>
619inline std::string getString ( std::list<Element>* l )
620{
621 std::string name = "std::list<Element>*:";
622 return name + getString<size_t>(l->size());
623}
624
625
626template<typename Element>
627inline Hurricane::Record* getRecord ( std::list<Element>* l )
628{
629 Hurricane::Record* record = NULL;
630 if ( !l->empty() ) {
631 record = new Hurricane::Record ( "std::list<Element>" );
632 unsigned n = 1;
633 typename std::list<Element>::iterator iterator = l->begin();
634 while ( iterator != l->end() ) {
635 record->add ( getSlot<const Element*>(getString(n++), &(*iterator)) );
636 ++iterator;
637 }
638 }
639 return record;
640}
641
642
643// -------------------------------------------------------------------
644// Inspector Support for : "[const] std::map<Key,Element,Compare>*.
645
646
647template<typename Key, typename Element>
648inline std::string getString ( std::map<Key,Element>* m )
649{
650 std::string name = "std::map<Element>:";
651 return name + getString<size_t>(m->size());
652}
653
654
655template<typename Key, typename Element>
656inline Hurricane::Record* getRecord ( std::map<Key,Element>* m )
657{
658 Hurricane::Record* record = NULL;
659 if ( !m->empty() ) {
660 record = new Hurricane::Record ( "std::map<Element>" );
661 typename std::map<Key,Element>::iterator iterator = m->begin();
662 while ( iterator != m->end() ) {
663 record->add ( getSlot<Element>(getString(iterator->first), iterator->second) );
664 ++iterator;
665 }
666 }
667 return record;
668}
669
670
671template<typename Key, typename Element>
672inline std::string getString ( const std::map<Key,Element>* m )
673{
674 std::string name = "const std::map<Element>:";
675 return name + getString<size_t>(m->size());
676}
677
678
679template<typename Key, typename Element>
680inline Hurricane::Record* getRecord ( const std::map<Key,Element>* m )
681{
682 Hurricane::Record* record = NULL;
683 if ( !m->empty() ) {
684 record = new Hurricane::Record ( "const std::map<Element>" );
685 typename std::map<Key,Element>::const_iterator iterator = m->begin();
686 while ( iterator != m->end() ) {
687 record->add ( getSlot<const Element>(getString(iterator->first), iterator->second) );
688 ++iterator;
689 }
690 }
691 return record;
692}
693
694
695// -------------------------------------------------------------------
696// Inspector Support for : "[const] std::map<Key,Element,Compare>*.
697
698
699template<typename Key, typename Element, typename Compare>
700inline std::string getString ( std::map<Key,Element,Compare>* m )
701{
702 std::string name = "std::map<Element>:";
703 return name + getString<size_t>(m->size());
704}
705
706
707template<typename Key, typename Element, typename Compare>
708inline Hurricane::Record* getRecord ( std::map<Key,Element,Compare>* m )
709{
710 Hurricane::Record* record = NULL;
711 if ( !m->empty() ) {
712 record = new Hurricane::Record ( "std::map<Element>" );
713 typename std::map<Key,Element,Compare>::iterator iterator = m->begin();
714 while ( iterator != m->end() ) {
715 record->add ( getSlot<Element>(getString(iterator->first), iterator->second) );
716 ++iterator;
717 }
718 }
719 return record;
720}
721
722
723template<typename Key, typename Element, typename Compare>
724inline std::string getString ( const std::map<Key,Element,Compare>* m )
725{
726 std::string name = "const std::map<Element>:";
727 return name + getString<size_t>(m->size());
728}
729
730
731template<typename Key, typename Element, typename Compare>
732inline Hurricane::Record* getRecord ( const std::map<Key,Element,Compare>* m )
733{
734 Hurricane::Record* record = NULL;
735 if ( !m->empty() ) {
736 record = new Hurricane::Record ( "const std::map<Element>" );
737 typename std::map<Key,Element,Compare>::const_iterator iterator = m->begin();
738 while ( iterator != m->end() ) {
739 record->add ( getSlot<const Element>(getString(iterator->first), iterator->second) );
740 ++iterator;
741 }
742 }
743 return record;
744}
745
746
747// -------------------------------------------------------------------
748// Inspector Support for : "const std::multimap<Key,Element,Compare>*".
749
750
751template<typename Key, typename Element, typename Compare>
752inline std::string getString ( const std::multimap<Key,Element,Compare>* m )
753{
754 std::string name = "const std::multimap<Element>:";
755 return name + getString<size_t>(m->size());
756}
757
758
759template<typename Key, typename Element, typename Compare>
760inline Hurricane::Record* getRecord ( const std::multimap<Key,Element,Compare>* m )
761{
762 Hurricane::Record* record = NULL;
763 if ( !m->empty() ) {
764 record = new Hurricane::Record ( "const std::multimap<Element>" );
765 typename std::multimap<Key,Element,Compare>::const_iterator iterator = m->begin();
766 while ( iterator != m->end() ) {
767 record->add ( getSlot<const Element>(getString(iterator->first), iterator->second) );
768 ++iterator;
769 }
770 }
771 return record;
772}
773
774
775template<typename Key, typename Element, typename Compare>
776inline std::string getString ( std::multimap<Key,Element,Compare>* m )
777{
778 std::string name = "std::multimap<Element>:";
779 return name + getString<size_t>(m->size());
780}
781
782
783template<typename Key, typename Element, typename Compare>
784inline Hurricane::Record* getRecord ( std::multimap<Key,Element,Compare>* m )
785{
786 Hurricane::Record* record = NULL;
787 if ( !m->empty() ) {
788 record = new Hurricane::Record ( "std::multimap<Element>" );
789 typename std::multimap<Key,Element,Compare>::iterator iterator = m->begin();
790 while ( iterator != m->end() ) {
791 record->add ( getSlot<Element>(getString(iterator->first), iterator->second) );
792 ++iterator;
793 }
794 }
795 return record;
796}
797
798
799// -------------------------------------------------------------------
800// Inspector Support for : "[const] std::set<Element,Compare>*".
801
802
803template<typename Element, typename Compare>
804inline std::string getString ( const std::set<Element,Compare>* s )
805{
806 std::string name = "const std::set<Element>:";
807 return name + getString<size_t>(s->size());
808}
809
810
811template<typename Element, typename Compare>
812inline Hurricane::Record* getRecord ( const std::set<Element,Compare>* s )
813{
814 Hurricane::Record* record = NULL;
815 if ( !s->empty() ) {
816 record = new Hurricane::Record ( "const std::set<Element>" );
817 unsigned n = 1;
818 typename std::set<Element,Compare>::const_iterator iterator = s->begin();
819 while ( iterator != s->end() ) {
820 record->add ( getSlot<const Element>(getString(n++), *iterator) );
821 ++iterator;
822 }
823 }
824 return record;
825}
826
827
828template< typename Element, typename Compare, typename Allocator >
829inline std::string getString ( std::set<Element,Compare,Allocator>* s )
830{
831 std::string name = "std::set<Element>:";
832 return name + getString<size_t>(s->size());
833}
834
835
836template< typename Element, typename Compare, typename Allocator >
837inline Hurricane::Record* getRecord ( std::set<Element,Compare,Allocator>* s )
838{
839 Hurricane::Record* record = NULL;
840 if (not s->empty()) {
841 record = new Hurricane::Record ( "std::set<Element>" );
842 unsigned n = 1;
843 typename std::set<Element,Compare,Allocator>::iterator iterator = s->begin();
844 while ( iterator != s->end() ) {
845 record->add( getSlot<Element>(getString(n++), *iterator) );
846 ++iterator;
847 }
848 }
849 return record;
850}
851
852// -------------------------------------------------------------------
853// Inspector Support for : "[const] std::set<Element,Compare>&".
854
855
856template<typename Element, typename Compare>
857inline std::string getString ( const std::set<Element,Compare>& s )
858{
859 std::string name = "const std::set<Element>:";
860 return name + getString<size_t>(s.size());
861}
862
863
864template<typename Element, typename Compare>
865inline Hurricane::Record* getRecord ( const std::set<Element,Compare>& s )
866{
867 Hurricane::Record* record = NULL;
868 if ( !s.empty() ) {
869 record = new Hurricane::Record ( "const std::set<Element>" );
870 unsigned n = 1;
871 typename std::set<Element,Compare>::const_iterator iterator = s.begin();
872 while ( iterator != s.end() ) {
873 record->add ( getSlot<Element>(getString(n++), *iterator) );
874 ++iterator;
875 }
876 }
877 return record;
878}
879
880// -------------------------------------------------------------------
881// Inspector Support for : "const std::multiset<Element,Compare>*".
882
883
884template<typename Element, typename Compare>
885inline std::string getString ( const std::multiset<Element,Compare>* s )
886{
887 std::string name = "std::multiset<Element>:";
888 return name + getString<size_t>(s->size());
889}
890
891
892template<typename Element, typename Compare>
893inline Hurricane::Record* getRecord ( const std::multiset<Element,Compare>* s )
894{
895 Hurricane::Record* record = NULL;
896 if ( !s->empty() ) {
897 record = new Hurricane::Record ( "std::multiset<Element>" );
898 unsigned n = 1;
899 typename std::multiset<Element,Compare>::const_iterator iterator = s->begin();
900 while ( iterator != s->end() ) {
901 record->add ( getSlot<Element>(getString(n++), *iterator) );
902 ++iterator;
903 }
904 }
905 return record;
906}
907
908
909#include "hurricane/Tabulation.h"
910
911
912// -------------------------------------------------------------------
913// Class : "::cdebug()".
914//
915// Wrapper around the STL ostream which to print debugging messages.
916
917class tstream : public std::ostream {
918 public:
919 inline int getMinLevel () const;
920 inline int getMaxLevel () const;
921 inline int setMinLevel ( int );
922 inline int setMaxLevel ( int );
923 inline int getLevel () const;
924 inline int setLevel ( int );
925 inline bool enabled () const;
926 inline bool enabled ( int ) const;
927 inline tstream& log ( int level, int count=0 );
928 inline tstream& tabw ( int level, int count );
929 inline tstream ( std::ostream & );
930 inline tstream& put ( char c );
931 inline tstream& flush ();
932 private:
933 inline tstream& _tab ();
934 inline tstream& _tabw ( int count );
935 public:
936 // Overload for manipulators.
937 inline tstream& operator<< ( std::ostream& (*pf)(std::ostream &) );
938 private:
939 int _minLevel;
940 int _maxLevel;
941 int _level;
942 Hurricane::Tabulation _tabulation;
943};
944
945
946inline tstream::tstream ( std::ostream& s )
947 : std::ostream(s.rdbuf())
948 , _minLevel (100000)
949 , _maxLevel (0)
950 , _level (0)
951 , _tabulation(" ")
952{ }
953
954inline int tstream::getMinLevel () const { return _minLevel; }
955inline int tstream::getMaxLevel () const { return _maxLevel; }
956inline int tstream::setMinLevel ( int l ) { int pl=_minLevel; _minLevel=l; return pl; }
957inline int tstream::setMaxLevel ( int l ) { int pl=_maxLevel; _maxLevel=l; return pl; }
958inline int tstream::getLevel () const { return _level; }
959inline int tstream::setLevel ( int l ) { int pl=_level; _level=l; return pl; }
960inline bool tstream::enabled () const { return (_level >= _minLevel) and (_level < _maxLevel); }
961inline bool tstream::enabled ( int l ) const { return (l >= _minLevel) and (l < _maxLevel); }
962inline tstream& tstream::tabw ( int level, int count ) { setLevel(level); return _tabw(count); }
963inline tstream& tstream::put ( char c ) { if (enabled()) static_cast<std::ostream*>(this)->put(c); return *this; }
964inline tstream& tstream::flush () { if (enabled()) static_cast<std::ostream*>(this)->flush(); return *this; }
965inline tstream& tstream::operator<< ( std::ostream& (*pf)(std::ostream&) ) { if (enabled()) (*pf)(*this); return *this; }
966inline tstream& operator<< ( tstream& o, const Hurricane::Tabulation& t )
967{ static_cast<std::ostream&>(o) << t; return o; }
968
969inline tstream& tstream::_tab () { if (enabled()) (* static_cast<std::ostream*>(this)) << _tabulation; return *this; }
970inline tstream& tstream::_tabw ( int count )
971{
972 if (enabled()) {
973 if (count > 0) while(count--) _tabulation++;
974 else if (count < 0) while(count++) _tabulation--;
975 }
976 return *this;
977}
978
979inline tstream& tstream::log ( int level, int count )
980{ setLevel(level); _tab(); return _tabw(count); }
981
982// For STL Types.
983inline tstream& operator<< ( tstream& o, const std::string s )
984{ if (o.enabled()) { static_cast<std::ostream&>(o) << s; } return o; };
985
986// For POD Types.
987// template<typename T>
988// inline tstream& operator<< ( tstream& o, T& t )
989// { if (o.enabled()) { static_cast<std::ostream&>(o) << getString<T&>(t); } return o; };
990
991template<typename T>
992inline tstream& operator<< ( tstream& o, T* t )
993{ if (o.enabled()) { static_cast<std::ostream&>(o) << getString<T*>(t); } return o; };
994
995// template<typename T>
996// inline tstream& operator<< ( tstream& o, const T& t )
997// { if (o.enabled()) { static_cast<std::ostream&>(o) << getString<const T&>(t); } return o; };
998
999template<typename T>
1000inline tstream& operator<< ( tstream& o, T t )
1001{ if (o.enabled()) { static_cast<std::ostream&>(o) << getString<T>(t); } return o; };
1002
1003template<typename T>
1004inline tstream& operator<< ( tstream& o, const T* t )
1005{ if (o.enabled()) { static_cast<std::ostream&>(o) << getString<const T*>(t); } return o; };
1006
1007template<>
1008inline tstream& operator<< ( tstream& o, std::ios_base& (*pf)(std::ios_base&) )
1009{ if (o.enabled()) { static_cast<std::ostream&>(o) << pf; } return o; };
1010
1011struct _Tsetw { int n_; };
1012inline _Tsetw tsetw ( int n ) { return { n }; }
1013
1014struct _Tsetf { int n_; };
1015inline _Tsetf tsetf ( int n ) { return { n }; }
1016
1017template<>
1018inline tstream& operator<< ( tstream& o, _Tsetw manip )
1019{ if (o.enabled()) { static_cast<std::ostream&>(o) << std::setw(manip.n_); } return o; }
1020
1021extern tstream cdebug;
1022
1023
1024#define cdebug_log(level,indent) if (cdebug.enabled(level)) cdebug.log(level,indent)
1025#define cdebug_tabw(level,indent) cdebug.tabw(level,indent)
1026
1027
1028# define GETSTRING_POINTER_SUPPORT(Data) \
1029 template<> inline std::string getString<Data*>( Data* data ) \
1030 { \
1031 if (!data) return "NULL [" #Data "]"; \
1032 return data->_getString(); \
1033 } \
1034 \
1035 template<> inline std::string getString<const Data*>( const Data* data ) \
1036 { if (!data) return "NULL [const " #Data "]"; return data->_getString(); }
1037
1038
1039# define IOSTREAM_POINTER_SUPPORT(Data) \
1040 inline std::ostream& operator<< ( std::ostream& o, Data* d ) \
1041 { \
1042 if (!d) return o << "NULL [" #Data "]"; \
1043 return o << "&" << getString<const Data*>(d); \
1044 } \
1045 inline std::ostream& operator<< ( std::ostream& o, const Data* d ) \
1046 { \
1047 if (!d) return o << "NULL [const " #Data "]"; \
1048 return o << "&" << getString<const Data*>(d); \
1049 } \
1050
1051
1052# define TSTREAM_POINTER_SUPPORT(Data) \
1053 inline tstream& operator<< ( tstream& o, Data* d ) \
1054 { return o << "&" << getString<const Data*>(d); } \
1055 inline tstream& operator<< ( tstream& o, const Data* d ) \
1056 { return o << "&" << getString<const Data*>(d); }
1057
1058
1059# define GETRECORD_POINTER_SUPPORT(Data) \
1060 template<> inline Hurricane::Record* getRecord<Data*>( Data* data ) \
1061 { if (!data) return NULL; return data->_getRecord(); } \
1062 \
1063 template<> inline Hurricane::Record* getRecord<const Data*>( const Data* data ) \
1064 { if (!data) return NULL; return data->_getRecord(); }
1065
1066
1067# define GETSTRING_REFERENCE_SUPPORT(Data) \
1068 template<> inline std::string getString<Data&>( Data& data ) \
1069 { return data._getString(); } \
1070 \
1071 template<> inline std::string getString<const Data&>( const Data& data ) \
1072 { return data._getString(); }
1073
1074
1075# define IOSTREAM_REFERENCE_SUPPORT(Data) \
1076 inline std::ostream& operator<< ( std::ostream& o, Data& d ) \
1077 { return o << getString<Data&>(d); } \
1078 \
1079 inline std::ostream& operator<< ( std::ostream& o, const Data& d ) \
1080 { return o << getString<const Data&>(d); } \
1081 \
1082
1083# define GETRECORD_REFERENCE_SUPPORT(Data) \
1084 template<> inline Hurricane::Record* getRecord<Data&>( Data& data ) \
1085 { return data._getRecord(); } \
1086 \
1087 template<> inline Hurricane::Record* getRecord<const Data&>( const Data& data ) \
1088 { return data._getRecord(); }
1089
1090
1091# define GETSTRING_VALUE_SUPPORT(Data) \
1092 template<> inline std::string getString<Data>( Data data ) \
1093 { return data._getString(); }
1094
1095
1096# define IOSTREAM_VALUE_SUPPORT(Data) \
1097 inline std::ostream& operator<< ( std::ostream& o, Data d ) \
1098 { return o << getString<Data>(d); }
1099
1100
1101# define GETRECORD_VALUE_SUPPORT(Data) \
1102 template<> inline Hurricane::Record* getRecord<Data>( Data data ) \
1103 { return data._getRecord(); }
1104
1105
1106# define INSPECTOR_P_SUPPORT(Data) \
1107 GETRECORD_POINTER_SUPPORT(Data) \
1108 GETSTRING_POINTER_SUPPORT(Data) \
1109 IOSTREAM_POINTER_SUPPORT(Data) \
1110 TSTREAM_POINTER_SUPPORT(Data)
1111
1112
1113# define INSPECTOR_R_SUPPORT(Data) \
1114 GETRECORD_REFERENCE_SUPPORT(Data) \
1115 GETSTRING_REFERENCE_SUPPORT(Data) \
1116 IOSTREAM_REFERENCE_SUPPORT(Data)
1117
1118
1119# define INSPECTOR_PR_SUPPORT(Data) \
1120 GETSTRING_POINTER_SUPPORT(Data) \
1121 GETSTRING_REFERENCE_SUPPORT(Data) \
1122 GETSTRING_VALUE_SUPPORT(Data) \
1123 IOSTREAM_POINTER_SUPPORT(Data) \
1124 IOSTREAM_REFERENCE_SUPPORT(Data) \
1125 GETRECORD_POINTER_SUPPORT(Data) \
1126 GETRECORD_REFERENCE_SUPPORT(Data)
1127
1128
1129# define INSPECTOR_PV_SUPPORT(Data) \
1130 GETSTRING_POINTER_SUPPORT(Data) \
1131 GETSTRING_VALUE_SUPPORT(Data) \
1132 IOSTREAM_POINTER_SUPPORT(Data) \
1133 IOSTREAM_VALUE_SUPPORT(Data) \
1134 GETRECORD_POINTER_SUPPORT(Data) \
1135 GETRECORD_VALUE_SUPPORT(Data)
1136
1137
1138// x-----------------------------------------------------------------x
1139// | Classes Neededs in All Hurricane Modules |
1140// x-----------------------------------------------------------------x
1141
1142#include "hurricane/Slot.h"
1143#include "hurricane/Initializer.h"
1144#include "hurricane/JsonWriter.h"
1145#include "hurricane/JsonObject.h"
Generic Collection auto-pointer.
Definition Collection.h:235
Tabulation description (API)
Definition Tabulation.h:33
Trace & indentation enabled stream.
Definition Commons.h:917
bool enabled() const
Definition Commons.h:960
int getLevel() const
Definition Commons.h:958
int setMinLevel(int)
Definition Commons.h:956
tstream & log(int level, int count=0)
Definition Commons.h:979
int setLevel(int)
Definition Commons.h:959
tstream & tabw(int level, int count)
Definition Commons.h:962
int setMaxLevel(int)
Definition Commons.h:957
int getMinLevel() const
Definition Commons.h:954
int getMaxLevel() const
Definition Commons.h:955
Contains Almost Everything.
Definition BasicLayer.h:39
string demangle(const char *symbol)


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