GenericTLV.hh
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 
17 #ifndef HH_SENF_Packets_GenericTLV_
18 #define HH_SENF_Packets_GenericTLV_ 1
19 
20 // Custom includes
21 #include <boost/ptr_container/ptr_map.hpp>
23 #include <senf/Utils/singleton.hh>
24 #include "Packets.hh"
25 
26 #include "GenericTLV.ih"
27 //-/////////////////////////////////////////////////////////////////////////////////////////////////
28 
29 namespace senf {
30 
123  template <class Base>
125  : private detail::GenericTLVParserBaseTag,
126  public Base
127  {
128  public:
130  : Base(i,s) {}
131 
133 
135  void init() const;
136 
137  template <class Parser>
138  Parser init();
139 
140  template <class Parser>
141  Parser as() const;
142 
143  template <class Parser>
144  bool is() const;
145 
147 
148  void dump(std::ostream & os) const;
149 
150 #ifndef DOXYGEN
151  template<class ForwardReadableRange>
152  void value(ForwardReadableRange const & val,
153  typename boost::disable_if<senf::is_pair<ForwardReadableRange> >::type * = 0);
154 
155  template<class First, class Second>
156  void value(std::pair<First, Second> const & val,
157  typename boost::disable_if<boost::is_convertible<First, typename Base::type_t::value_type> >::type * = 0);
158 
159  template <class Type, class ForwardReadableRange>
160  void value(std::pair<Type, ForwardReadableRange> const & val,
161  typename boost::enable_if<boost::is_convertible<Type, typename Base::type_t::value_type> >::type * = 0);
162 #else
163  template<class ForwardReadableRange>
164  void value(ForwardReadableRange const & val);
165 
166  template <class ForwardReadableRange>
167  void value(std::pair<typename Base::type_t::value_type, ForwardReadableRange> const & val);
168 #endif
169 
170  private:
171  template<class ForwardReadableRange>
172  void value_(ForwardReadableRange const &range);
173 
174  Base & self();
175  Base const & self() const;
176  };
177 
178 
226  template <class BaseParser, class Keytype = typename BaseParser::type_t::value_type>
228  : public singleton<GenericTLVParserRegistry<BaseParser,Keytype> >
229  {
231 
232  typedef boost::ptr_map<Keytype,
233  detail::GenericTLVParserRegistry_EntryBase<BaseParser> > Map;
234  Map map_;
235 
236  public:
238  friend class singleton<GenericTLVParserRegistry<BaseParser,Keytype> >;
239 
240  template <class PacketParser>
243  };
244 
245  template <typename Parser>
246  void registerParser();
247 
249 
250  bool isRegistered(GenericTLVParserBase<BaseParser> const & parser) const;
251  bool isRegistered(Keytype const & key) const;
252 
253  void dump(GenericTLVParser const & parser, std::ostream & os) const;
254  void dump(GenericTLVParser const & parser, Keytype const & key, std::ostream & os) const;
255 
256  PacketParserBase::size_type bytes(GenericTLVParser const & parser) const;
257  PacketParserBase::size_type bytes(GenericTLVParser const & parser, Keytype const & key) const;
258 
260  const_iterator begin() const;
261  const_iterator end() const;
262  };
263 
265  {
266  TLVParserNotRegisteredException() : senf::Exception("tlv parser not registered") {}
267  };
268 
269 
270  template <class ListPolicy>
272  : public ListParser<ListPolicy>
273  {
274  public:
277 
278  template <typename TLVParser>
279  bool contains() const;
280  bool contains(typename ListPolicy::element_type::type_t::value_type typeId) const;
281 
282  template <typename TLVParser>
283  TLVParser find() const;
284  };
285 
286 
295 # define SENF_PACKET_TLV_REGISTRY_REGISTER( ConreteTLVParser ) \
296  namespace { \
297  ConreteTLVParser::Registry::RegistrationProxy<ConreteTLVParser> \
298  BOOST_PP_CAT(tlvparserRegistration_, __LINE__); \
299  }
300 
301 # define SENF_PARSER_TLV_LIST SENF_PARSER_LIST
302 }
303 
304 //-/////////////////////////////////////////////////////////////////////////////////////////////////
305 //#include "GenericTLV.cci"
306 #include "GenericTLV.ct"
307 #include "GenericTLV.cti"
308 #endif
309 
310 
311 // Local Variables:
312 // mode: c++
313 // fill-column: 100
314 // comment-column: 40
315 // c-file-style: "senf"
316 // indent-tabs-mode: nil
317 // ispell-local-dictionary: "american"
318 // compile-command: "scons -u test"
319 // End:
TLV parser registration facility.
Definition: GenericTLV.hh:227
Packets public header.
Return number of bytes to allocate to new object of given type.
bool contains(InputIterator first, InputIterator last, ValueType const &value)
void dump(std::ostream &os) const
Base class for generic TLV parsers.
Definition: GenericTLV.hh:124
raw_container::const_iterator const_iterator
Definition: PacketTypes.hh:70
GenericTLVParserBase< BaseParser > GenericTLVParser
Definition: GenericTLV.hh:248
Map::const_iterator const_iterator
Definition: GenericTLV.hh:259
Packet data STL-sequence view.
Definition: PacketData.hh:61
detail::packet::size_type size_type
Unsigned integral type.
PacketInterpreterBase::range value() const
boost::iterator_range< iterator > range
Arbitrary sequential element collection.
Definition: ListParser.hh:65
ListPolicy policy
Definition: ListParser.hh:70
detail::packet::iterator data_iterator
Raw data iterator type.
GenericTLVParserBase(PacketParserBase::data_iterator i, PacketParserBase::state_type s)
Definition: GenericTLV.hh:129
PacketParserBase::size_type bytes() const