assemblage.hpp
Go to the documentation of this file.
00001 /* 00002 Copyright 2005-2007 Adobe Systems Incorporated 00003 Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt 00004 or a copy at http://stlab.adobe.com/licenses.html) 00005 */ 00006 00007 /*************************************************************************************************/ 00008 00009 #ifndef ADOBE_ASSEMBLAGE_HPP 00010 #define ADOBE_ASSEMBLAGE_HPP 00011 00012 #include <adobe/config.hpp> 00013 00014 #include <list> 00015 00016 #include <boost/bind/apply.hpp> 00017 #include <boost/function.hpp> 00018 #include <boost/signals/connection.hpp> 00019 00020 #include <adobe/algorithm/for_each.hpp> 00021 #include <adobe/memory.hpp> 00022 00023 /*************************************************************************************************/ 00024 00025 namespace adobe { 00026 00027 /*************************************************************************************************/ 00028 00029 class assemblage_t 00030 { 00031 public: 00032 ~assemblage_t() 00033 { 00034 // disconnect all our connections 00035 adobe::for_each(cleanup_m, boost::bind(boost::apply<void>(), _1)); 00036 } 00037 00038 void cleanup(boost::function<void()> f) 00039 { 00040 cleanup_m.push_front(f); 00041 } 00042 00043 private: 00044 std::list<boost::function<void ()> > cleanup_m; 00045 }; 00046 00047 /****************************************************************************************************/ 00048 00049 template <typename T> 00050 inline void assemblage_cleanup_ptr(assemblage_t& assemblage, T* x) 00051 { assemblage.cleanup(boost::bind(delete_ptr(), x)); } 00052 00053 /****************************************************************************************************/ 00054 00055 inline void assemblage_cleanup_connection(assemblage_t& assemblage, boost::signals::connection& x) 00056 { assemblage.cleanup(boost::bind(&boost::signals::connection::disconnect, x)); } 00057 00058 /*************************************************************************************************/ 00059 00060 } // namespace adobe 00061 00062 /*************************************************************************************************/ 00063 00064 #endif 00065 00066 /*************************************************************************************************/ |