21 static const std::string& s_class() {
22 static const std::string s_v(
"tools::mem");
26 mem(){increment(s_class().c_str());}
27 virtual ~mem(){decrement(s_class().c_str());}
29 mem& operator=(
const mem&){
return *
this;}
34 static void increment(
const char* a_class){
36 if(check_by_class()) {
37 mem_list::iterator it;
38 for(it=list().
begin();it!=list().end();++it) {
39 if(!::strcmp((*it).first.c_str(),a_class)) {
44 list().push_back(std::pair<std::string,int>(std::string(a_class),1));
48 static void decrement(
const char* a_class,
unsigned int a_num = 1){
50 if(check_by_class()) {
51 mem_list::iterator it;
52 for(it=list().
begin();it!=list().end();++it) {
53 if(!::strcmp((*it).first.c_str(),a_class)) {
54 (*it).second -= a_num;
58 list().push_back(std::pair<std::string,int>(std::string(a_class),-
int(a_num)));
62 static void set_check_by_class(
bool a_value) {
63 check_by_class() = a_value;
69 static void balance(std::ostream& a_out){
71 a_out <<
"tools::mem::balance :"
72 <<
" bad global object balance : " << counter()
74 if(check_by_class()) {
75 a_out <<
"tools::mem::balance :"
76 <<
" check by class was enabled."
79 a_out <<
"tools::mem::balance :"
80 <<
" check by class was disabled."
84 mem_list::iterator it;
85 for(it=list().
begin();it!=list().end();++it) {
87 a_out <<
"tools::mem::balance :"
88 <<
" for class " << (*it).first
89 <<
", bad object balance : " << (*it).second
98 static int& counter() {
99 static int s_count = 0;
103 static bool& check_by_class() {
104 static bool s_check_by_class =
false;
105 return s_check_by_class;
109 typedef std::list< std::pair<std::string,int> > mem_list;
111 static mem_list& list() {
112 static mem_list* s_list =
new mem_list();
117 inline const std::string& s_new() {
118 static const std::string s_v(
"new");
122 inline const std::string& s_malloc() {
123 static const std::string s_v(
"malloc");
127 inline const std::string& s_tex() {
128 static const std::string s_v(
"tex");
132 inline const std::string& s_gsto() {
133 static const std::string s_v(
"gsto");