named_scope.hpp 25 KB

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