bbtk::Object Class Reference

#include <bbtkObject.h>

Inheritance diagram for bbtk::Object:

Inheritance graph
[legend]

List of all members.

Public Types

typedef boost::shared_ptr< ObjectPointer
typedef boost::weak_ptr< ObjectWeakPointer

Public Member Functions

 Object ()
virtual ~Object ()
virtual std::string GetObjectName () const
virtual std::string GetObjectInfo () const
virtual size_t GetObjectSize () const
virtual size_t GetObjectInternalSize () const
virtual size_t GetObjectRecursiveSize () const
long GetUseCount ()

Static Public Member Functions

static void InsertInObjectList (Pointer)
static void RemoveFromObjectList (WeakPointer)
static void InsertInPackageList (Pointer)
static void ReleasePackages ()
static void PrintObjectListInfo (const std::string &name)
static void PrintObjectInfo (const Pointer &o)
static long GetObjectsCount ()

Protected Member Functions

void LockThis ()
void UnLockThis ()
template<class U>
boost::shared_ptr< U > GetThisPointer () const

Static Protected Member Functions

template<class U>
static boost::shared_ptr< U > MakePointer (U *s, bool lock=false)
template<class U, class D>
static boost::shared_ptr< U > MakePointer (U *s, const D &del, bool lock=false)

Private Types

typedef std::set
< boost::weak_ptr< Object > > 
ObjectListType

Private Attributes

WeakPointer mThisPointer
Pointer mThisPointerLocked

Static Private Attributes

static ObjectListType mgObjectList
static ObjectListType mgPackageList

Classes

struct  Deleter
 Default objects deleter : removes object from list on deletion. More...


Detailed Description

Definition at line 49 of file bbtkObject.h.


Member Typedef Documentation

typedef boost::shared_ptr<Object> bbtk::Object::Pointer

typedef boost::weak_ptr<Object> bbtk::Object::WeakPointer

typedef std::set<boost::weak_ptr<Object> > bbtk::Object::ObjectListType [private]

Definition at line 137 of file bbtkObject.h.


Constructor & Destructor Documentation

bbtk::Object::Object (  ) 

Definition at line 46 of file bbtkObject.cxx.

00047   { 
00048   }

bbtk::Object::~Object (  )  [virtual]

Definition at line 53 of file bbtkObject.cxx.

00054   { 
00055   }


Member Function Documentation

std::string bbtk::Object::GetObjectName (  )  const [virtual]

Reimplemented in bbtk::Connection, bbtk::Executer, bbtk::Factory, bbtk::Interpreter, bbtk::Package, and bbtk::Transcriptor.

Definition at line 91 of file bbtkObject.cxx.

Referenced by bbtk::BlackBox::Deleter::Delete(), and bbtk::Object::Deleter::operator()().

00092   {
00093     return std::string("**Unknown object**");
00094   }

Here is the caller graph for this function:

std::string bbtk::Object::GetObjectInfo (  )  const [virtual]

Reimplemented in bbtk::Connection, bbtk::Executer, bbtk::Factory, bbtk::Interpreter, bbtk::Package, and bbtk::Transcriptor.

Definition at line 98 of file bbtkObject.cxx.

00099   {
00100     return std::string("");
00101   }

virtual size_t bbtk::Object::GetObjectSize (  )  const [inline, virtual]

Reimplemented in bbtk::Connection, bbtk::Executer, bbtk::Factory, bbtk::Interpreter, bbtk::Package, and bbtk::Transcriptor.

Definition at line 60 of file bbtkObject.h.

00060 { return sizeof(Object); }

virtual size_t bbtk::Object::GetObjectInternalSize (  )  const [inline, virtual]

Reimplemented in bbtk::Connection, bbtk::Executer, bbtk::Factory, bbtk::Interpreter, bbtk::Package, and bbtk::Transcriptor.

Definition at line 61 of file bbtkObject.h.

00061 { return sizeof(Object); }

virtual size_t bbtk::Object::GetObjectRecursiveSize (  )  const [inline, virtual]

Reimplemented in bbtk::Connection, bbtk::Executer, bbtk::Factory, bbtk::Interpreter, bbtk::Package, and bbtk::Transcriptor.

Definition at line 62 of file bbtkObject.h.

00062 { return sizeof(Object); }

long bbtk::Object::GetUseCount (  )  [inline]

Definition at line 63 of file bbtkObject.h.

00063 { return mThisPointer.use_count(); }

void bbtk::Object::InsertInObjectList ( Pointer  p  )  [static]

Definition at line 59 of file bbtkObject.cxx.

References bbtkDebugMessage, and mgObjectList.

00060   { 
00061     bbtkDebugMessage("object",9,"##> Object::InsertInObjectList(\""
00062                      <<p->GetObjectName()<<"\" ["<<p<<"])"<<std::endl);
00063     boost::weak_ptr<Object> w(p);
00064     mgObjectList.insert(w); 
00065   }

void bbtk::Object::RemoveFromObjectList ( WeakPointer  p  )  [static]

Definition at line 80 of file bbtkObject.cxx.

References bbtkDebugMessage, and mgObjectList.

00081   { 
00082     bbtkDebugMessage("object",9,"##> Object::RemoveFromObjectList()"
00083                      <<std::endl);
00084     mgObjectList.erase(p);
00085 
00086   }

void bbtk::Object::InsertInPackageList ( Pointer  p  )  [static]

Definition at line 69 of file bbtkObject.cxx.

References bbtkDebugMessage, and mgPackageList.

00070   { 
00071     bbtkDebugMessage("object",9,"##> Object::InsertInPackageList(\""
00072                      <<p->GetObjectName()<<"\" ["<<p<<"])"<<std::endl);
00073     boost::weak_ptr<Object> w(p);
00074     mgPackageList.insert(w); 
00075   }

void bbtk::Object::ReleasePackages (  )  [static]

Definition at line 213 of file bbtkObject.cxx.

References bbtkDebugMessage, bbtk::i, and mgPackageList.

00214   {
00215     bbtkDebugMessage("object",1,"##> Object::ReleasePackages()"<<std::endl);
00216     // Release package pointers
00217     ObjectListType::iterator i;
00218     for (i = mgPackageList.begin();
00219          i!= mgPackageList.end();
00220          ++i)
00221       {
00222         if (i->use_count() != 0) 
00223           { 
00224             bbtkDebugMessage("object",1,"##> Releasing package '"<<
00225                              i->lock()->GetThisPointer<Package>()->GetName()
00226                              <<"'"<<std::endl);
00227             //      Object::Pointer p(i->lock());
00228             Package::WeakPointer w(i->lock()->GetThisPointer<Package>());
00229             Package::Release(w);
00230             /*
00231             if (p->GetObjectName().find(name) != std::string::npos ) 
00232               {
00233                 std::cout << n << "/" << mgObjectList.size() << " ";
00234                 PrintObjectInfo(p);
00235                 m += p->GetObjectSize();
00236                 n++;
00237               }
00238             */
00239           }
00240       }  
00241 
00242   }

void bbtk::Object::PrintObjectListInfo ( const std::string &  name  )  [static]

Definition at line 105 of file bbtkObject.cxx.

References bbtk::i, mgObjectList, and PrintObjectInfo().

00106   {
00107     
00108     std::cout 
00109       << "=============== Living bbtk::Object pointers ========="<<std::endl;
00110 
00111     long n = 0;
00112     long u = 0;
00113     size_t m = 0;
00114     ObjectListType::iterator i;
00115     for (i = mgObjectList.begin();
00116          i!=mgObjectList.end();
00117          ++i)
00118       {
00119         if (i->use_count() == 0) 
00120           {
00121             u++;
00122           }
00123         else 
00124           { 
00125             Object::Pointer p(i->lock());
00126             if (p->GetObjectName().find(name) != std::string::npos ) 
00127               {
00128                 std::cout << n << "/" << mgObjectList.size() << " ";
00129                 PrintObjectInfo(p);
00130                 m += p->GetObjectSize();
00131                 n++;
00132               }
00133           }
00134       }
00135     std::cout 
00136       << "------------------------------------------------------"<<std::endl; 
00137 
00138     std::cout << " Total : "<<n<<" objects - "<<m<<" b"<<std::endl;
00139     if (u==1)
00140       {
00141         std::cout<<"* Note : "<<u
00142                  <<" object in list has 0 ref count, "
00143                  <<"i.e. destroyed without removing itself from the living objects list ! (this is just an implementation error not a memory leak)"<<std::endl;
00144       }
00145     else if (u>1)
00146       {
00147         std::cout<<"* Note : "<<u
00148                  <<" objects in list have 0 ref count, "
00149                  <<"i.e. destroyed without removing themselves from the living objects list ! (this is just an implementation error not a memory leak)"<<std::endl;
00150       }
00151     std::cout
00152       << "============ EO Living bbtk::Object pointers ========="<<std::endl;
00153         
00154   }

