Referenced.h
Go to the documentation of this file.
00001 
00005 #ifndef OPENHRP_UTIL_REFERENCED_H_INCLUDED
00006 #define OPENHRP_UTIL_REFERENCED_H_INCLUDED
00007 
00008 #include <boost/intrusive_ptr.hpp>
00009 
00010 namespace hrp {
00011     class Referenced;
00012     void intrusive_ptr_add_ref(Referenced* obj);
00013     void intrusive_ptr_release(Referenced* obj);
00014     
00015     class Referenced
00016     {
00017       public:
00018         Referenced() { refCounter_ = 0; }
00019         virtual ~Referenced() { }
00020 
00021     protected:
00022         int refCounter() { return refCounter_; }
00023 
00024       private:
00025         friend void intrusive_ptr_add_ref(Referenced* obj);
00026         friend void intrusive_ptr_release(Referenced* obj);
00027 
00028         int refCounter_;
00029     };
00030 
00031     inline void intrusive_ptr_add_ref(hrp::Referenced* obj){
00032         obj->refCounter_++;
00033     }
00034 
00035     inline void intrusive_ptr_release(hrp::Referenced* obj){
00036         obj->refCounter_--;
00037         if(obj->refCounter_ == 0){
00038             delete obj;
00039         }
00040     }
00041 };
00042 
00043 #endif


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sun Apr 2 2017 03:43:56