2 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
3 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
4 // Stefan Bund <g0dil@berlios.de>
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the
18 // Free Software Foundation, Inc.,
19 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 \brief singleton public header */
25 #define HH_singleton_ 1
28 #include <boost/utility.hpp>
30 //#include "singleton.mpp"
31 ///////////////////////////////hh.p////////////////////////////////////////
35 /** \brief Mark a class as singleton and provide singleton accessor
37 This mixin class will mark a class as singleton and provide an accessor function to access
38 this singleton instance. The following preconditions must be met for this class to work as
40 \li There must be only a single thread executing before main() starts. (This should always
42 \li The singleton class must have a default constructor
44 If these conditions are met, this mixin will ensure that the singleton is constructed \e
45 before main even starts executing. If static construction code calls the instance() member,
46 it is ensured, that a valid instance is returned.
51 : public senf::singleton<SomeClass>
54 SomeClass(); // Must have default constructor
59 int main(int argc, char ** argv)
61 // At this point, the instance has already been constructed
63 SomeClass::instance().doSomething();
67 \note This implementation is directly taken from
68 <tt>boost/pool/detail/singleton.hpp</tt>. See that file for a description of the
69 technique. The only difference is, that I prefer to advertise this class as a mixin
70 (though it may be used the same way as the original too).
77 static Self & instance(); ///< Return singleton instance
89 static force_creation creator_;
94 ///////////////////////////////hh.e////////////////////////////////////////
95 //#include "singleton.cci"
96 //#include "singleton.ct"
97 //#include "singleton.cti"
104 // c-file-style: "senf"
105 // indent-tabs-mode: nil
106 // ispell-local-dictionary: "american"
107 // compile-command: "scons -u test"
108 // comment-column: 40