8ed7edf92fafd231d7aceaba3dbcb9ef791f2045
[senf.git] / senf / Utils / Logger / Config.ih
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27
28 /** \file
29     \brief Config internal header */
30
31 #ifndef IH_SENF_Utils_Logger_Config_
32 #define IH_SENF_Utils_Logger_Config_ 1
33
34 // Custom includes
35 #include <boost/preprocessor/expand.hpp>
36 #include <boost/preprocessor/seq/for_each.hpp>
37 #include <boost/preprocessor/seq/to_tuple.hpp>
38 #include <boost/preprocessor/seq/fold_right.hpp>
39 #include <boost/preprocessor/seq/pop_back.hpp>
40 #include <boost/preprocessor/if.hpp>
41 #include <boost/preprocessor/facilities/is_empty.hpp>
42 #include <senf/Utils/preprocessor.hh>
43
44 //-/////////////////////////////////////////////////////////////////////////////////////////////////
45
46 namespace senf {
47 namespace log {
48 namespace detail {
49
50     struct na {};
51
52     /// Internal: Compile time configuration for given \a Stream and \a Area
53     template <class Stream, class Area, class QueryStream=Stream, bool Query=true>
54     struct Config
55     {
56         typedef typename Config<na, Area, Stream, Query>::compileLimit compileLimit;
57     };
58
59 #   ifndef DOXYGEN
60
61     template <class Area, class QueryStream, bool Query>
62     struct Config<na, Area, QueryStream, Query>
63     {
64         typedef typename Config<QueryStream, na, QueryStream, Query>::compileLimit compileLimit;
65     };
66
67     template <class Stream, class QueryStream, bool Query>
68     struct Config<Stream, na, QueryStream, Query>
69     {
70         typedef typename Config<na, na, QueryStream, Query>::compileLimit compileLimit;
71     };
72
73     template <class QueryStream, bool Query>
74     struct Config<na, na, QueryStream, Query>
75     {
76         typedef typename QueryStream::compileLimit compileLimit;
77     };
78
79 #   endif
80
81 }}}
82
83 #define SENF_LOG_CHECK_NA_
84
85 #define SENF_LOG_CAT(a,b) SENF_LOG_CAT_I(a,b)
86 #define SENF_LOG_CAT_I(a,b) a ## b
87
88 #define SENF_LOG_IS_NA(elt) BOOST_PP_IS_EMPTY( SENF_LOG_CAT(SENF_LOG_CHECK_NA, elt) )
89
90 #define SENF_LOG_SEQ_TO_NAME_(s,state,elem)                                                       \
91     BOOST_PP_IF( SENF_LOG_IS_NA(elem), senf::log::detail::na, state::elem )
92
93 #define SENF_LOG_SEQ_TO_NAME(seq)                                                                 \
94     BOOST_PP_SEQ_FOLD_LEFT(SENF_LOG_SEQ_TO_NAME_, , seq)
95
96 #define SENF_LOG_PREDECL_(s, state, elem)                                                         \
97     namespace elem { state }
98
99 #define SENF_LOG_PREDECL_long(seq)                                                                \
100     BOOST_PP_SEQ_FOLD_RIGHT( SENF_LOG_PREDECL_,                                                   \
101                              class SENF_PP_SEQ_BACK(seq);,                                        \
102                              BOOST_PP_SEQ_POP_BACK(seq) )
103
104 #define SENF_LOG_PREDECL_short(seq)                                                               \
105    BOOST_PP_IF( SENF_LOG_IS_NA( SENF_PP_SEQ_BACK(seq) ), ; , class SENF_PP_SEQ_BACK(seq); )
106
107 #define SENF_LOG_PREDECL(seq)                                                                     \
108     BOOST_PP_CAT(SENF_LOG_PREDECL_,                                                               \
109                  BOOST_PP_IF(BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(seq)),long,short))(seq)
110
111 #define SENF_LOG_NIL(x)
112
113 #define SENF_LOG_CONF_DEFINE(stream, area, level)                                                 \
114     SENF_LOG_PREDECL(stream)                                                                      \
115     SENF_LOG_PREDECL(area)                                                                        \
116     namespace senf { namespace log { namespace detail {                                           \
117         template <class QueryStream>                                                              \
118         struct Config< SENF_LOG_SEQ_TO_NAME(stream),                                              \
119                        SENF_LOG_SEQ_TO_NAME(area),                                                \
120                        QueryStream,                                                               \
121                        true >                                                                     \
122         { typedef senf::log::level compileLimit; };                                               \
123     }}}
124
125 #ifdef SENF_LOG_CONF
126
127 #   define SLC_elt(r, data, elt) \
128         SENF_LOG_CONF_DEFINE elt
129
130     BOOST_PP_SEQ_FOR_EACH(SLC_elt, none, SENF_LOG_CONF)
131
132 #   undef SLC_elt
133
134 #endif
135
136
137
138
139 //-/////////////////////////////////////////////////////////////////////////////////////////////////
140 #endif
141
142 \f
143 // Local Variables:
144 // mode: c++
145 // fill-column: 100
146 // comment-column: 40
147 // c-file-style: "senf"
148 // indent-tabs-mode: nil
149 // ispell-local-dictionary: "american"
150 // compile-command: "scons -u test"
151 // End: