PacketRegistry.cti
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
14 /** \file
15  \brief PacketRegistry inline template implementation */
16 
17 #include "PacketRegistry.ih"
18 
19 // Custom includes
20 
21 #define prefix_ inline
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
23 
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 // senf::PacketRegistry<Tag>::ScopedRegistrationProxy<PacketType>
26 
27 template <class Tag>
28 template <class PacketType>
29 prefix_ senf::PacketRegistry<Tag>::ScopedRegistrationProxy<PacketType>::
30 ScopedRegistrationProxy(typename Tag::key_t key, int priority)
31 {
32  PacketRegistry<Tag>::template registerPacket<PacketType>(key,priority);
33 }
34 
35 template <class Tag>
36 template <class PacketType>
37 prefix_ senf::PacketRegistry<Tag>::ScopedRegistrationProxy<PacketType>::~ScopedRegistrationProxy()
38 {
39  try {
40  PacketRegistry<Tag>::template unregisterPacket<PacketType>();
41  }
42  catch (PacketTypeNotRegisteredException & ex)
43  {}
44 }
45 
46 //-/////////////////////////////////////////////////////////////////////////////////////////////////
47 // senf::PacketRegistry<Tag>
48 
49 template <class Tag>
50 template <class PacketType>
51 prefix_ void senf::PacketRegistry<Tag>::registerPacket(typename Tag::key_t key, int priority)
52 {
53  registry().template registerPacket<PacketType>(key, priority);
54 }
55 
56 template <class Tag>
57 template <class PacketType>
58 prefix_ void senf::PacketRegistry<Tag>::unregisterPacket()
59 {
60  if (alive())
61  registry().template unregisterPacket<PacketType>();
62 }
63 
64 template <class Tag>
65 prefix_ void senf::PacketRegistry<Tag>::unregisterPacket(typename Tag::key_t key, int priority)
66 {
67  if (alive())
68  registry().unregisterPacket(key, priority);
69 }
70 
71 template <class Tag>
72 template <class PacketType>
73 prefix_ typename Tag::key_t senf::PacketRegistry<Tag>::key()
74 {
75  return registry().key(senf::typeIdValue<PacketType>());
76 }
77 
78 template <class Tag>
79 template <class PacketType>
80 prefix_ typename boost::optional<typename Tag::key_t> senf::PacketRegistry<Tag>::key(NoThrow_t)
81 {
82  return registry().key(senf::typeIdValue<PacketType>(),true);
83 }
84 
85 template <class Tag>
86 prefix_ typename Tag::key_t senf::PacketRegistry<Tag>::key(Packet const & packet)
87 {
88  return registry().key(packet.typeId());
89 }
90 
91 template <class Tag>
92 prefix_ typename boost::optional<typename Tag::key_t>
93 senf::PacketRegistry<Tag>::key(Packet const & packet, NoThrow_t)
94 {
95  return registry().key(packet.typeId(),true);
96 }
97 
98 template <class Tag>
99 prefix_ typename senf::PacketRegistry<Tag>::Entry const &
100 senf::PacketRegistry<Tag>::lookup(typename Tag::key_t key)
101 {
102  return registry().lookup(key);
103 }
104 
105 template <class Tag>
106 prefix_ typename senf::PacketRegistry<Tag>::Entry const *
107 senf::PacketRegistry<Tag>::lookup(typename Tag::key_t key, NoThrow_t)
108 {
109  return registry().lookup(key,true);
110 }
111 
112 template <class Tag>
113 prefix_ typename senf::PacketRegistry<Tag>::iterator senf::PacketRegistry<Tag>::begin()
114 {
115  return registry().begin();
116 }
117 
118 template <class Tag>
119 prefix_ typename senf::PacketRegistry<Tag>::iterator senf::PacketRegistry<Tag>::end()
120 {
121  return registry().end();
122 }
123 
124 template <class Tag>
125 prefix_ senf::PacketRegistry<Tag>::PacketRegistry()
126  : registry_ (prettyName(typeid(Tag)))
127 {}
128 
129 template <class Tag>
130 prefix_ typename senf::PacketRegistry<Tag>::Registry &
131 senf::PacketRegistry<Tag>::registry()
132 {
133  return instance().registry_;
134 }
135 
136 //-/////////////////////////////////////////////////////////////////////////////////////////////////
137 // senf::detail::PacketRegistryImpl<KeyType>
138 
139 template <class KeyType>
140 prefix_ senf::detail::PacketRegistryImpl<KeyType>::PacketRegistryImpl(std::string const & name)
141  : registryByKey_( registry_.template get<ByKey>()),
142  registryByType_( registry_.template get<ByType>())
143 {
144  registries()[name] = this;
145 }
146 
147 template <class KeyType>
148 prefix_ typename senf::detail::PacketRegistryImpl<KeyType>::iterator
149 senf::detail::PacketRegistryImpl<KeyType>::begin()
150  const
151 {
152  return registry_.begin();
153 }
154 
155 template <class KeyType>
156 prefix_ typename senf::detail::PacketRegistryImpl<KeyType>::iterator
157 senf::detail::PacketRegistryImpl<KeyType>::end()
158  const
159 {
160  return registry_.end();
161 }
162 
163 //-/////////////////////////////////////////////////////////////////////////////////////////////////
164 #undef prefix_
165 
166 
167 // Local Variables:
168 // mode: c++
169 // fill-column: 100
170 // c-file-style: "senf"
171 // indent-tabs-mode: nil
172 // ispell-local-dictionary: "american"
173 // compile-command: "scons -u test"
174 // comment-column: 40
175 // End: