inlib  1.2.0
/Users/barrand/private/dev/softinex/old/inexlib-1.2/inlib/inlib/sg/holder
Go to the documentation of this file.
00001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
00002 // See the file inlib.license for terms.
00003 
00004 #ifndef inlib_sg_holder
00005 #define inlib_sg_holder
00006 
00007 // class to manage an object.
00008 // Only one holder owns the object. In case
00009 // of holder copy(), the new holder receives a null object.
00010 
00011 #include "node"
00012 
00013 namespace inlib {
00014 namespace sg {
00015 
00016 template <class T>
00017 class holder : public node {
00018 public:
00019   static const std::string& s_class() {
00020     static const std::string s_v("inlib::sg::holder");
00021     return s_v;
00022   }
00023 public:
00024   virtual void* cast(const std::string& a_class) const {
00025     if(void* p = inlib::cmp_cast< holder<T> >(this,a_class)) {return p;}
00026     return node::cast(a_class);
00027   }
00028   virtual node* copy() const {return new holder(*this);}
00029   virtual const std::string& s_cls() const {return s_class();}
00030 public:  
00031   holder(T* a_obj):m_obj(a_obj){} //it takes a_obj ownership.
00032   virtual ~holder(){delete m_obj;}
00033 public:
00034   holder(const holder& a_from):node(a_from),m_obj(0){}
00035   holder& operator=(const holder& a_from){
00036     node::operator=(a_from);
00037     m_obj=0;
00038     return *this;
00039   }
00040 protected:
00041   T* m_obj;
00042 };
00043 
00044 }}
00045 
00046 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines