synaps/base/COUNT.h

00001 #ifndef SYNAPS_UTIL_COUNT_H
00002 #define SYNAPS_UTIL_COUNT_H
00003 
00004 
00005 #ifdef MEMORY_INFO
00006 
00007 #include <iostream>
00008 #include <typeinfo>
00009 #include <map>
00010 #include <synaps/init.h>
00011 
00012 
00013 __BEGIN_NAMESPACE_SYNAPS
00014 
00015 template < typename T >
00016 struct counter {
00017         typedef map<char,unsigned> rep_t;
00018 
00019         rep_t ctr;
00020 
00021         counter(){}
00022 
00023         void incr(char c) {ctr[c]++;}
00024 
00025         ~counter() {
00026                 typedef typename rep_t::const_iterator const_iterator;
00027                 std::cout<<__PRETTY_FUNCTION__<<std::endl;
00028                 //typeid(T).name()<<endl;
00029                 for(const_iterator i = ctr.begin(); i!= ctr.end();i++) {
00030                         if(i->first==' ')
00031                                 std::cout <<"    constructor ()  : "<<i->second<<std::endl;
00032                         else if(i->first=='c')
00033                                 std::cout <<"    constructor copy: "<<i->second<<std::endl;
00034                         else if(i->first=='=')
00035                                 std::cout <<"    operator =      : "<<i->second<<std::endl;
00036                         else
00037                                 std::cout <<"    "<<i->first<<"               : "<<i->second<<std::endl;
00038                 }
00039         }
00040 };
00041 
00042 template < typename T >
00043 struct COUNT {
00044   static counter<T> _counter;
00045   COUNT(){}
00046   COUNT(char c) {COUNT<T>::_counter.incr(c);}
00047 };
00048 
00049 template < typename T > counter<T> COUNT<T>::_counter;
00050 
00051 
00052 __END_NAMESPACE_SYNAPS
00053 
00054 #else
00055 
00056 __BEGIN_NAMESPACE_SYNAPS
00057 
00058 template<class T> struct COUNT {
00059   COUNT(){}
00060   COUNT(char c){}
00061 };
00062 
00063 __END_NAMESPACE_SYNAPS
00064 
00065 #endif // MEMORY_INFO
00066 
00067 #endif //COUNT_H
00068 
00069 

SYNAPS DOCUMENTATION
logo