33#define HURRICANE_COMMONS_H
70 template<
typename DboType>
73 inline void operator() ( DboType* dbo ) { dbo->destroy(); }
77 template<
typename DboType>
78 class dbo_ptr :
public std::shared_ptr<DboType> {
80 dbo_ptr ( DboType* dbo ) : std::shared_ptr<DboType>(dbo,DboDestroy<DboType>()) { }
91 inline string _TName (
const string& s ) {
return s; }
92 inline string _PName (
const string& s ) {
return "Hurricane::" + s; }
95 inline Type abs (
const Type& value ) {
return (value<0) ? -value : value; }
98 inline string demangle (
string symbol ) {
return demangle(symbol.c_str()); }
101 template<
typename Element>
102 inline void erase_element ( vector<Element*>& v,
const Element* e )
104 for (
auto ielement = v.begin() ; ielement != v.end() ; ++ielement )
105 if (*ielement == e) { v.erase( ielement );
return; }
113 inline int floatCompare (
float a,
float b )
115 assert (
sizeof(
float) ==
sizeof(
int) );
117 if ( a == b )
return 0;
118 return *(
int*)&a - *(
int*)&b;
121 inline int floatDifference (
float a,
float b,
int threshold )
123 int difference = floatCompare(a,b);
124 if ( abs(difference) < threshold )
return 0;
126 return (difference<0) ? -1 : 1;
130 inline void floatRound (
float& value,
float precision )
132 float rounded = roundf ( value*precision );
133 value = rounded / precision;
137 inline float roundfp (
float value,
float precision=100.0 ) {
return roundf(value*precision)/precision; }
140 template<
typename Type>
inline void order ( Type& a, Type& b ) {
if (a>b) std::swap(a,b); }
142 template<
typename Type>
inline Type setInBound ( Type lower, Type upper, Type& value )
144 if (value < lower) value = lower;
145 else if (value > upper) value = upper;
150 string& split ( std::string& );
159 inline unsigned int hashFNV (
unsigned int id )
162 static const unsigned int FNVOffsetBasis = 0x811c9dc5;
163 static const unsigned int FNVPrime = 0x01000193;
165 unsigned int hash = FNVOffsetBasis;
166 for (
unsigned int idBytes =
id ; idBytes ; idBytes >>= 8 ) {
167 hash = hash * FNVPrime;
168 hash = hash xor (idBytes & 0xFF);
173 inline unsigned int iterFNV (
unsigned int hash,
unsigned int id )
176 static const unsigned int FNVPrime = 0x01000193;
178 for (
unsigned int idBytes =
id ; idBytes ; idBytes >>= 8 ) {
179 hash = hash * FNVPrime;
180 hash = hash xor (idBytes & 0xFF);
186 inline unsigned int hashFNV ( std::string s )
189 static const unsigned int FNVOffsetBasis = 0x811c9dc5;
190 static const unsigned int FNVPrime = 0x01000193;
192 unsigned int hash = FNVOffsetBasis;
193 for (
size_t i=0 ; i<s.size() ; ++i ) {
194 hash = hash * FNVPrime;
195 hash = hash xor s[i];
201 inline unsigned int hashFNV (
const char* s )
204 static const unsigned int FNVOffsetBasis = 0x811c9dc5;
205 static const unsigned int FNVPrime = 0x01000193;
207 unsigned int hash = FNVOffsetBasis;
208 for ( ; (int)(*s) != 0 ; ++s ) {
209 hash = hash * FNVPrime;
219#include "hurricane/Record.h"
231template<
typename Data>
inline Hurricane::Slot* getSlot ( std::string name, Data );
239template<
typename Data>
inline std::string getString ( Data data )
240{
return std::string(
"<type ")
242 + std::string(
" unsupported by getString()>"); }
244template<>
inline std::string getString<std::nullptr_t> ( std::nullptr_t )
245{
return "nullptr" ; }
249template<>
inline std::string getString<const bool&> (
const bool& b )
250{
return (b)?
"True":
"False" ; }
252template<>
inline std::string getString<const int&> (
const int& i )
253{ std::ostringstream os (
""); os << i;
return os.str(); }
255template<>
inline std::string getString<const long&> (
const long& l )
256{ std::ostringstream os (
""); os << l;
return os.str(); }
258template<>
inline std::string getString<const unsigned int&> (
const unsigned int& u )
259{ std::ostringstream os (
""); os << u;
return os.str(); }
261template<>
inline std::string getString<const unsigned long&> (
const unsigned long& ul )
262{ std::ostringstream os (
""); os << ul;
return os.str(); }
264template<>
inline std::string getString<const unsigned long long&> (
const unsigned long long& ull )
265{ std::ostringstream os (
""); os << ull;
return os.str(); }
267template<>
inline std::string getString<const unsigned short int&> (
const unsigned short int& us )
268{ std::ostringstream os (
""); os << us;
return os.str(); }
270template<>
inline std::string getString<const float&> (
const float& f )
271{ std::ostringstream os (
""); os << f;
return os.str(); }
273template<>
inline std::string getString<const double&> (
const double& d )
274{ std::ostringstream os; os << d;
return os.str(); }
276template<>
inline std::string getString<const std::string&> (
const std::string& s )
281template<>
inline std::string getString<const bool*> (
const bool* b )
282{
return (*b)?
"True":
"False" ; }
284template<>
inline std::string getString<const char*> (
const char* c )
287template<>
inline std::string getString<const int*> (
const int* i )
288{ std::ostringstream os (
""); os << *i;
return os.str(); }
290template<>
inline std::string getString<const long*> (
const long* l )
291{ std::ostringstream os (
""); os << *l;
return os.str(); }
293template<>
inline std::string getString<const unsigned int*> (
const unsigned int* u )
294{ std::ostringstream os (
""); os << *u;
return os.str(); }
296template<>
inline std::string getString<const unsigned long*> (
const unsigned long* ul )
297{ std::ostringstream os (
""); os << *ul;
return os.str(); }
299template<>
inline std::string getString<const unsigned long long*> (
const unsigned long long* ull )
300{ std::ostringstream os (
""); os << *ull;
return os.str(); }
302template<>
inline std::string getString<const unsigned short int*> (
const unsigned short int* us )
303{ std::ostringstream os (
""); os << *us;
return os.str(); }
305template<>
inline std::string getString<const float*> (
const float* f )
306{ std::ostringstream os (
""); os << *f;
return os.str(); }
308template<>
inline std::string getString<const double*> (
const double* d )
309{ std::ostringstream os; os << *d;
return os.str(); }
311template<>
inline std::string getString<const void*> (
const void* p )
312{ std::ostringstream os (
"0x"); os << std::hex << p;
return os.str(); }
314template<>
inline std::string getString<const std::string*> (
const std::string* s )
320template<>
inline std::string getString<bool*> (
bool* b )
321{
return (*b)?
"True":
"False" ; }
323template<>
inline std::string getString<char*> (
char* c )
326template<>
inline std::string getString<int*> (
int* i )
327{ std::ostringstream os (
""); os << *i;
return os.str(); }
329template<>
inline std::string getString<long*> (
long* l )
330{ std::ostringstream os (
""); os << *l;
return os.str(); }
332template<>
inline std::string getString<unsigned int*> (
unsigned int* u )
333{ std::ostringstream os (
""); os << *u;
return os.str(); }
335template<>
inline std::string getString<unsigned long*> (
unsigned long* ul )
336{ std::ostringstream os (
""); os << *ul;
return os.str(); }
338template<>
inline std::string getString<unsigned long long*> (
unsigned long long* ull )
339{ std::ostringstream os (
""); os << *ull;
return os.str(); }
341template<>
inline std::string getString<unsigned short int*> (
unsigned short int* us )
342{ std::ostringstream os (
""); os << *us;
return os.str(); }
344template<>
inline std::string getString<float*> (
float* f )
345{ std::ostringstream os (
""); os << *f;
return os.str(); }
347template<>
inline std::string getString<double*> (
double* d )
348{ std::ostringstream os; os << *d;
return os.str(); }
350template<>
inline std::string getString<void*> (
void* p )
351{ std::ostringstream os (
"0x"); os << std::hex << p;
return os.str(); }
353template<>
inline std::string getString<std::string*> ( std::string* s )
359template<>
inline std::string getString<bool> (
bool b )
360{
return (b)?
"True":
"False" ; }
362template<>
inline std::string getString<char> (
char c )
363{
return std::string(1,c); }
365template<>
inline std::string getString<int> (
int i )
366{ std::ostringstream os (
""); os << i;
return os.str(); }
368template<>
inline std::string getString<long> (
long l )
369{ std::ostringstream os (
""); os << l;
return os.str(); }
371template<>
inline std::string getString<unsigned int> (
unsigned int u )
372{ std::ostringstream os (
""); os << u;
return os.str(); }
374template<>
inline std::string getString<unsigned long> (
unsigned long ul )
375{ std::ostringstream os (
""); os << ul;
return os.str(); }
377template<>
inline std::string getString<unsigned long long> (
unsigned long long ull )
378{ std::ostringstream os (
""); os << ull;
return os.str(); }
380template<>
inline std::string getString<unsigned short int> (
unsigned short int us )
381{ std::ostringstream os (
""); os << us;
return os.str(); }
383template<>
inline std::string getString<float> (
float f )
384{ std::ostringstream os (
""); os << f;
return os.str(); }
386template<>
inline std::string getString<double> (
double d )
387{ std::ostringstream os; os << d;
return os.str(); }
389template<>
inline std::string getString<std::string> ( std::string s )
393template<
typename Data>
inline Hurricane::Record* getRecord ( Data data )
403template<
typename T,
typename U>
404inline std::string getString (
const std::pair<T,U>& p )
406 return "const std::pair<T,U>";
410template<
typename T,
typename U>
411inline Hurricane::Record* getRecord (
const std::pair<T,U>& p )
413 Hurricane::Record* record = NULL;
414 record =
new Hurricane::Record (
"const std::pair<T,U>" );
415 record->add( getSlot<const T>(std::string(
"first" ), &p.first ) );
416 record->add( getSlot<const U>(std::string(
"second"), &p.second) );
421template<
typename T,
typename U>
422inline std::string getString ( std::pair<T,U>& p )
424 return "std::pair<T,U>";
428template<
typename T,
typename U>
429inline Hurricane::Record* getRecord ( std::pair<T,U>& p )
431 Hurricane::Record* record = NULL;
432 record =
new Hurricane::Record (
"std::pair<T,U>" );
433 record->add( getSlot<T>(std::string(
"first" ), &p.first ) );
434 record->add( getSlot<U>(std::string(
"second"), &p.second) );
443template<
typename Element,
size_t N>
444inline std::string getString ( std::array<Element,N>* v )
446 std::string name =
"const std::array<Element,N>:";
447 return name + getString<size_t>(v->size());
451template<
typename Element,
size_t N>
452inline Hurricane::Record* getRecord ( std::array<Element,N>* v )
454 Hurricane::Record* record = NULL;
456 record =
new Hurricane::Record (
"std::array<Element,N>" );
458 typename std::array<Element,N>::iterator iterator = v->begin();
459 while ( iterator != v->end() ) {
460 record->add ( getSlot<Element>(getString(n++), *iterator) );
468template<
typename Element,
size_t N>
469inline std::string getString (
const std::array<Element,N>* v )
471 std::string name =
"const std::array<Element,N>:";
472 return name + getString<size_t>(v->size());
476template<
typename Element,
size_t N>
477inline Hurricane::Record* getRecord (
const std::array<Element,N>* v )
479 Hurricane::Record* record = NULL;
481 record =
new Hurricane::Record (
"const std::array<Element,N>" );
483 typename std::array<Element,N>::const_iterator iterator = v->begin();
484 while ( iterator != v->end() ) {
485 record->add ( getSlot<const Element>(getString(n++), *iterator) );
493template<
typename Element,
size_t N>
494inline std::string getString ( std::array<Element,N>& v )
496 std::string name =
"std::array<Element,N>&:";
497 return name + getString<size_t>(v.size());
501template<
typename Element,
size_t N>
502inline Hurricane::Record* getRecord ( std::array<Element,N>& v )
504 Hurricane::Record* record = NULL;
506 record =
new Hurricane::Record (
"std::array<Element,N>&" );
508 for (
auto element : v )
509 record->add( getSlot<Element>(getString(n++), element) );
515template<
typename Element,
size_t N>
516inline std::string getString (
const std::array<Element,N>& v )
518 std::string name =
"const std::array<Element,N>&:";
519 return name + getString<size_t>(v.size());
523template<
typename Element,
size_t N>
524inline Hurricane::Record* getRecord (
const std::array<Element,N>& v )
526 Hurricane::Record* record = NULL;
528 record =
new Hurricane::Record (
"const std::array<Element,N>&" );
530 for (
auto element : v )
531 record->add( getSlot<Element>(getString(n++), element) );
541template<
typename Element>
542inline std::string getString ( std::vector<Element>* v )
544 std::string name =
"std::vector<Element>*:";
545 return name + getString<size_t>(v->size());
549template<
typename Element>
550inline Hurricane::Record* getRecord ( std::vector<Element>* v )
552 Hurricane::Record* record = NULL;
554 record =
new Hurricane::Record (
"std::vector<Element>*" );
556 typename std::vector<Element>::iterator iterator = v->begin();
557 while ( iterator != v->end() ) {
558 record->add ( getSlot<const Element*>(getString(n++), &(*iterator)) );
570template<
typename Element>
571inline std::string getString ( std::vector<Element*>* v )
573 std::string name =
"std::vector<Element*>*:";
574 return name + getString<size_t>(v->size());
578template<
typename Element>
579inline Hurricane::Record* getRecord ( std::vector<Element*>* v )
581 Hurricane::Record* record = NULL;
583 record =
new Hurricane::Record (
"std::vector<Element*>*" );
585 typename std::vector<Element*>::iterator iterator = v->begin();
586 while ( iterator != v->end() ) {
587 record->add ( getSlot<Element*>(getString(n++), *iterator) );
599template<
typename Element>
600inline std::string getString (
const std::vector<Element>* v )
602 std::string name =
"const std::vector<Element>*:";
603 return name + getString<size_t>(v->size());
607template<
typename Element>
608inline Hurricane::Record* getRecord (
const std::vector<Element>* v )
610 Hurricane::Record* record = NULL;
612 record =
new Hurricane::Record (
"const std::vector<Element>*" );
614 typename std::vector<Element>::const_iterator iterator = v->begin();
615 while ( iterator != v->end() ) {
616 record->add ( getSlot<const Element*>(getString(n++), &(*iterator)) );
628template<
typename Element>
629inline std::string getString (
const std::vector<Element*>* v )
631 std::string name =
"const std::vector<Element*>*:";
632 return name + getString<size_t>(v->size());
636template<
typename Element>
637inline Hurricane::Record* getRecord (
const std::vector<Element*>* v )
639 Hurricane::Record* record = NULL;
640 if (not v->empty()) {
641 record =
new Hurricane::Record (
"const std::vector<Element*>*" );
643 typename std::vector<Element*>::const_iterator iterator = v->begin();
644 while (iterator != v->end()) {
645 record->add ( getSlot<const Element*>(getString(n++), *iterator) );
657template<
typename Element>
658inline std::string getString (
const std::list<Element>* l )
660 std::string name =
"const std::list<Element>*:";
661 return name + getString<size_t>(l->size());
665template<
typename Element>
666inline Hurricane::Record* getRecord (
const std::list<Element>* l )
668 Hurricane::Record* record = NULL;
670 record =
new Hurricane::Record (
"const std::list<Element>" );
672 typename std::list<Element>::const_iterator iterator = l->begin();
673 while ( iterator != l->end() ) {
674 record->add ( getSlot<const Element*>(getString(n++), &(*iterator)) );
682template<
typename Element>
683inline std::string getString ( std::list<Element>* l )
685 std::string name =
"std::list<Element>*:";
686 return name + getString<size_t>(l->size());
690template<
typename Element>
691inline Hurricane::Record* getRecord ( std::list<Element>* l )
693 Hurricane::Record* record = NULL;
695 record =
new Hurricane::Record (
"std::list<Element>" );
697 typename std::list<Element>::iterator iterator = l->begin();
698 while ( iterator != l->end() ) {
699 record->add ( getSlot<const Element*>(getString(n++), &(*iterator)) );
711template<
typename Key,
typename Element>
712inline std::string getString ( std::map<Key,Element>* m )
714 std::string name =
"std::map<Element>:";
715 return name + getString<size_t>(m->size());
719template<
typename Key,
typename Element>
720inline Hurricane::Record* getRecord ( std::map<Key,Element>* m )
722 Hurricane::Record* record = NULL;
724 record =
new Hurricane::Record (
"std::map<Element>" );
725 typename std::map<Key,Element>::iterator iterator = m->begin();
726 while ( iterator != m->end() ) {
727 record->add ( getSlot<Element>(getString(iterator->first), iterator->second) );
735template<
typename Key,
typename Element>
736inline std::string getString (
const std::map<Key,Element>* m )
738 std::string name =
"const std::map<Element>:";
739 return name + getString<size_t>(m->size());
743template<
typename Key,
typename Element>
744inline Hurricane::Record* getRecord (
const std::map<Key,Element>* m )
746 Hurricane::Record* record = NULL;
748 record =
new Hurricane::Record (
"const std::map<Element>" );
749 typename std::map<Key,Element>::const_iterator iterator = m->begin();
750 while ( iterator != m->end() ) {
751 record->add ( getSlot<const Element>(getString(iterator->first), iterator->second) );
763template<
typename Key,
typename Element,
typename Compare>
764inline std::string getString ( std::map<Key,Element,Compare>* m )
766 std::string name =
"std::map<Element>:";
767 return name + getString<size_t>(m->size());
771template<
typename Key,
typename Element,
typename Compare>
772inline Hurricane::Record* getRecord ( std::map<Key,Element,Compare>* m )
774 Hurricane::Record* record = NULL;
776 record =
new Hurricane::Record (
"std::map<Element>" );
777 typename std::map<Key,Element,Compare>::iterator iterator = m->begin();
778 while ( iterator != m->end() ) {
779 record->add ( getSlot<Element>(getString(iterator->first), iterator->second) );
787template<
typename Key,
typename Element,
typename Compare>
788inline std::string getString (
const std::map<Key,Element,Compare>* m )
790 std::string name =
"const std::map<Element>:";
791 return name + getString<size_t>(m->size());
795template<
typename Key,
typename Element,
typename Compare>
796inline Hurricane::Record* getRecord (
const std::map<Key,Element,Compare>* m )
798 Hurricane::Record* record = NULL;
800 record =
new Hurricane::Record (
"const std::map<Element>" );
801 typename std::map<Key,Element,Compare>::const_iterator iterator = m->begin();
802 while ( iterator != m->end() ) {
803 record->add ( getSlot<const Element>(getString(iterator->first), iterator->second) );
815template<
typename Key,
typename Element,
typename Compare>
816inline std::string getString (
const std::multimap<Key,Element,Compare>* m )
818 std::string name =
"const std::multimap<Element>:";
819 return name + getString<size_t>(m->size());
823template<
typename Key,
typename Element,
typename Compare>
824inline Hurricane::Record* getRecord (
const std::multimap<Key,Element,Compare>* m )
826 Hurricane::Record* record = NULL;
828 record =
new Hurricane::Record (
"const std::multimap<Element>" );
829 typename std::multimap<Key,Element,Compare>::const_iterator iterator = m->begin();
830 while ( iterator != m->end() ) {
831 record->add ( getSlot<const Element>(getString(iterator->first), iterator->second) );
839template<
typename Key,
typename Element,
typename Compare>
840inline std::string getString ( std::multimap<Key,Element,Compare>* m )
842 std::string name =
"std::multimap<Element>:";
843 return name + getString<size_t>(m->size());
847template<
typename Key,
typename Element,
typename Compare>
848inline Hurricane::Record* getRecord ( std::multimap<Key,Element,Compare>* m )
850 Hurricane::Record* record = NULL;
852 record =
new Hurricane::Record (
"std::multimap<Element>" );
853 typename std::multimap<Key,Element,Compare>::iterator iterator = m->begin();
854 while ( iterator != m->end() ) {
855 record->add ( getSlot<Element>(getString(iterator->first), iterator->second) );
867template<
typename Element,
typename Compare>
868inline std::string getString (
const std::set<Element,Compare>* s )
870 std::string name =
"const std::set<Element>:";
871 return name + getString<size_t>(s->size());
875template<
typename Element,
typename Compare>
876inline Hurricane::Record* getRecord (
const std::set<Element,Compare>* s )
878 Hurricane::Record* record = NULL;
880 record =
new Hurricane::Record (
"const std::set<Element>" );
882 typename std::set<Element,Compare>::const_iterator iterator = s->begin();
883 while ( iterator != s->end() ) {
884 record->add ( getSlot<const Element>(getString(n++), *iterator) );
892template<
typename Element,
typename Compare,
typename Allocator >
893inline std::string getString ( std::set<Element,Compare,Allocator>* s )
895 std::string name =
"std::set<Element>:";
896 return name + getString<size_t>(s->size());
900template<
typename Element,
typename Compare,
typename Allocator >
901inline Hurricane::Record* getRecord ( std::set<Element,Compare,Allocator>* s )
903 Hurricane::Record* record = NULL;
904 if (not s->empty()) {
905 record =
new Hurricane::Record (
"std::set<Element>" );
907 typename std::set<Element,Compare,Allocator>::iterator iterator = s->begin();
908 while ( iterator != s->end() ) {
909 record->add( getSlot<Element>(getString(n++), *iterator) );
920template<
typename Element,
typename Compare>
921inline std::string getString (
const std::set<Element,Compare>& s )
923 std::string name =
"const std::set<Element>:";
924 return name + getString<size_t>(s.size());
928template<
typename Element,
typename Compare>
929inline Hurricane::Record* getRecord (
const std::set<Element,Compare>& s )
931 Hurricane::Record* record = NULL;
933 record =
new Hurricane::Record (
"const std::set<Element>" );
935 typename std::set<Element,Compare>::const_iterator iterator = s.begin();
936 while ( iterator != s.end() ) {
937 record->add ( getSlot<Element>(getString(n++), *iterator) );
948template<
typename Element,
typename Compare>
949inline std::string getString (
const std::multiset<Element,Compare>* s )
951 std::string name =
"std::multiset<Element>:";
952 return name + getString<size_t>(s->size());
956template<
typename Element,
typename Compare>
957inline Hurricane::Record* getRecord (
const std::multiset<Element,Compare>* s )
959 Hurricane::Record* record = NULL;
961 record =
new Hurricane::Record (
"std::multiset<Element>" );
963 typename std::multiset<Element,Compare>::const_iterator iterator = s->begin();
964 while ( iterator != s->end() ) {
965 record->add ( getSlot<Element>(getString(n++), *iterator) );
973#include "hurricane/Tabulation.h"
981class tstream :
public std::ostream {
990 inline bool enabled (
int )
const;
991 inline tstream&
log (
int level,
int count=0 );
992 inline tstream&
tabw (
int level,
int count );
993 inline tstream ( std::ostream & );
994 inline tstream& put (
char c );
995 inline tstream& flush ();
997 inline tstream& _tab ();
998 inline tstream& _tabw (
int count );
1001 inline tstream& operator<< ( std::ostream& (*pf)(std::ostream &) );
1010inline tstream::tstream ( std::ostream& s )
1011 : std::ostream(s.rdbuf())
1012 , _minLevel (100000)
1024inline bool tstream::enabled ()
const {
return (_level >= _minLevel) and (_level < _maxLevel); }
1027inline tstream& tstream::put (
char c ) {
if (
enabled())
static_cast<std::ostream*
>(
this)->put(c);
return *
this; }
1028inline tstream& tstream::flush () {
if (
enabled())
static_cast<std::ostream*
>(
this)->flush();
return *
this; }
1029inline tstream& tstream::operator<< ( std::ostream& (*pf)(std::ostream&) ) {
if (
enabled()) (*pf)(*this);
return *
this; }
1031{
static_cast<std::ostream&
>(o) << t;
return o; }
1033inline tstream& tstream::_tab () {
if (
enabled()) (*
static_cast<std::ostream*
>(
this)) << _tabulation;
return *
this; }
1034inline tstream& tstream::_tabw (
int count )
1037 if (count > 0)
while(count--) _tabulation++;
1038 else if (count < 0)
while(count++) _tabulation--;
1044{
setLevel(level); _tab();
return _tabw(count); }
1048{
if (o.
enabled()) {
static_cast<std::ostream&
>(o) << s; }
return o; };
1057{
if (o.
enabled()) {
static_cast<std::ostream&
>(o) << getString<T*>(t); }
return o; };
1065{
if (o.
enabled()) {
static_cast<std::ostream&
>(o) << getString<T>(t); }
return o; };
1069{
if (o.
enabled()) {
static_cast<std::ostream&
>(o) << getString<const T*>(t); }
return o; };
1072inline tstream& operator<< (
tstream& o, std::ios_base& (*pf)(std::ios_base&) )
1073{
if (o.
enabled()) {
static_cast<std::ostream&
>(o) << pf; }
return o; };
1075struct _Tsetw {
int n_; };
1076inline _Tsetw tsetw (
int n ) {
return { n }; }
1078struct _Tsetf {
int n_; };
1079inline _Tsetf tsetf (
int n ) {
return { n }; }
1083{
if (o.
enabled()) {
static_cast<std::ostream&
>(o) << std::setw(manip.n_); }
return o; }
1088#define cdebug_log(level,indent) if (cdebug.enabled(level)) cdebug.log(level,indent)
1089#define cdebug_tabw(level,indent) cdebug.tabw(level,indent)
1092# define GETSTRING_POINTER_SUPPORT(Data) \
1093 template<> inline std::string getString<Data*>( Data* data ) \
1095 if (!data) return "NULL [" #Data "]"; \
1096 return data->_getString(); \
1099 template<> inline std::string getString<const Data*>( const Data* data ) \
1100 { if (!data) return "NULL [const " #Data "]"; return data->_getString(); }
1103# define IOSTREAM_POINTER_SUPPORT(Data) \
1104 inline std::ostream& operator<< ( std::ostream& o, Data* d ) \
1106 if (!d) return o << "NULL [" #Data "]"; \
1107 return o << "&" << getString<const Data*>(d); \
1109 inline std::ostream& operator<< ( std::ostream& o, const Data* d ) \
1111 if (!d) return o << "NULL [const " #Data "]"; \
1112 return o << "&" << getString<const Data*>(d); \
1116# define TSTREAM_POINTER_SUPPORT(Data) \
1117 inline tstream& operator<< ( tstream& o, Data* d ) \
1118 { return o << "&" << getString<const Data*>(d); } \
1119 inline tstream& operator<< ( tstream& o, const Data* d ) \
1120 { return o << "&" << getString<const Data*>(d); }
1123# define GETRECORD_POINTER_SUPPORT(Data) \
1124 template<> inline Hurricane::Record* getRecord<Data*>( Data* data ) \
1125 { if (!data) return NULL; return data->_getRecord(); } \
1127 template<> inline Hurricane::Record* getRecord<const Data*>( const Data* data ) \
1128 { if (!data) return NULL; return data->_getRecord(); }
1131# define GETSTRING_REFERENCE_SUPPORT(Data) \
1132 template<> inline std::string getString<Data&>( Data& data ) \
1133 { return data._getString(); } \
1135 template<> inline std::string getString<const Data&>( const Data& data ) \
1136 { return data._getString(); }
1139# define IOSTREAM_REFERENCE_SUPPORT(Data) \
1140 inline std::ostream& operator<< ( std::ostream& o, Data& d ) \
1141 { return o << getString<Data&>(d); } \
1143 inline std::ostream& operator<< ( std::ostream& o, const Data& d ) \
1144 { return o << getString<const Data&>(d); } \
1147# define GETRECORD_REFERENCE_SUPPORT(Data) \
1148 template<> inline Hurricane::Record* getRecord<Data&>( Data& data ) \
1149 { return data._getRecord(); } \
1151 template<> inline Hurricane::Record* getRecord<const Data&>( const Data& data ) \
1152 { return data._getRecord(); }
1155# define GETSTRING_VALUE_SUPPORT(Data) \
1156 template<> inline std::string getString<Data>( Data data ) \
1157 { return data._getString(); }
1160# define IOSTREAM_VALUE_SUPPORT(Data) \
1161 inline std::ostream& operator<< ( std::ostream& o, Data d ) \
1162 { return o << getString<Data>(d); }
1165# define GETRECORD_VALUE_SUPPORT(Data) \
1166 template<> inline Hurricane::Record* getRecord<Data>( Data data ) \
1167 { return data._getRecord(); }
1170# define INSPECTOR_P_SUPPORT(Data) \
1171 GETRECORD_POINTER_SUPPORT(Data) \
1172 GETSTRING_POINTER_SUPPORT(Data) \
1173 IOSTREAM_POINTER_SUPPORT(Data) \
1174 TSTREAM_POINTER_SUPPORT(Data)
1177# define INSPECTOR_R_SUPPORT(Data) \
1178 GETRECORD_REFERENCE_SUPPORT(Data) \
1179 GETSTRING_REFERENCE_SUPPORT(Data) \
1180 IOSTREAM_REFERENCE_SUPPORT(Data)
1183# define INSPECTOR_PR_SUPPORT(Data) \
1184 GETSTRING_POINTER_SUPPORT(Data) \
1185 GETSTRING_REFERENCE_SUPPORT(Data) \
1186 GETSTRING_VALUE_SUPPORT(Data) \
1187 IOSTREAM_POINTER_SUPPORT(Data) \
1188 IOSTREAM_REFERENCE_SUPPORT(Data) \
1189 GETRECORD_POINTER_SUPPORT(Data) \
1190 GETRECORD_REFERENCE_SUPPORT(Data)
1193# define INSPECTOR_PV_SUPPORT(Data) \
1194 GETSTRING_POINTER_SUPPORT(Data) \
1195 GETSTRING_VALUE_SUPPORT(Data) \
1196 IOSTREAM_POINTER_SUPPORT(Data) \
1197 IOSTREAM_VALUE_SUPPORT(Data) \
1198 GETRECORD_POINTER_SUPPORT(Data) \
1199 GETRECORD_VALUE_SUPPORT(Data)
1206#include "hurricane/Slot.h"
1207#include "hurricane/Initializer.h"
1208#include "hurricane/JsonWriter.h"
1209#include "hurricane/JsonObject.h"
1223 static uint64_t _classBit;
1224 static std::map<uint64_t,std::string> _classNames;
1225 std::string _className;
1226 const FastRTTI* _baseRTTI;
1230 inline FastRTTI ( std::string className,
const FastRTTI* baseRTTI );
1232 inline uint64_t classId ()
const;
1233 inline bool hasBaseClass ( uint64_t )
const;
1234 inline void initialize ();
1235 inline std::string _getString ()
const;
1236 inline Record* _getRecord ()
const;
1240 FastRTTI::FastRTTI ( std::string className,
const FastRTTI* baseRTTI )
1241 : _className(
"<"+className+
">")
1242 , _baseRTTI(baseRTTI)
1245 if (baseRTTI)
const_cast<FastRTTI*
>( baseRTTI )->initialize();
1249 inline uint64_t FastRTTI::classId ()
const {
return _classId; }
1251 inline bool FastRTTI::hasBaseClass ( uint64_t baseClassId )
const
1252 {
return (_baseIds bitand baseClassId); }
1254 inline void FastRTTI::initialize ()
1256 if (classId())
return;
1257 _classId = (1 << _classBit++);
1259 _classNames[ _classId ] = _className;
1260 if (_baseRTTI) _baseIds = _baseRTTI->_baseIds;
1261 _baseIds |= _classId;
1265 template<
typename Derived>
1266 class derived_cast {
1268 Derived* _derivedPointer;
1270 template<
typename Base>
1271 inline derived_cast ( Base* basePointer )
1272 : _derivedPointer(nullptr)
1274 if (not basePointer)
return;
1275 if (basePointer->vfastRTTI().hasBaseClass( Derived::fastRTTI().classId() ))
1276 _derivedPointer =
static_cast<Derived*
>( basePointer );
1278 inline operator Derived* ()
const;
1281 template<
typename Derived>
1282 inline derived_cast<Derived>::operator Derived* ()
const {
return _derivedPointer; }
1288INSPECTOR_P_SUPPORT(Hurricane::FastRTTI);
1294 inline std::string FastRTTI::_getString ()
const {
return _className +
":" + getString(_baseIds); }
1296 inline Record* FastRTTI::_getRecord ()
const
1298 Record* record =
new Record ( getString(
this) );
1299 for (
size_t bit=0 ; bit<64 ; ++bit ) {
1300 uint64_t classMask = (((uint64_t)1) << bit);
1301 if (_baseIds & classMask) {
1302 std::string baseName = getString( classMask ) +
" -> " + _classNames[ classMask ];
1303 record->add( getSlot( getString(bit), baseName ));
Tabulation description (API).
Definition Tabulation.h:33
Trace & indentation enabled stream.
Definition Commons.h:981
bool enabled() const
Definition Commons.h:1024
int getLevel() const
Definition Commons.h:1022
int setMinLevel(int)
Definition Commons.h:1020
tstream & log(int level, int count=0)
Definition Commons.h:1043
int setLevel(int)
Definition Commons.h:1023
tstream & tabw(int level, int count)
Definition Commons.h:1026
int setMaxLevel(int)
Definition Commons.h:1021
int getMinLevel() const
Definition Commons.h:1018
int getMaxLevel() const
Definition Commons.h:1019
Contains Almost Everything.
Definition BasicLayer.h:39
string demangle(const char *symbol)