Utils/Logger: Fix SENF_LOG_CONF to support top-level areas and streams
[senf.git] / Utils / Logger / Config.ih
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
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.
12 //
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.
17 //
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.
22
23 /** \file
24     \brief Config internal header */
25
26 #ifndef IH_Config_
27 #define IH_Config_ 1
28
29 // Custom includes
30 #include <boost/preprocessor/expand.hpp>
31 #include <boost/preprocessor/seq/for_each.hpp>
32 #include <boost/preprocessor/seq/to_tuple.hpp>
33 #include <boost/preprocessor/seq/fold_right.hpp>
34 #include <boost/preprocessor/seq/pop_back.hpp>
35 #include <boost/preprocessor/if.hpp>
36 #include "../preprocessor.hh"
37
38 ///////////////////////////////ih.p////////////////////////////////////////
39
40 namespace senf {
41 namespace log {
42 namespace detail {
43
44     struct na {};
45
46     /// Internal: Compile time configuration for given \a Stream and \a Area
47     template <class Stream, class Area>
48     struct Config
49     {
50         typedef typename Config<Stream,na>::compileLimit compileLimit;
51     };
52
53 #   ifndef DOXYGEN
54
55     template <class Stream>
56     struct Config<Stream, na>
57     {
58         typedef typename Stream::compileLimit compileLimit;
59     };
60
61 #   endif
62
63 }}}
64
65 #define SENF_LOG_SEQ_TO_NAME_(s,state,elem) state::elem
66
67 #define SENF_LOG_SEQ_TO_NAME(seq)                                                                 \
68     BOOST_PP_SEQ_FOLD_LEFT(SENF_LOG_SEQ_TO_NAME_, , seq)
69
70 #define SENF_LOG_PREDECL_(s, state, elem)                                                         \
71     namespace elem { state }
72
73 #define SENF_LOG_PREDECL_long(seq)                                                                \
74     BOOST_PP_SEQ_FOLD_RIGHT( SENF_LOG_PREDECL_,                                                   \
75                              class SENF_PP_SEQ_BACK(seq);,                                        \
76                              BOOST_PP_SEQ_POP_BACK(seq) )
77
78 #define SENF_LOG_PREDECL_short(seq)                                                               \
79         class SENF_PP_SEQ_BACK(seq);
80
81 #define SENF_LOG_PREDECL(seq)                                                                     \
82     BOOST_PP_CAT(SENF_LOG_PREDECL_,                                                               \
83                  BOOST_PP_IF(BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(seq)),long,short))(seq)
84
85 #define SENF_LOG_NIL(x)
86
87 #define SENF_LOG_CONF_DEFINE(stream, area, level)                                                 \
88     SENF_LOG_PREDECL(stream)                                                                      \
89     SENF_LOG_PREDECL(area)                                                                        \
90     namespace senf { namespace log { namespace detail {                                           \
91         template <>                                                                               \
92         struct Config< SENF_LOG_SEQ_TO_NAME(stream),                                              \
93                        SENF_LOG_SEQ_TO_NAME(area) >                                               \
94         { typedef senf::log::level compileLimit; };                                               \
95     }}}
96
97 #ifdef SENF_LOG_CONF
98
99 #   define _ senf::log::detail::na
100 #   define SLC_elt(r, data, elt) \
101         SENF_LOG_CONF_DEFINE elt
102
103     BOOST_PP_SEQ_FOR_EACH(SLC_elt, none, SENF_LOG_CONF)
104
105 #   undef SLC_elt
106 #   undef _
107
108 #endif
109
110
111
112
113 ///////////////////////////////ih.e////////////////////////////////////////
114 #endif
115
116 \f
117 // Local Variables:
118 // mode: c++
119 // fill-column: 100
120 // comment-column: 40
121 // c-file-style: "senf"
122 // indent-tabs-mode: nil
123 // ispell-local-dictionary: "american"
124 // compile-command: "scons -u test"
125 // End: