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


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