Fix SCons 1.2.0 build failure
[senf.git] / Packets / PacketRegistry.ih
1 // $Id$
2 //
3 // Copyright (C) 2006
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 PacketRegistry internal header */
25
26 #ifndef IH_SENF_Packets_PacketRegistry_
27 #define IH_SENF_Packets_PacketRegistry_ 1
28
29 // Custom includes
30 #include <ext/functional>
31 #include <boost/intrusive_ptr.hpp>
32 #include <boost/iterator/transform_iterator.hpp>
33 #include "../Utils/TypeIdValue.hh"
34
35 ///////////////////////////////ih.p////////////////////////////////////////
36
37 namespace senf {
38
39     /** \brief Registry entry
40
41         Value returned by a registry lookup
42      */
43     struct PkReg_Entry
44         : public intrusive_refcount
45     {
46         virtual ~PkReg_Entry();
47         virtual Packet::factory_t factory() const = 0;
48                                         ///< Get factory of the registered packet type
49         virtual std::string name() const = 0;
50     };
51
52 namespace detail {
53
54     /** \brief Internal: Registry entry implementation for a specific packet type
55
56         \internal
57      */
58     template <class PacketType>
59     struct PkReg_EntryImpl
60         : public PkReg_Entry
61     {
62         virtual Packet::factory_t factory() const;
63         virtual std::string name() const;
64     };
65
66     /** \brief Internal: Registry implementation base-class and registry of registries
67
68         \internal
69      */
70     class PacketRegistryImplBase
71         : private boost::noncopyable
72     {
73     public:
74         virtual ~PacketRegistryImplBase();
75
76         static void dump(std::ostream & os);
77
78     protected:
79         typedef std::map<std::string, PacketRegistryImplBase*>  RegistryMap;
80         static RegistryMap & registries();
81
82     private:
83         virtual void v_dump(std::ostream & os) = 0;
84     };
85
86     /** \brief Internal: Singleton class implementing the packet registry.
87
88         \internal
89      */
90     template <class KeyType>
91     class PacketRegistryImpl
92         : public PacketRegistryImplBase
93     {
94     public:
95         typedef KeyType key_t;
96         typedef PkReg_Entry Entry;
97
98     private:
99         typedef boost::intrusive_ptr<Entry> Entry_ptr;
100         typedef std::map<key_t, Entry_ptr> PacketMap;
101         typedef std::map<senf::TypeIdValue, key_t> ReversePacketMap;
102
103     public:
104         ///////////////////////////////////////////////////////////////////////////
105         // Types
106
107         typedef boost::transform_iterator< ::__gnu_cxx::select1st<typename PacketMap::value_type>,
108                                            typename PacketMap::const_iterator > iterator;
109
110         ///////////////////////////////////////////////////////////////////////////
111         ///\name Structors and default members
112         ///@{
113
114         PacketRegistryImpl(std::string const & name);
115
116         ///@}
117         ///////////////////////////////////////////////////////////////////////////
118
119         template <class PacketType>
120         void registerPacket(key_t key);
121
122         key_t key(senf::TypeIdValue const & type);
123         boost::optional<key_t> key(senf::TypeIdValue const & type, bool);
124
125         Entry const & lookup(key_t key);
126         Entry const * lookup(key_t key, bool);
127
128         iterator begin() const;
129         iterator end() const;
130
131     protected:
132
133     private:
134         virtual void v_dump(std::ostream & os);
135
136         PacketMap registry_;
137         ReversePacketMap reverseRegistry_;
138     };
139
140 }}
141
142 ///////////////////////////////ih.e////////////////////////////////////////
143 #endif
144
145 \f
146 // Local Variables:
147 // mode: c++
148 // fill-column: 100
149 // c-file-style: "senf"
150 // indent-tabs-mode: nil
151 // ispell-local-dictionary: "american"
152 // compile-command: "scons -u test"
153 // comment-column: 40
154 // End: