Definitions.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 Definitions internal header */
16 
17 #ifndef IH_SENF_Utils_Logger_Definitions_
18 #define IH_SENF_Utils_Logger_Definitions_ 1
19 
20 // Custom includes
21 
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
23 
24 // Implementation details concerning SENF_LOG_CLASS_AREA
25 //
26 // The SENF_LOG_CLASS_AREA statement shall declare the containing class as it's own default area. Of
27 // course, we cannot make the containing class into an area. Therefore we need to trick around a bit:
28 //
29 // We begin by defining an area SENFLogArea with in the class. This area however is hacked, so that
30 // it's name() member will return the name of the containing class (which is simple: just cut of the
31 // last couple of characters of the name since the name will always end in '::SENFLogArea').
32 //
33 // This however does not allow the use of the containing class as an area. There are several places
34 // which need to be adjusted to allow using the containing class as an area: The logging statements
35 // (SENF_LOG), the compile time configuration via SENF_LOG_CONF and the runtime configuration via
36 // route statements.
37 //
38 // Lets begin with the compile time configuration. The compile time configuration is done using
39 // specialization of the senf::log::detail::Config template. This doesn't care, what the area
40 // template argument really is. Therefore, compile-time configuration just uses the containing class
41 // as is. So we need to make sure, that the logging statements use the containing class when
42 // checking the compile-time limit whereas they need to use the nested SENFLogArea when calling the
43 // targets.
44 //
45 // So let's look at the logging statements. The central logic for parsing the logging parameters is
46 // in SENF_LOG_MERGE_PARAMETERS in Parameters.ih. Here we have a special case which detects classes
47 // with a SENFLogArea member and then set's things up correctly: It uses the containing class for
48 // compile time checking (this is, what 'area_base' typedef is for) while using the nested
49 // SENFLogArea for routing (this is, what the 'area' typedef is for).
50 //
51 // So the last thing which needs to be adjusted is the routing which is part of the Target
52 // class. Here for each template taking an area as an argument we really provide TWO templates, one
53 // taking the area directly, the other checking for a nested SENFLogArea member. We can
54 // differentiate these overloads using boost::enable_if and friends.
55 //
56 // This setup makes a class with SENF_LOG_CLASS_AREA() look like an ordinary area even though the
57 // implementation is somewhat different.
58 
59 #define SENF_LOG_DEFINE_AREA_I(area, decls) \
60  struct area \
61  : public senf::log::detail::AreaBase, public senf::singleton<area> \
62  { \
63  static std::string name() { return instance().v_name(); } \
64  using senf::singleton<area>::instance; \
65  decls \
66  private: \
67  area() { init(); } \
68  friend class senf::singleton<area>; \
69  }
70 
71 namespace senf {
72 namespace log {
73 namespace detail {
74 
75  /// Internal: Alias base class
76  struct AliasBase {};
77 
78 }}}
79 
80 //-/////////////////////////////////////////////////////////////////////////////////////////////////
81 #endif
82 
83 
84 // Local Variables:
85 // mode: c++
86 // fill-column: 100
87 // comment-column: 40
88 // c-file-style: "senf"
89 // indent-tabs-mode: nil
90 // ispell-local-dictionary: "american"
91 // compile-command: "scons -u test"
92 // End: