#ifndef DIGEDAG_UTIL_SHAREDPTR_BOOST_HPP #define DIGEDAG_UTIL_SHAREDPTR_BOOST_HPP #include #ifndef USE_BOOST # error "Oops - USE_BOOST undefined for boost version of shared_ptr" #endif #include #include namespace digedag { namespace util { template class enable_shared_from_this; // simply use boost's shared ptr implementation template class shared_ptr : public boost::shared_ptr { private: std::string id_; public: std::string get_id (void) const { return id_; } shared_ptr (std::string id = "???") : boost::shared_ptr () , id_ (id) { std::cout << " ### creating (1) shared_ptr for " << id_ << std::endl; } shared_ptr (T * t, std::string id = "???") : boost::shared_ptr (t) , id_ (id) { std::cout << " ### creating (2) shared_ptr for " << id_ << std::endl; } shared_ptr (boost::shared_ptr & p) : boost::shared_ptr (p) , id_ (p.get_id ()) { std::cout << " ### creating (3) shared_ptr for " << id_ << std::endl; } shared_ptr (const boost::shared_ptr & p) : boost::shared_ptr (p) , id_ (p.get_id ()) { std::cout << " ### creating (4) shared_ptr for " << id_ << std::endl; } shared_ptr (boost::shared_ptr & p) : boost::shared_ptr (p) , id_ ("ctor 5") { std::cout << " ### creating (5) shared_ptr for " << id_ << std::endl; } shared_ptr (const boost::shared_ptr & p) : boost::shared_ptr (p) , id_ ("ctor 6") { std::cout << " ### creating (6) shared_ptr for " << id_ << std::endl; } ~shared_ptr (void) { std::cout << " ### deleting shared_ptr for " << id_ << std::endl; } public: template friend bool operator! (const boost::shared_ptr & p); template friend class util::enable_shared_from_this; }; template bool operator! (const boost::shared_ptr & p) { return ( p.get () ); } template class enable_shared_from_this : public boost::enable_shared_from_this { public: enable_shared_from_this (void) : boost::enable_shared_from_this () { } boost::shared_ptr shared_from_this () { return boost::shared_ptr (boost::enable_shared_from_this ::shared_from_this ()); } }; } // namespace util } // namespace digedag #endif // DIGEDAG_UTIL_SHAREDPTR_BOOST_HPP