4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
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.
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.
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.
24 \brief PacketRegistry internal header */
26 #ifndef IH_PacketRegistryImpl_
27 #define IH_PacketRegistryImpl_ 1
30 #include <ext/functional>
31 #include <boost/intrusive_ptr.hpp>
32 #include <boost/iterator/transform_iterator.hpp>
33 #include "../Utils/TypeIdValue.hh"
35 ///////////////////////////////ih.p////////////////////////////////////////
39 /** \brief Registry entry
41 Value returned by a registry lookup
44 : public intrusive_refcount
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;
54 /** \brief Internal: Registry entry implementation for a specific packet type
58 template <class PacketType>
59 struct PkReg_EntryImpl
62 virtual Packet::factory_t factory() const;
63 virtual std::string name() const;
66 /** \brief Internal: Registry implementation base-class and registry of registries
70 class PacketRegistryImplBase
71 : private boost::noncopyable
74 virtual ~PacketRegistryImplBase();
76 static void dump(std::ostream & os);
79 typedef std::map<std::string, PacketRegistryImplBase*> RegistryMap;
80 static RegistryMap & registries();
83 virtual void v_dump(std::ostream & os) = 0;
86 /** \brief Internal: Singleton class implementing the packet registry.
90 template <class KeyType>
91 class PacketRegistryImpl
92 : public PacketRegistryImplBase
95 typedef KeyType key_t;
96 typedef PkReg_Entry Entry;
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;
104 ///////////////////////////////////////////////////////////////////////////
107 typedef boost::transform_iterator< __gnu_cxx::select1st<typename PacketMap::value_type>,
108 typename PacketMap::const_iterator > iterator;
110 ///////////////////////////////////////////////////////////////////////////
111 ///\name Structors and default members
114 PacketRegistryImpl(std::string const & name);
117 ///////////////////////////////////////////////////////////////////////////
119 template <class PacketType>
120 void registerPacket(key_t key);
122 key_t key(senf::TypeIdValue const & type);
123 boost::optional<key_t> key(senf::TypeIdValue const & type, bool);
125 Entry const & lookup(key_t key);
126 Entry const * lookup(key_t key, bool);
128 iterator begin() const;
129 iterator end() const;
134 virtual void v_dump(std::ostream & os);
137 ReversePacketMap reverseRegistry_;
142 ///////////////////////////////ih.e////////////////////////////////////////
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