]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /* |
2 | * Copyright Andrey Semashev 2007 - 2015. | |
3 | * Distributed under the Boost Software License, Version 1.0. | |
4 | * (See accompanying file LICENSE_1_0.txt or copy at | |
5 | * http://www.boost.org/LICENSE_1_0.txt) | |
6 | */ | |
7 | /*! | |
8 | * \file formatters/named_scope.hpp | |
9 | * \author Andrey Semashev | |
10 | * \date 11.11.2012 | |
11 | * | |
12 | * The header contains a formatter function for named scope attribute values. | |
13 | */ | |
14 | ||
15 | #ifndef BOOST_LOG_EXPRESSIONS_FORMATTERS_NAMED_SCOPE_HPP_INCLUDED_ | |
16 | #define BOOST_LOG_EXPRESSIONS_FORMATTERS_NAMED_SCOPE_HPP_INCLUDED_ | |
17 | ||
18 | #include <string> | |
19 | #include <iterator> | |
20 | #include <utility> | |
21 | #include <boost/static_assert.hpp> | |
22 | #include <boost/type_traits/is_same.hpp> | |
23 | #include <boost/move/core.hpp> | |
24 | #include <boost/move/utility_core.hpp> | |
25 | #include <boost/parameter/binding.hpp> | |
26 | #include <boost/preprocessor/iteration/iterate.hpp> | |
27 | #include <boost/preprocessor/repetition/enum_params.hpp> | |
28 | #include <boost/preprocessor/repetition/enum_binary_params.hpp> | |
29 | #include <boost/phoenix/core/actor.hpp> | |
30 | #include <boost/phoenix/core/terminal_fwd.hpp> | |
31 | #include <boost/phoenix/core/is_nullary.hpp> | |
32 | #include <boost/phoenix/core/environment.hpp> | |
33 | #include <boost/fusion/sequence/intrinsic/at_c.hpp> | |
34 | #include <boost/log/detail/config.hpp> | |
35 | #include <boost/log/attributes/attribute_name.hpp> | |
36 | #include <boost/log/attributes/fallback_policy.hpp> | |
37 | #include <boost/log/attributes/named_scope.hpp> | |
38 | #include <boost/log/attributes/value_visitation.hpp> | |
39 | #include <boost/log/detail/light_function.hpp> | |
40 | #include <boost/log/detail/parameter_tools.hpp> | |
41 | #include <boost/log/detail/custom_terminal_spec.hpp> | |
42 | #include <boost/log/detail/deduce_char_type.hpp> | |
43 | #include <boost/log/detail/attr_output_terminal.hpp> | |
44 | #include <boost/log/expressions/attr_fwd.hpp> | |
45 | #include <boost/log/expressions/keyword_fwd.hpp> | |
46 | #include <boost/log/utility/formatting_ostream.hpp> | |
47 | #include <boost/log/utility/string_literal_fwd.hpp> | |
48 | #include <boost/log/utility/functional/bind.hpp> | |
49 | #include <boost/log/keywords/format.hpp> | |
50 | #include <boost/log/keywords/delimiter.hpp> | |
51 | #include <boost/log/keywords/depth.hpp> | |
52 | #include <boost/log/keywords/iteration.hpp> | |
53 | #include <boost/log/keywords/empty_marker.hpp> | |
54 | #include <boost/log/keywords/incomplete_marker.hpp> | |
55 | #include <boost/log/detail/header.hpp> | |
56 | ||
57 | #ifdef BOOST_HAS_PRAGMA_ONCE | |
58 | #pragma once | |
59 | #endif | |
60 | ||
61 | namespace boost { | |
62 | ||
63 | BOOST_LOG_OPEN_NAMESPACE | |
64 | ||
65 | namespace expressions { | |
66 | ||
67 | //! Scope iteration directions | |
68 | enum scope_iteration_direction | |
69 | { | |
70 | forward, //!< Iterate through scopes from outermost to innermost | |
71 | reverse //!< Iterate through scopes from innermost to outermost | |
72 | }; | |
73 | ||
74 | namespace aux { | |
75 | ||
76 | #ifdef BOOST_LOG_USE_CHAR | |
77 | //! Parses the named scope format string and constructs the formatter function | |
78 | BOOST_LOG_API boost::log::aux::light_function< void (basic_formatting_ostream< char >&, attributes::named_scope::value_type::value_type const&) > | |
79 | parse_named_scope_format(const char* begin, const char* end); | |
80 | #endif | |
81 | ||
82 | #ifdef BOOST_LOG_USE_WCHAR_T | |
83 | //! Parses the named scope format string and constructs the formatter function | |
84 | BOOST_LOG_API boost::log::aux::light_function< void (basic_formatting_ostream< wchar_t >&, attributes::named_scope::value_type::value_type const&) > | |
85 | parse_named_scope_format(const wchar_t* begin, const wchar_t* end); | |
86 | #endif | |
87 | ||
88 | //! Parses the named scope format string and constructs the formatter function | |
89 | template< typename CharT > | |
90 | inline boost::log::aux::light_function< void (basic_formatting_ostream< CharT >&, attributes::named_scope::value_type::value_type const&) > | |
91 | parse_named_scope_format(const CharT* format) | |
92 | { | |
93 | return parse_named_scope_format(format, format + std::char_traits< CharT >::length(format)); | |
94 | } | |
95 | ||
96 | //! Parses the named scope format string and constructs the formatter function | |
97 | template< typename CharT, typename TraitsT, typename AllocatorT > | |
98 | inline boost::log::aux::light_function< void (basic_formatting_ostream< CharT >&, attributes::named_scope::value_type::value_type const&) > | |
99 | parse_named_scope_format(std::basic_string< CharT, TraitsT, AllocatorT > const& format) | |
100 | { | |
101 | const CharT* p = format.c_str(); | |
102 | return parse_named_scope_format(p, p + format.size()); | |
103 | } | |
104 | ||
105 | //! Parses the named scope format string and constructs the formatter function | |
106 | template< typename CharT, typename TraitsT > | |
107 | inline boost::log::aux::light_function< void (basic_formatting_ostream< CharT >&, attributes::named_scope::value_type::value_type const&) > | |
108 | parse_named_scope_format(basic_string_literal< CharT, TraitsT > const& format) | |
109 | { | |
110 | const CharT* p = format.c_str(); | |
111 | return parse_named_scope_format(p, p + format.size()); | |
112 | } | |
113 | ||
114 | template< typename CharT > | |
115 | class format_named_scope_impl | |
116 | { | |
117 | public: | |
118 | //! Function result type | |
119 | typedef void result_type; | |
120 | ||
121 | //! Character type | |
122 | typedef CharT char_type; | |
123 | //! String type | |
124 | typedef std::basic_string< char_type > string_type; | |
125 | //! Formatting stream type | |
126 | typedef basic_formatting_ostream< char_type > stream_type; | |
127 | //! Attribute value type | |
128 | typedef attributes::named_scope::value_type value_type; | |
129 | //! Named scope formatter | |
130 | typedef boost::log::aux::light_function< void (stream_type&, value_type::value_type const&) > element_formatter_type; | |
131 | ||
132 | private: | |
133 | //! Element formatting function | |
134 | element_formatter_type m_element_formatter; | |
135 | //! Element delimiter | |
136 | string_type m_delimiter; | |
137 | //! Incomplete list marker | |
138 | string_type m_incomplete_marker; | |
139 | //! Empty list marker | |
140 | string_type m_empty_marker; | |
141 | //! Maximum number of elements to output | |
142 | value_type::size_type m_depth; | |
143 | //! Iteration direction | |
144 | scope_iteration_direction m_direction; | |
145 | ||
146 | public: | |
147 | //! Initializing constructor | |
148 | format_named_scope_impl | |
149 | ( | |
150 | element_formatter_type const& element_formatter, | |
151 | string_type const& delimiter, | |
152 | string_type const& incomplete_marker, | |
153 | string_type const& empty_marker, | |
154 | value_type::size_type depth, | |
155 | scope_iteration_direction direction | |
156 | ) : | |
157 | m_element_formatter(element_formatter), | |
158 | m_delimiter(delimiter), | |
159 | m_incomplete_marker(incomplete_marker), | |
160 | m_empty_marker(empty_marker), | |
161 | m_depth(depth), | |
162 | m_direction(direction) | |
163 | { | |
164 | } | |
165 | //! Copy constructor | |
166 | format_named_scope_impl(format_named_scope_impl const& that) : | |
167 | m_element_formatter(that.m_element_formatter), | |
168 | m_delimiter(that.m_delimiter), | |
169 | m_incomplete_marker(that.m_incomplete_marker), | |
170 | m_empty_marker(that.m_empty_marker), | |
171 | m_depth(that.m_depth), | |
172 | m_direction(that.m_direction) | |
173 | { | |
174 | } | |
175 | ||
176 | //! Formatting operator | |
177 | result_type operator() (stream_type& strm, value_type const& scopes) const | |
178 | { | |
179 | if (!scopes.empty()) | |
180 | { | |
181 | if (m_direction == expressions::forward) | |
182 | format_forward(strm, scopes); | |
183 | else | |
184 | format_reverse(strm, scopes); | |
185 | } | |
186 | else | |
187 | { | |
188 | strm << m_empty_marker; | |
189 | } | |
190 | } | |
191 | ||
192 | private: | |
193 | //! The function performs formatting of the extracted scope stack in forward direction | |
194 | void format_forward(stream_type& strm, value_type const& scopes) const | |
195 | { | |
196 | value_type::const_iterator it, end = scopes.end(); | |
197 | if (m_depth > 0) | |
198 | { | |
199 | value_type::size_type const scopes_to_iterate = (std::min)(m_depth, scopes.size()); | |
200 | it = scopes.end(); | |
201 | std::advance(it, -static_cast< value_type::difference_type >(scopes_to_iterate)); | |
202 | } | |
203 | else | |
204 | { | |
205 | it = scopes.begin(); | |
206 | } | |
207 | ||
208 | if (it != end) | |
209 | { | |
210 | if (it != scopes.begin()) | |
211 | strm << m_incomplete_marker; | |
212 | ||
213 | m_element_formatter(strm, *it); | |
214 | for (++it; it != end; ++it) | |
215 | { | |
216 | strm << m_delimiter; | |
217 | m_element_formatter(strm, *it); | |
218 | } | |
219 | } | |
220 | } | |
221 | //! The function performs formatting of the extracted scope stack in reverse direction | |
222 | void format_reverse(stream_type& strm, value_type const& scopes) const | |
223 | { | |
224 | value_type::const_reverse_iterator it = scopes.rbegin(), end; | |
225 | if (m_depth > 0) | |
226 | { | |
227 | value_type::size_type const scopes_to_iterate = (std::min)(m_depth, scopes.size()); | |
228 | end = it; | |
229 | std::advance(end, static_cast< value_type::difference_type >(scopes_to_iterate)); | |
230 | } | |
231 | else | |
232 | { | |
233 | end = scopes.rend(); | |
234 | } | |
235 | ||
236 | if (it != end) | |
237 | { | |
238 | m_element_formatter(strm, *it); | |
239 | for (++it; it != end; ++it) | |
240 | { | |
241 | strm << m_delimiter; | |
242 | m_element_formatter(strm, *it); | |
243 | } | |
244 | ||
245 | if (it != scopes.rend()) | |
246 | strm << m_incomplete_marker; | |
247 | } | |
248 | } | |
249 | }; | |
250 | ||
251 | } // namespace aux | |
252 | ||
253 | /*! | |
254 | * Named scope formatter terminal. | |
255 | */ | |
256 | template< typename FallbackPolicyT, typename CharT > | |
257 | class format_named_scope_terminal | |
258 | { | |
259 | public: | |
260 | #ifndef BOOST_LOG_DOXYGEN_PASS | |
261 | //! Internal typedef for type categorization | |
262 | typedef void _is_boost_log_terminal; | |
263 | #endif | |
264 | ||
265 | //! Attribute value type | |
266 | typedef attributes::named_scope::value_type value_type; | |
267 | //! Fallback policy | |
268 | typedef FallbackPolicyT fallback_policy; | |
269 | //! Character type | |
270 | typedef CharT char_type; | |
271 | //! String type | |
272 | typedef std::basic_string< char_type > string_type; | |
273 | //! Formatting stream type | |
274 | typedef basic_formatting_ostream< char_type > stream_type; | |
275 | //! Formatter function | |
276 | typedef aux::format_named_scope_impl< char_type > formatter_function_type; | |
277 | ||
278 | //! Function result type | |
279 | typedef string_type result_type; | |
280 | ||
281 | private: | |
282 | //! Attribute value visitor invoker | |
283 | typedef value_visitor_invoker< value_type, fallback_policy > visitor_invoker_type; | |
284 | ||
285 | private: | |
286 | //! Attribute name | |
287 | attribute_name m_name; | |
288 | //! Formatter function | |
289 | formatter_function_type m_formatter; | |
290 | //! Attribute value visitor invoker | |
291 | visitor_invoker_type m_visitor_invoker; | |
292 | ||
293 | public: | |
294 | //! Initializing constructor | |
295 | template< typename FormatT > | |
296 | format_named_scope_terminal | |
297 | ( | |
298 | attribute_name const& name, | |
299 | fallback_policy const& fallback, | |
300 | FormatT const& element_format, | |
301 | string_type const& delimiter, | |
302 | string_type const& incomplete_marker, | |
303 | string_type const& empty_marker, | |
304 | value_type::size_type depth, | |
305 | scope_iteration_direction direction | |
306 | ) : | |
307 | m_name(name), m_formatter(aux::parse_named_scope_format(element_format), delimiter, incomplete_marker, empty_marker, depth, direction), m_visitor_invoker(fallback) | |
308 | { | |
309 | } | |
310 | //! Copy constructor | |
311 | format_named_scope_terminal(format_named_scope_terminal const& that) : | |
312 | m_name(that.m_name), m_formatter(that.m_formatter), m_visitor_invoker(that.m_visitor_invoker) | |
313 | { | |
314 | } | |
315 | ||
316 | //! Returns attribute name | |
317 | attribute_name get_name() const | |
318 | { | |
319 | return m_name; | |
320 | } | |
321 | ||
322 | //! Returns fallback policy | |
323 | fallback_policy const& get_fallback_policy() const | |
324 | { | |
325 | return m_visitor_invoker.get_fallback_policy(); | |
326 | } | |
327 | ||
328 | //! Retruns formatter function | |
329 | formatter_function_type const& get_formatter_function() const | |
330 | { | |
331 | return m_formatter; | |
332 | } | |
333 | ||
334 | //! Invokation operator | |
335 | template< typename ContextT > | |
336 | result_type operator() (ContextT const& ctx) | |
337 | { | |
338 | string_type str; | |
339 | stream_type strm(str); | |
340 | m_visitor_invoker(m_name, fusion::at_c< 0 >(phoenix::env(ctx).args()), binder1st< formatter_function_type&, stream_type& >(m_formatter, strm)); | |
341 | strm.flush(); | |
342 | return BOOST_LOG_NRVO_RESULT(str); | |
343 | } | |
344 | ||
345 | //! Invokation operator | |
346 | template< typename ContextT > | |
347 | result_type operator() (ContextT const& ctx) const | |
348 | { | |
349 | string_type str; | |
350 | stream_type strm(str); | |
351 | m_visitor_invoker(m_name, fusion::at_c< 0 >(phoenix::env(ctx).args()), binder1st< formatter_function_type const&, stream_type& >(m_formatter, strm)); | |
352 | strm.flush(); | |
353 | return BOOST_LOG_NRVO_RESULT(str); | |
354 | } | |
355 | ||
356 | BOOST_DELETED_FUNCTION(format_named_scope_terminal()) | |
357 | }; | |
358 | ||
359 | /*! | |
360 | * Named scope formatter actor. | |
361 | */ | |
362 | template< typename FallbackPolicyT, typename CharT, template< typename > class ActorT = phoenix::actor > | |
363 | class format_named_scope_actor : | |
364 | public ActorT< format_named_scope_terminal< FallbackPolicyT, CharT > > | |
365 | { | |
366 | public: | |
367 | //! Character type | |
368 | typedef CharT char_type; | |
369 | //! Fallback policy | |
370 | typedef FallbackPolicyT fallback_policy; | |
371 | //! Base terminal type | |
372 | typedef format_named_scope_terminal< fallback_policy, char_type > terminal_type; | |
373 | //! Attribute value type | |
374 | typedef typename terminal_type::value_type value_type; | |
375 | //! Formatter function | |
376 | typedef typename terminal_type::formatter_function_type formatter_function_type; | |
377 | ||
378 | //! Base actor type | |
379 | typedef ActorT< terminal_type > base_type; | |
380 | ||
381 | public: | |
382 | //! Initializing constructor | |
383 | explicit format_named_scope_actor(base_type const& act) : base_type(act) | |
384 | { | |
385 | } | |
386 | ||
387 | /*! | |
388 | * \returns The attribute name | |
389 | */ | |
390 | attribute_name get_name() const | |
391 | { | |
392 | return this->proto_expr_.child0.get_name(); | |
393 | } | |
394 | ||
395 | /*! | |
396 | * \returns Fallback policy | |
397 | */ | |
398 | fallback_policy const& get_fallback_policy() const | |
399 | { | |
400 | return this->proto_expr_.child0.get_fallback_policy(); | |
401 | } | |
402 | ||
403 | /*! | |
404 | * \returns Formatter function | |
405 | */ | |
406 | formatter_function_type const& get_formatter_function() const | |
407 | { | |
408 | return this->proto_expr_.child0.get_formatter_function(); | |
409 | } | |
410 | }; | |
411 | ||
412 | #ifndef BOOST_LOG_DOXYGEN_PASS | |
413 | ||
414 | #define BOOST_LOG_AUX_OVERLOAD(left_ref, right_ref)\ | |
415 | template< typename LeftExprT, typename FallbackPolicyT, typename CharT >\ | |
416 | BOOST_FORCEINLINE phoenix::actor< aux::attribute_output_terminal< phoenix::actor< LeftExprT >, attributes::named_scope::value_type, FallbackPolicyT, typename format_named_scope_actor< FallbackPolicyT, CharT >::formatter_function_type > >\ | |
417 | operator<< (phoenix::actor< LeftExprT > left_ref left, format_named_scope_actor< FallbackPolicyT, CharT > right_ref right)\ | |
418 | {\ | |
419 | typedef aux::attribute_output_terminal< phoenix::actor< LeftExprT >, attributes::named_scope::value_type, FallbackPolicyT, typename format_named_scope_actor< FallbackPolicyT, CharT >::formatter_function_type > terminal_type;\ | |
420 | phoenix::actor< terminal_type > actor = {{ terminal_type(left, right.get_name(), right.get_formatter_function(), right.get_fallback_policy()) }};\ | |
421 | return actor;\ | |
422 | } | |
423 | ||
424 | #include <boost/log/detail/generate_overloads.hpp> | |
425 | ||
426 | #undef BOOST_LOG_AUX_OVERLOAD | |
427 | ||
428 | #endif // BOOST_LOG_DOXYGEN_PASS | |
429 | ||
430 | namespace aux { | |
431 | ||
432 | //! Auxiliary traits to acquire default formatter parameters depending on the character type | |
433 | template< typename CharT > | |
434 | struct default_named_scope_params; | |
435 | ||
436 | #ifdef BOOST_LOG_USE_CHAR | |
437 | template< > | |
438 | struct default_named_scope_params< char > | |
439 | { | |
440 | static const char* forward_delimiter() { return "->"; } | |
441 | static const char* reverse_delimiter() { return "<-"; } | |
442 | static const char* incomplete_marker() { return "..."; } | |
443 | static const char* empty_marker() { return ""; } | |
444 | }; | |
445 | #endif | |
446 | #ifdef BOOST_LOG_USE_WCHAR_T | |
447 | template< > | |
448 | struct default_named_scope_params< wchar_t > | |
449 | { | |
450 | static const wchar_t* forward_delimiter() { return L"->"; } | |
451 | static const wchar_t* reverse_delimiter() { return L"<-"; } | |
452 | static const wchar_t* incomplete_marker() { return L"..."; } | |
453 | static const wchar_t* empty_marker() { return L""; } | |
454 | }; | |
455 | #endif | |
456 | ||
457 | template< typename CharT, template< typename > class ActorT, typename FallbackPolicyT, typename ArgsT > | |
458 | BOOST_FORCEINLINE format_named_scope_actor< FallbackPolicyT, CharT, ActorT > format_named_scope(attribute_name const& name, FallbackPolicyT const& fallback, ArgsT const& args) | |
459 | { | |
460 | typedef format_named_scope_actor< FallbackPolicyT, CharT, ActorT > actor_type; | |
461 | typedef typename actor_type::terminal_type terminal_type; | |
462 | typedef default_named_scope_params< CharT > default_params; | |
463 | scope_iteration_direction dir = args[keywords::iteration | expressions::forward]; | |
464 | const CharT* default_delimiter = (dir == expressions::forward ? default_params::forward_delimiter() : default_params::reverse_delimiter()); | |
465 | typename actor_type::base_type act = | |
466 | {{ | |
467 | terminal_type | |
468 | ( | |
469 | name, | |
470 | fallback, | |
471 | args[keywords::format], | |
472 | args[keywords::delimiter | default_delimiter], | |
473 | args[keywords::incomplete_marker | default_params::incomplete_marker()], | |
474 | args[keywords::empty_marker | default_params::empty_marker()], | |
475 | args[keywords::depth | static_cast< attributes::named_scope::value_type::size_type >(0)], | |
476 | dir | |
477 | ) | |
478 | }}; | |
479 | return actor_type(act); | |
480 | } | |
481 | ||
482 | } // namespace aux | |
483 | ||
484 | /*! | |
485 | * The function generates a manipulator node in a template expression. The manipulator must participate in a formatting | |
486 | * expression (stream output or \c format placeholder filler). | |
487 | * | |
488 | * \param name Attribute name | |
489 | * \param element_format Format string for a single named scope | |
490 | */ | |
491 | template< typename CharT > | |
492 | BOOST_FORCEINLINE format_named_scope_actor< fallback_to_none, CharT > format_named_scope(attribute_name const& name, const CharT* element_format) | |
493 | { | |
494 | typedef format_named_scope_actor< fallback_to_none, CharT > actor_type; | |
495 | typedef typename actor_type::terminal_type terminal_type; | |
496 | typename actor_type::base_type act = {{ terminal_type(name, fallback_to_none(), element_format) }}; | |
497 | return actor_type(act); | |
498 | } | |
499 | ||
500 | /*! | |
501 | * The function generates a manipulator node in a template expression. The manipulator must participate in a formatting | |
502 | * expression (stream output or \c format placeholder filler). | |
503 | * | |
504 | * \param name Attribute name | |
505 | * \param element_format Format string for a single named scope | |
506 | */ | |
507 | template< typename CharT > | |
508 | BOOST_FORCEINLINE format_named_scope_actor< fallback_to_none, CharT > format_named_scope(attribute_name const& name, std::basic_string< CharT > const& element_format) | |
509 | { | |
510 | typedef format_named_scope_actor< fallback_to_none, CharT > actor_type; | |
511 | typedef typename actor_type::terminal_type terminal_type; | |
512 | typename actor_type::base_type act = {{ terminal_type(name, fallback_to_none(), element_format) }}; | |
513 | return actor_type(act); | |
514 | } | |
515 | ||
516 | /*! | |
517 | * The function generates a manipulator node in a template expression. The manipulator must participate in a formatting | |
518 | * expression (stream output or \c format placeholder filler). | |
519 | * | |
520 | * \param keyword Attribute keyword | |
521 | * \param element_format Format string for a single named scope | |
522 | */ | |
523 | template< typename DescriptorT, template< typename > class ActorT, typename CharT > | |
524 | BOOST_FORCEINLINE format_named_scope_actor< fallback_to_none, CharT, ActorT > | |
525 | format_named_scope(attribute_keyword< DescriptorT, ActorT > const& keyword, const CharT* element_format) | |
526 | { | |
527 | BOOST_STATIC_ASSERT_MSG((is_same< typename DescriptorT::value_type, attributes::named_scope::value_type >::value),\ | |
528 | "Boost.Log: Named scope formatter only accepts attribute values of type attributes::named_scope::value_type."); | |
529 | ||
530 | typedef format_named_scope_actor< fallback_to_none, CharT, ActorT > actor_type; | |
531 | typedef typename actor_type::terminal_type terminal_type; | |
532 | typename actor_type::base_type act = {{ terminal_type(keyword.get_name(), fallback_to_none(), element_format) }}; | |
533 | return actor_type(act); | |
534 | } | |
535 | ||
536 | /*! | |
537 | * The function generates a manipulator node in a template expression. The manipulator must participate in a formatting | |
538 | * expression (stream output or \c format placeholder filler). | |
539 | * | |
540 | * \param keyword Attribute keyword | |
541 | * \param element_format Format string for a single named scope | |
542 | */ | |
543 | template< typename DescriptorT, template< typename > class ActorT, typename CharT > | |
544 | BOOST_FORCEINLINE format_named_scope_actor< fallback_to_none, CharT, ActorT > | |
545 | format_named_scope(attribute_keyword< DescriptorT, ActorT > const& keyword, std::basic_string< CharT > const& element_format) | |
546 | { | |
547 | BOOST_STATIC_ASSERT_MSG((is_same< typename DescriptorT::value_type, attributes::named_scope::value_type >::value),\ | |
548 | "Boost.Log: Named scope formatter only accepts attribute values of type attributes::named_scope::value_type."); | |
549 | ||
550 | typedef format_named_scope_actor< fallback_to_none, CharT, ActorT > actor_type; | |
551 | typedef typename actor_type::terminal_type terminal_type; | |
552 | typename actor_type::base_type act = {{ terminal_type(keyword.get_name(), fallback_to_none(), element_format) }}; | |
553 | return actor_type(act); | |
554 | } | |
555 | ||
556 | /*! | |
557 | * The function generates a manipulator node in a template expression. The manipulator must participate in a formatting | |
558 | * expression (stream output or \c format placeholder filler). | |
559 | * | |
560 | * \param placeholder Attribute placeholder | |
561 | * \param element_format Format string for a single named scope | |
562 | */ | |
563 | template< typename T, typename FallbackPolicyT, typename TagT, template< typename > class ActorT, typename CharT > | |
564 | BOOST_FORCEINLINE format_named_scope_actor< FallbackPolicyT, CharT, ActorT > | |
565 | format_named_scope(attribute_actor< T, FallbackPolicyT, TagT, ActorT > const& placeholder, const CharT* element_format) | |
566 | { | |
567 | BOOST_STATIC_ASSERT_MSG((is_same< T, attributes::named_scope::value_type >::value),\ | |
568 | "Boost.Log: Named scope formatter only accepts attribute values of type attributes::named_scope::value_type."); | |
569 | ||
570 | typedef format_named_scope_actor< FallbackPolicyT, CharT, ActorT > actor_type; | |
571 | typedef typename actor_type::terminal_type terminal_type; | |
572 | typename actor_type::base_type act = {{ terminal_type(placeholder.get_name(), placeholder.get_fallback_policy(), element_format) }}; | |
573 | return actor_type(act); | |
574 | } | |
575 | ||
576 | /*! | |
577 | * The function generates a manipulator node in a template expression. The manipulator must participate in a formatting | |
578 | * expression (stream output or \c format placeholder filler). | |
579 | * | |
580 | * \param placeholder Attribute placeholder | |
581 | * \param element_format Format string for a single named scope | |
582 | */ | |
583 | template< typename T, typename FallbackPolicyT, typename TagT, template< typename > class ActorT, typename CharT > | |
584 | BOOST_FORCEINLINE format_named_scope_actor< FallbackPolicyT, CharT, ActorT > | |
585 | format_named_scope(attribute_actor< T, FallbackPolicyT, TagT, ActorT > const& placeholder, std::basic_string< CharT > const& element_format) | |
586 | { | |
587 | BOOST_STATIC_ASSERT_MSG((is_same< T, attributes::named_scope::value_type >::value),\ | |
588 | "Boost.Log: Named scope formatter only accepts attribute values of type attributes::named_scope::value_type."); | |
589 | ||
590 | typedef format_named_scope_actor< FallbackPolicyT, CharT, ActorT > actor_type; | |
591 | typedef typename actor_type::terminal_type terminal_type; | |
592 | typename actor_type::base_type act = {{ terminal_type(placeholder.get_name(), placeholder.get_fallback_policy(), element_format) }}; | |
593 | return actor_type(act); | |
594 | } | |
595 | ||
596 | #if !defined(BOOST_LOG_DOXYGEN_PASS) | |
597 | ||
598 | # define BOOST_PP_FILENAME_1 <boost/log/detail/named_scope_fmt_pp.hpp> | |
599 | # define BOOST_PP_ITERATION_LIMITS (1, 6) | |
600 | # include BOOST_PP_ITERATE() | |
601 | ||
602 | #else // BOOST_LOG_DOXYGEN_PASS | |
603 | ||
604 | /*! | |
605 | * Formatter generator. Construct the named scope formatter with the specified formatting parameters. | |
606 | * | |
607 | * \param name Attribute name | |
608 | * \param args An set of named parameters. Supported parameters: | |
609 | * \li \c format - A format string for named scopes. The string can contain "%n", "%f" and "%l" placeholders for the scope name, file and line number, respectively. This parameter is mandatory. | |
610 | * \li \c delimiter - A string that is used to delimit the formatted scope names. Default: "->" or "<-", depending on the iteration direction. | |
611 | * \li \c incomplete_marker - A string that is used to indicate that the list was printed incomplete because of depth limitation. Default: "...". | |
612 | * \li \c empty_marker - A string that is output in case if the scope list is empty. Default: "", i.e. nothing is output. | |
613 | * \li \c iteration - Iteration direction, see \c scope_iteration_direction enumeration. Default: forward. | |
614 | * \li \c depth - Iteration depth. Default: unlimited. | |
615 | */ | |
616 | template< typename... ArgsT > | |
617 | unspecified format_named_scope(attribute_name const& name, ArgsT... const& args); | |
618 | ||
619 | /*! \overload */ | |
620 | template< typename DescriptorT, template< typename > class ActorT, typename... ArgsT > | |
621 | unspecified format_named_scope(attribute_keyword< DescriptorT, ActorT > const& keyword, ArgsT... const& args); | |
622 | ||
623 | /*! \overload */ | |
624 | template< typename T, typename FallbackPolicyT, typename TagT, template< typename > class ActorT, typename... ArgsT > | |
625 | unspecified format_named_scope(attribute_actor< T, FallbackPolicyT, TagT, ActorT > const& placeholder, ArgsT... const& args); | |
626 | ||
627 | #endif // BOOST_LOG_DOXYGEN_PASS | |
628 | ||
629 | } // namespace expressions | |
630 | ||
631 | BOOST_LOG_CLOSE_NAMESPACE // namespace log | |
632 | ||
633 | #ifndef BOOST_LOG_DOXYGEN_PASS | |
634 | ||
635 | namespace phoenix { | |
636 | ||
637 | namespace result_of { | |
638 | ||
639 | template< typename FallbackPolicyT, typename CharT > | |
640 | struct is_nullary< custom_terminal< boost::log::expressions::format_named_scope_terminal< FallbackPolicyT, CharT > > > : | |
641 | public mpl::false_ | |
642 | { | |
643 | }; | |
644 | ||
645 | } // namespace result_of | |
646 | ||
647 | } // namespace phoenix | |
648 | ||
649 | #endif | |
650 | ||
651 | } // namespace boost | |
652 | ||
653 | #include <boost/log/detail/footer.hpp> | |
654 | ||
655 | #endif // BOOST_LOG_EXPRESSIONS_FORMATTERS_NAMED_SCOPE_HPP_INCLUDED_ |