3 ==============================================================================
5 This file is part of the S.F.Tracker
6 Copyright 2005-7 by Satoshi Fujiwara.
8 S.F.Tracker can be redistributed and/or modified under the terms of the
9 GNU General Public License, as published by the Free Software Foundation;
10 either version 2 of the License, or (at your option) any later version.
12 S.F.Tracker is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with S.F.Tracker; if not, visit www.gnu.org/licenses or write to the
19 Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 Boston, MA 02111-1307 USA
22 ==============================================================================
26 * @author S.F. (Satoshi Fujiwara)
28 #include <boost/thread.hpp>
29 #include <boost/shared_ptr.hpp>
31 template<typename BaseClass,template <class> class PointerType = boost::shared_ptr > struct singleton
33 typedef PointerType<BaseClass> ptr;
36 static ptr& instance()
38 boost::call_once(init,flag_);
45 singleton(const singleton& );
46 static void init(){instance_.reset(new BaseClass);};
47 static PointerType<BaseClass> instance_;
48 static boost::once_flag flag_;
51 template<class BaseClass,template <class> class PointerType> boost::once_flag singleton<BaseClass,PointerType>::flag_ = BOOST_ONCE_INIT;
52 template<class BaseClass,template <class> class PointerType> PointerType<BaseClass> singleton<BaseClass,PointerType>::instance_;