1 #include "bbtkObject.h"
2 #include "bbtkMessageManager.h"
8 //=======================================================================
9 Object::ObjectListType Object::mgObjectList;
10 //=======================================================================
12 //=======================================================================
16 //=======================================================================
19 //=======================================================================
23 //=======================================================================
25 //=======================================================================
26 void Object::InsertInObjectList(Pointer p)
28 bbtkDebugMessage("object",9,"##> Object::InsertInObjectList(\""
29 <<p->GetObjectName()<<"\" ["<<p<<"])"<<std::endl);
30 boost::weak_ptr<Object> w(p);
31 mgObjectList.insert(w);
33 //=======================================================================
36 //=======================================================================
37 void Object::RemoveFromObjectList(WeakPointer p)
39 bbtkDebugMessage("object",9,"##> Object::RemoveFromObjectList()"
41 mgObjectList.erase(p);
44 //=======================================================================
47 //=======================================================================
48 std::string Object::GetObjectName() const
50 return std::string("**Unknown object**");
52 //=======================================================================
54 //=======================================================================
55 std::string Object::GetObjectInfo() const
57 return std::string("");
59 //=======================================================================
61 //=======================================================================
62 void Object::PrintObjectListInfo(const std::string& name)
66 << "=============== Living bbtk::Object pointers ========="<<std::endl;
71 ObjectListType::iterator i;
72 for (i = mgObjectList.begin();
73 i!=mgObjectList.end();
76 if (i->use_count() == 0)
82 Object::Pointer p(i->lock());
83 if (p->GetObjectName().find(name) != std::string::npos )
85 std::cout << n << "/" << mgObjectList.size() << " ";
87 m += p->GetObjectSize();
93 << "------------------------------------------------------"<<std::endl;
95 std::cout << " Total : "<<n<<" objects - "<<m<<" b"<<std::endl;
98 std::cout<<"* Note : "<<u
99 <<" object in list has 0 ref count, "
100 <<"i.e. destroyed without removing itself from the living objects list ! (this is just an implementation error not a memory leak)"<<std::endl;
104 std::cout<<"* Note : "<<u
105 <<" objects in list have 0 ref count, "
106 <<"i.e. destroyed without removing themselves from the living objects list ! (this is just an implementation error not a memory leak)"<<std::endl;
109 << "============ EO Living bbtk::Object pointers ========="<<std::endl;
112 //=======================================================================
115 //=======================================================================
116 void Object::PrintObjectInfo(const std::string& name)
119 ObjectListType::iterator i;
120 for (i = mgObjectList.begin();
121 i!=mgObjectList.end();
125 if (i->use_count() == 0) continue;
126 Object::Pointer p(i->lock());
127 if (p->GetObjectName().find(name) != std::string::npos )
129 std::cout << n << "/" << mgObjectList.size() << " ";
134 //=======================================================================
136 //=======================================================================
137 void Object::PrintObjectInfo(const Object::Pointer& p)
139 std::cout << "* [" << p << "] \t"
140 << p.use_count()-1 << " r \t"
141 << p->GetObjectRecursiveSize() << " ("
142 << p->GetObjectSize() << ") b \t"
143 << p->GetObjectName()
145 std::cout << p->GetObjectInfo();
147 //=======================================================================
149 //=======================================================================
151 void Object::Deleter::operator() (Object* p)
153 std::string name = p->GetObjectName();
154 void* adr = (void*)p;
155 bbtkDebugMessage("object",1,"##> Object::Deleter : deleting \""
156 <<name<<"\" ["<<adr<<"]"<<std::endl);
157 Object::RemoveFromObjectList(mPointer);
159 bbtkDebugMessage("object",2,"<## Object::Deleter : \""<<name<<"\" ["
160 <<adr<<"] deleted"<<std::endl);
162 //=======================================================================
172 //=======================================================================
173 bool StaticInitTime::PrintObjectListInfo = false;
174 //=======================================================================
175 //=======================================================================
176 StaticInitTime::StaticInitTime()
179 //=======================================================================
180 //=======================================================================
181 StaticInitTime::~StaticInitTime()
183 if (PrintObjectListInfo)
185 std::cout << std::endl
186 << "***************** main ended *******************"
187 << std::endl << std::endl;
188 Object::PrintObjectListInfo("");
191 //=======================================================================
192 //=======================================================================
193 // The static instance
194 static StaticInitTime i;
195 //=======================================================================