1 #ifndef TestSuite_JSONStats_h
2 #define TestSuite_JSONStats_h
4 #include "../../JSONOptions.h"
6 #if defined(JSON_UNIT_TEST) || defined(JSON_DEBUG)
7 #define LIBJSON_OBJECT(name)\
8 static size_t & getCtorCounter(void){\
9 static size_t count = 0;\
10 static int i = JSONStats::setCallbacks(getCtorCounter, getCopyCtorCounter, getAssignmentCounter, getDtorCounter, #name);\
13 static size_t & getCopyCtorCounter(void){\
14 static size_t count = 0;\
15 static int i = JSONStats::setCallbacks(getCtorCounter, getCopyCtorCounter, getAssignmentCounter, getDtorCounter, #name);\
18 static size_t & getAssignmentCounter(void){\
19 static size_t count = 0;\
20 static int i = JSONStats::setCallbacks(getCtorCounter, getCopyCtorCounter, getAssignmentCounter, getDtorCounter, #name);\
23 static size_t & getDtorCounter(void){\
24 static size_t count = 0;\
25 static int i = JSONStats::setCallbacks(getCtorCounter, getCopyCtorCounter, getAssignmentCounter, getDtorCounter, #name);\
28 #define LIBJSON_CTOR getCtorCounter() += 1
29 #define LIBJSON_COPY_CTOR getCopyCtorCounter() += 1
30 #define LIBJSON_ASSIGNMENT getAssignmentCounter() += 1
31 #define LIBJSON_DTOR getDtorCounter() += 1
40 std::map<getCounter_m, objectStructure*> & mymap = getMapper();
41 std::map<getCounter_m, objectStructure*>::iterator b = mymap.begin();
42 std::map<getCounter_m, objectStructure*>::iterator e = mymap.end();
43 std::cout <<
"Counters for libjson:" << std::endl;
45 std::cout <<
" " << b -> second -> _name << std::endl;
46 std::cout <<
" Constructor: " << b -> second -> _cTor() << std::endl;
47 std::cout <<
" Copy Constructor: " << b -> second -> _ccTor() << std::endl;
48 std::cout <<
" Assignment: " << b -> second -> _assign() << std::endl;
49 std::cout <<
" Destructor: " << b -> second -> _dTor() << std::endl;
54 typedef size_t & (*getCounter_m)(void);
55 struct objectStructure {
56 objectStructure(getCounter_m cTor, getCounter_m ccTor, getCounter_m assign, getCounter_m dTor,
const std::string & name):
57 _cTor(cTor), _ccTor(ccTor), _assign(assign), _dTor(dTor), _name(name){}
64 static int setCallbacks(getCounter_m cTor, getCounter_m ccTor, getCounter_m assign, getCounter_m dtor,
const std::string & name){
65 getMapper()[cTor] =
new objectStructure (cTor, ccTor, assign, dtor, name);
69 static std::map<getCounter_m, objectStructure*> & getMapper(
void) {
70 static std::map<getCounter_m, objectStructure*> mymap;
75 #define LIBJSON_OBJECT(name)
76 #define LIBJSON_CTOR (void)0
77 #define LIBJSON_DTOR (void)0
78 #define LIBJSON_COPY_CTOR (void)0
79 #define LIBJSON_ASSIGNMENT (void)0
80 typedef int JSONStats;