Here is the call graph for this function:

void bbtk::Object::PrintObjectInfo ( const Pointer &  o  )  [static]

Definition at line 180 of file bbtkObject.cxx.

Referenced by PrintObjectListInfo().

00181   {
00182     std::cout << "* [" << p << "] \t" 
00183               << p.use_count()-1 << " r \t"
00184               << p->GetObjectRecursiveSize() << " ("
00185               << p->GetObjectSize() << ") b \t"
00186               << p->GetObjectName() 
00187               << std::endl;
00188     std::cout << p->GetObjectInfo();
00189   }

Here is the caller graph for this function:

static long bbtk::Object::GetObjectsCount (  )  [inline, static]

Definition at line 75 of file bbtkObject.h.

00075 { return mgObjectList.size(); }

void bbtk::Object::LockThis (  )  [inline, protected]

Definition at line 88 of file bbtkObject.h.

00088 { mThisPointerLocked = mThisPointer.lock(); }   

void bbtk::Object::UnLockThis (  )  [inline, protected]

Definition at line 89 of file bbtkObject.h.

00089 { mThisPointerLocked = Pointer(); }

template<class U>
boost::shared_ptr<U> bbtk::Object::GetThisPointer (  )  const [inline, protected]

Definition at line 92 of file bbtkObject.h.

00093     {
00094       return boost::dynamic_pointer_cast<U>(mThisPointer.lock());
00095     }

template<class U>
static boost::shared_ptr<U> bbtk::Object::MakePointer ( U *  s,
bool  lock = false 
) [inline, static, protected]

Definition at line 97 of file bbtkObject.h.

Referenced by bbtk::Executer::Executer(), bbtk::Interpreter::Init(), bbtk::Transcriptor::New(), bbtk::Package::New(), bbtk::Interpreter::New(), bbtk::Factory::New(), and bbtk::Executer::New().

00098     {                                                                   
00099       if (s->mThisPointer.lock())                                       
00100         {                                                               
00101           boost::shared_ptr<U> p = s->GetThisPointer<U>();
00102           if (!lock) s->mThisPointerLocked.reset();
00103           return p;
00104         }                                                               
00105       boost::shared_ptr<U> p = boost::shared_ptr<U>(s,Object::Deleter());
00106       static_cast<Object::Deleter*>                                     
00107         (p._internal_get_deleter(typeid(Object::Deleter)))              
00108         ->mPointer = p;                                                 
00109       s->mThisPointer = p;                                              
00110       Object::InsertInObjectList(p);                                    
00111       if (lock) s->LockThis();                                          
00112       return p;                                                 
00113     }                                                                   

Here is the caller graph for this function:

template<class U, class D>
static boost::shared_ptr<U> bbtk::Object::MakePointer ( U *  s,
const D &  del,
bool  lock = false 
) [inline, static, protected]

Definition at line 115 of file bbtkObject.h.

00118     {                                                                   
00119       if (s->mThisPointer.lock())                                       
00120         {                                                               
00121           boost::shared_ptr<U> p = s->GetThisPointer<U>();
00122           if (!lock) s->mThisPointerLocked.reset();
00123           return p;
00124         }                                                               
00125       boost::shared_ptr<U> p = boost::shared_ptr<U>(s,del);
00126       static_cast<D*>                                   
00127         (p._internal_get_deleter(typeid(D)))            
00128         ->mPointer = p;                                                 
00129       s->mThisPointer = p;                                              
00130       Object::InsertInObjectList(p);                                    
00131       if (lock) s->LockThis();                                          
00132       return p;                                                 
00133     }                                                                   


Member Data Documentation

Object::ObjectListType bbtk::Object::mgObjectList [static, private]

Definition at line 138 of file bbtkObject.h.

Referenced by InsertInObjectList(), PrintObjectListInfo(), and RemoveFromObjectList().

Object::ObjectListType bbtk::Object::mgPackageList [static, private]

Definition at line 139 of file bbtkObject.h.

Referenced by InsertInPackageList(), and ReleasePackages().

WeakPointer bbtk::Object::mThisPointer [private]

Definition at line 140 of file bbtkObject.h.

Pointer bbtk::Object::mThisPointerLocked [private]

Definition at line 141 of file bbtkObject.h.


The documentation for this class was generated from the following files:

Generated on Wed Nov 12 11:38:49 2008 for BBTK by  doxygen 1.5.6