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_SENF_Packets_PacketRegistry_
27 #define IH_SENF_Packets_PacketRegistry_ 1
30 #include <ext/functional>
32 #include <boost/intrusive_ptr.hpp>
33 #include <boost/iterator/transform_iterator.hpp>
34 #include <senf/Utils/TypeIdValue.hh>
36 ///////////////////////////////ih.p////////////////////////////////////////
40 /** \brief Registry entry
42 Value returned by a registry lookup
45 : public intrusive_refcount
47 virtual ~PkReg_Entry();
48 virtual Packet::factory_t factory() const = 0;
49 ///< Get factory of the registered packet type
50 virtual std::string name() const = 0;
51 virtual TypeIdValue typeIdValue() const = 0;
56 /** \brief Internal: Registry entry implementation for a specific packet type
60 template <class PacketType>
61 struct PkReg_EntryImpl
64 virtual Packet::factory_t factory() const;
65 virtual std::string name() const;
66 virtual TypeIdValue typeIdValue() const ;
69 /** \brief Internal: Registry implementation base-class and registry of registries
73 class PacketRegistryImplBase
74 : private boost::noncopyable
77 virtual ~PacketRegistryImplBase();
79 static void dump(std::ostream & os);
83 typedef std::map<std::string, PacketRegistryImplBase*> RegistryMap;
84 static RegistryMap & registries();
87 virtual bool v_empty() const = 0;
88 virtual void v_dump(std::ostream & os) const = 0;
89 virtual void v_clear() = 0;
92 /** \brief Internal: Singleton class implementing the packet registry.
96 template <class KeyType>
97 class PacketRegistryImpl
98 : public PacketRegistryImplBase
101 typedef KeyType key_t;
102 typedef PkReg_Entry Entry;
105 typedef boost::intrusive_ptr<Entry> Entry_ptr;
106 typedef std::map<key_t, Entry_ptr> PacketMap;
107 typedef std::map<senf::TypeIdValue, key_t> ReversePacketMap;
110 ///////////////////////////////////////////////////////////////////////////
113 typedef boost::transform_iterator< ::__gnu_cxx::select1st<typename PacketMap::value_type>,
114 typename PacketMap::const_iterator > iterator;
116 ///////////////////////////////////////////////////////////////////////////
117 ///\name Structors and default members
120 PacketRegistryImpl(std::string const & name);
123 ///////////////////////////////////////////////////////////////////////////
125 template <class PacketType>
126 void registerPacket(key_t key);
128 template <class PacketType>
129 void unregisterPacket();
130 void unregisterPacket(key_t key);
132 key_t key(senf::TypeIdValue const & type);
133 boost::optional<key_t> key(senf::TypeIdValue const & type, bool);
135 Entry const & lookup(key_t key);
136 Entry const * lookup(key_t key, bool);
138 iterator begin() const;
139 iterator end() const;
144 virtual bool v_empty() const;
145 virtual void v_dump(std::ostream & os) const;
146 virtual void v_clear();
149 ReversePacketMap reverseRegistry_;
152 template <class KeyType, bool is_integral=std::numeric_limits<KeyType>::is_integer>
155 static void dump(KeyType const & v, std::ostream & os);
158 template <class KeyType>
159 struct DumpKey<KeyType, true>
161 static void dump(KeyType const & v, std::ostream & os);
166 ///////////////////////////////ih.e////////////////////////////////////////
173 // c-file-style: "senf"
174 // indent-tabs-mode: nil
175 // ispell-local-dictionary: "american"
176 // compile-command: "scons -u test"
177 // comment-column: 40