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()
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());
85 m += p->GetObjectSize();
89 << "------------------------------------------------------"<<std::endl;
91 std::cout << " Total : "<<n<<" objects - "<<m<<" b"<<std::endl;
94 std::cout<<"* Note : "<<u
95 <<" object in list has 0 ref count, "
96 <<"i.e. destroyed without removing itself from the living objects list ! (this is just an implementation error not a memory leak)"<<std::endl;
100 std::cout<<"* Note : "<<u
101 <<" objects in list have 0 ref count, "
102 <<"i.e. destroyed without removing themselves from the living objects list ! (this is just an implementation error not a memory leak)"<<std::endl;
105 << "============ EO Living bbtk::Object pointers ========="<<std::endl;
108 //=======================================================================
110 //=======================================================================
111 void Object::PrintObjectInfo(const std::string& name)
114 ObjectListType::iterator i;
115 for (i = mgObjectList.begin();
116 i!=mgObjectList.end();
120 if (i->use_count() == 0) continue;
121 Object::Pointer p(i->lock());
122 if (p->GetObjectName().find(name) != std::string::npos )
124 std::cout << n << "/" << mgObjectList.size() << " ";
129 //=======================================================================
131 //=======================================================================
132 void Object::PrintObjectInfo(const Object::Pointer& p)
134 std::cout << "* [" << p << "] \t"
135 << p.use_count()-1 << " r \t"
136 << p->GetObjectRecursiveSize() << " ("
137 << p->GetObjectSize() << ") b \t"
138 << p->GetObjectName()
140 std::cout << p->GetObjectInfo();
142 //=======================================================================
144 //=======================================================================
146 void Object::Deleter::operator() (Object* p)
148 std::string name = p->GetObjectName();
149 void* adr = (void*)p;
150 bbtkDebugMessage("object",1,"##> Object::Deleter : deleting \""
151 <<name<<"\" ["<<adr<<"]"<<std::endl);
152 Object::RemoveFromObjectList(mPointer);
154 bbtkDebugMessage("object",2,"<## Object::Deleter : \""<<name<<"\" ["
155 <<adr<<"] deleted"<<std::endl);
157 //=======================================================================
167 //=======================================================================
168 bool StaticInitTime::PrintObjectListInfo = false;
169 //=======================================================================
170 //=======================================================================
171 StaticInitTime::StaticInitTime()
174 //=======================================================================
175 //=======================================================================
176 StaticInitTime::~StaticInitTime()
178 if (PrintObjectListInfo)
180 std::cout << std::endl
181 << "***************** main ended *******************"
182 << std::endl << std::endl;
183 Object::PrintObjectListInfo();
186 //=======================================================================
187 //=======================================================================
188 // The static instance
189 static StaticInitTime i;
190 //=======================================================================