Fix documentation build under maverick (doxygen 1.7.1)
[senf.git] / senf / Utils / pool_alloc_mixin.hh
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief pool_alloc_mixin public header */
25
26 #ifndef HH_SENF_Utils_pool_alloc_mixin_
27 #define HH_SENF_Utils_pool_alloc_mixin_ 1
28
29 // Custom includes
30 #include <boost/pool/singleton_pool.hpp>
31
32 //#include "pool_alloc_mixin.mpp"
33 //-/////////////////////////////////////////////////////////////////////////////////////////////////
34
35 namespace senf {
36
37     struct pool_alloc_mixin_tag;
38
39     /** \brief Mixin to assign pool allocator to a class
40
41         This mixin will overload a classes <tt>operator new</tt> and <tt>operator delete</tt> so as
42         to make the class use the <a
43         href="http://www.boost.org/doc/libs/release/libs/pool/doc/index.html">Boost.Pool</a> memory allocator by
44         default. Using this allocator does however introduce a few restrictions:
45
46         \li The operator is defined for a fixed size. Therefore if you derive from the class <b>you
47             must not change it's size</b>.
48         \li If you change the size of the class in a derived class you have to derive from
49             pool_alloc_mixin again.
50
51         Usage:
52         \code
53           class SomeClass
54               : public senf::pool_alloc_mixin<SomeClass>
55           {
56               // ...
57           };
58         \endcode
59
60         \note pool_alloc_mixin uses the <a
61             href="http://www.boost.org/doc/libs/release/libs/pool/doc/index.html">Boost.Pool</a> <i>singleton
62             pool</i> interface with the tag <tt>pool_alloc_mixin_tag</tt>. This class is accessible
63             via the <tt>pool</tt> member. Using this member, it is simple to call relevant pool
64             functions, e.g. <tt>SomeClass::pool<>::release_memory()</tt>.
65      */
66     template <class Self>
67     class pool_alloc_mixin
68     {
69     public:
70         /** \brief Templated typedef for the pool used
71
72             Since the instantiation of the typedef must be delayed until Self is completely defined,
73             the simple typedef is replaced with a nested struct.
74          */
75         template <class T=void>
76         struct pool
77             : public boost::singleton_pool< pool_alloc_mixin_tag, sizeof(Self) >
78         {
79             typedef boost::singleton_pool< pool_alloc_mixin_tag, sizeof(Self) > type;
80         };
81
82         static void * operator new (size_t size);
83                                         ///< Operator new utilizing pool allocation
84         static void operator delete (void *p, size_t size);
85                                         ///< Operator delete utilizing pool allocation
86
87 #ifdef SENF_DEBUG
88         static unsigned long allocCounter();
89     private:
90         static unsigned long allocCounter(long delta);
91 #endif
92     };
93
94 }
95
96 //-/////////////////////////////////////////////////////////////////////////////////////////////////
97 //#include "pool_alloc_mixin.cci"
98 //#include "pool_alloc_mixin.ct"
99 #include "pool_alloc_mixin.cti"
100 #endif
101
102 \f
103 // Local Variables:
104 // mode: c++
105 // fill-column: 100
106 // c-file-style: "senf"
107 // indent-tabs-mode: nil
108 // ispell-local-dictionary: "american"
109 // compile-command: "scons -u test"
110 // comment-column: 40
111 // End: