MIHMessageRegistry.ih
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 MIH Message-Registry internal header */
16 
17 #ifndef IH_SENF_Packets_80221Bundle_MIHMessageRegistry_
18 #define IH_SENF_Packets_80221Bundle_MIHMessageRegistry_ 1
19 
20 // Custom includes
21 
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
23 namespace senf {
24 
25  namespace detail {
26 
27  template<class T, typename Signature>
28  struct has_static_validate_member
29  {
30  template<Signature *>
31  struct helper;
32 
33  template<class U>
34  static char test(helper<&U::validate> *);
35 
36  template<class U>
37  static char (&test(...))[2];
38 
39  static const bool value = sizeof(test<T>(0))==1;
40  };
41 
42 
43  struct MIHMessageRegistry_EntryBase
44  : private boost::noncopyable
45  {
46  virtual ~MIHMessageRegistry_EntryBase() {}
47  virtual void validate(senf::Packet message) const = 0;
48  virtual std::string name() const = 0;
49  };
50 
51 
52  template <class MIHPacket,
53  bool use_validate_member = has_static_validate_member<typename MIHPacket::type, void(MIHPacket)>::value>
54  struct MIHMessageRegistryEntry : MIHMessageRegistry_EntryBase
55  {
56  virtual void validate(senf::Packet message) const {}
57  virtual std::string name() const {
58  return senf::prettyName(typeid(MIHPacket));
59  }
60  };
61 
62  template <class MIHPacket>
63  struct MIHMessageRegistryEntry<MIHPacket, true> : MIHMessageRegistry_EntryBase
64  {
65  virtual void validate(senf::Packet message) const;
66  virtual std::string name() const {
67  return senf::prettyName(typeid(MIHPacket));
68  }
69  };
70 
71  }
72 }
73 //-/////////////////////////////////////////////////////////////////////////////////////////////////
74 #endif
75 
76 
77 
78 // Local Variables:
79 // mode: c++
80 // fill-column: 100
81 // c-file-style: "senf"
82 // indent-tabs-mode: nil
83 // ispell-local-dictionary: "american"
84 // compile-command: "scons -u test"
85 // comment-column: 40
86 // End: