1 #include "bbtkObject.h"
2 #include "bbtkMessageManager.h"
3 #include "bbtkPackage.h"
9 //=======================================================================
10 Object::ObjectListType Object::mgObjectList;
11 Object::ObjectListType Object::mgPackageList;
12 //=======================================================================
14 //=======================================================================
18 //=======================================================================
21 //=======================================================================
25 //=======================================================================
27 //=======================================================================
28 void Object::InsertInObjectList(Pointer p)
30 bbtkDebugMessage("object",9,"##> Object::InsertInObjectList(\""
31 <<p->GetObjectName()<<"\" ["<<p<<"])"<<std::endl);
32 boost::weak_ptr<Object> w(p);
33 mgObjectList.insert(w);
35 //=======================================================================
37 //=======================================================================
38 void Object::InsertInPackageList(Pointer p)
40 bbtkDebugMessage("object",9,"##> Object::InsertInPackageList(\""
41 <<p->GetObjectName()<<"\" ["<<p<<"])"<<std::endl);
42 boost::weak_ptr<Object> w(p);
43 mgPackageList.insert(w);
45 //=======================================================================
48 //=======================================================================
49 void Object::RemoveFromObjectList(WeakPointer p)
51 bbtkDebugMessage("object",9,"##> Object::RemoveFromObjectList()"
53 mgObjectList.erase(p);
56 //=======================================================================
59 //=======================================================================
60 std::string Object::GetObjectName() const
62 return std::string("**Unknown object**");
64 //=======================================================================
66 //=======================================================================
67 std::string Object::GetObjectInfo() const
69 return std::string("");
71 //=======================================================================
73 //=======================================================================
74 void Object::PrintObjectListInfo(const std::string& name)
78 << "=============== Living bbtk::Object pointers ========="<<std::endl;
83 ObjectListType::iterator i;
84 for (i = mgObjectList.begin();
85 i!=mgObjectList.end();
88 if (i->use_count() == 0)
94 Object::Pointer p(i->lock());
95 if (p->GetObjectName().find(name) != std::string::npos )
97 std::cout << n << "/" << mgObjectList.size() << " ";
99 m += p->GetObjectSize();
105 << "------------------------------------------------------"<<std::endl;
107 std::cout << " Total : "<<n<<" objects - "<<m<<" b"<<std::endl;
110 std::cout<<"* Note : "<<u
111 <<" object in list has 0 ref count, "
112 <<"i.e. destroyed without removing itself from the living objects list ! (this is just an implementation error not a memory leak)"<<std::endl;
116 std::cout<<"* Note : "<<u
117 <<" objects in list have 0 ref count, "
118 <<"i.e. destroyed without removing themselves from the living objects list ! (this is just an implementation error not a memory leak)"<<std::endl;
121 << "============ EO Living bbtk::Object pointers ========="<<std::endl;
124 //=======================================================================
127 //=======================================================================
128 void Object::PrintObjectInfo(const std::string& name)
131 ObjectListType::iterator i;
132 for (i = mgObjectList.begin();
133 i!=mgObjectList.end();
137 if (i->use_count() == 0) continue;
138 Object::Pointer p(i->lock());
139 if (p->GetObjectName().find(name) != std::string::npos )
141 std::cout << n << "/" << mgObjectList.size() << " ";
146 //=======================================================================
148 //=======================================================================
149 void Object::PrintObjectInfo(const Object::Pointer& p)
151 std::cout << "* [" << p << "] \t"
152 << p.use_count()-1 << " r \t"
153 << p->GetObjectRecursiveSize() << " ("
154 << p->GetObjectSize() << ") b \t"
155 << p->GetObjectName()
157 std::cout << p->GetObjectInfo();
159 //=======================================================================
161 //=======================================================================
163 void Object::Deleter::operator() (Object* p)
165 std::string name = p->GetObjectName();
166 void* adr = (void*)p;
167 bbtkDebugMessage("object",1,"##> Object::Deleter : deleting \""
168 <<name<<"\" ["<<adr<<"]"<<std::endl);
169 Object::RemoveFromObjectList(mPointer);
171 bbtkDebugMessage("object",2,"<## Object::Deleter : \""<<name<<"\" ["
172 <<adr<<"] deleted"<<std::endl);
174 //=======================================================================
179 void Object::ReleasePackages()
181 bbtkDebugMessage("object",1,"##> Object::ReleasePackages()"<<std::endl);
182 // Release package pointers
183 ObjectListType::iterator i;
184 for (i = mgPackageList.begin();
185 i!= mgPackageList.end();
188 if (i->use_count() != 0)
190 // Object::Pointer p(i->lock());
191 Package::WeakPointer w(i->lock()->GetThisPointer<Package>());
194 if (p->GetObjectName().find(name) != std::string::npos )
196 std::cout << n << "/" << mgObjectList.size() << " ";
198 m += p->GetObjectSize();
210 //=======================================================================
211 bool StaticInitTime::PrintObjectListInfo = false;
212 //=======================================================================
213 //=======================================================================
214 StaticInitTime::StaticInitTime()
217 //=======================================================================
218 //=======================================================================
219 StaticInitTime::~StaticInitTime()
221 Object::ReleasePackages();
223 if (PrintObjectListInfo)
225 std::cout << std::endl
226 << "************************** main ended *******************"
227 << std::endl << std::endl;
228 Object::PrintObjectListInfo("");
230 if (Object::GetObjectsCount()>0)
232 std::cout << std::endl;
233 std::cout << "**************************** WARNING *************************"
235 std::cout << "**** "<< Object::GetObjectsCount()
236 <<" bbtk objects still alive after main ended"<<std::endl;
237 if (!PrintObjectListInfo)
241 <<"Rerun bbi with -D option or put 'debug -D' in bbs file"
244 <<"to view the objects list "
247 std::cout << "**************************************************************"
253 //=======================================================================
254 //=======================================================================
255 // The static instance
256 static StaticInitTime i;
257 //=======================================================================