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)
8 * \file value_extraction.hpp
9 * \author Andrey Semashev
12 * The header contains implementation of tools for extracting an attribute value
16 #ifndef BOOST_LOG_ATTRIBUTES_VALUE_EXTRACTION_HPP_INCLUDED_
17 #define BOOST_LOG_ATTRIBUTES_VALUE_EXTRACTION_HPP_INCLUDED_
19 #include <boost/mpl/vector.hpp>
20 #include <boost/mpl/joint_view.hpp>
21 #include <boost/mpl/if.hpp>
22 #include <boost/mpl/eval_if.hpp>
23 #include <boost/mpl/identity.hpp>
24 #include <boost/mpl/is_sequence.hpp>
25 #include <boost/mpl/contains.hpp>
26 #include <boost/mpl/push_back.hpp>
27 #include <boost/type_traits/is_same.hpp>
28 #include <boost/core/enable_if.hpp>
29 #include <boost/log/detail/config.hpp>
30 #include <boost/log/exceptions.hpp>
31 #include <boost/log/core/record.hpp>
32 #include <boost/log/attributes/attribute_name.hpp>
33 #include <boost/log/attributes/attribute_value.hpp>
34 #include <boost/log/attributes/attribute.hpp>
35 #include <boost/log/attributes/attribute_value_set.hpp>
36 #include <boost/log/attributes/value_extraction_fwd.hpp>
37 #include <boost/log/attributes/fallback_policy.hpp>
38 #include <boost/log/expressions/keyword_fwd.hpp>
39 #include <boost/log/utility/value_ref.hpp>
40 #include <boost/log/utility/type_dispatch/static_type_dispatcher.hpp>
41 #include <boost/log/detail/header.hpp>
43 #ifdef BOOST_HAS_PRAGMA_ONCE
49 BOOST_LOG_OPEN_NAMESPACE
54 * \brief A metafunction that allows to acquire the result of the value extraction
56 * The metafunction results in a type that is in form of <tt>T const&</tt>, if \c T is
57 * not an MPL type sequence and <tt>DefaultT</tt> is the same as <tt>T</tt>,
58 * or <tt>value_ref< TypesT, TagT ></tt> otherwise, with
59 * \c TypesT being a type sequence comprising the types from sequence \c T and \c DefaultT,
60 * if it is not present in \c T already.
62 template< typename T, typename DefaultT, typename TagT >
63 struct extract_or_default
65 typedef typename mpl::eval_if<
66 mpl::is_sequence< T >,
68 mpl::contains< T, DefaultT >,
70 mpl::push_back< T, DefaultT >
73 is_same< T, DefaultT >,
75 mpl::vector2< T, DefaultT >
77 >::type extracted_type;
79 typedef typename mpl::if_<
80 mpl::is_sequence< extracted_type >,
81 value_ref< extracted_type, TagT >,
87 * \brief A metafunction that allows to acquire the result of the value extraction
89 * The metafunction results in a type that is in form of <tt>T const&</tt>, if \c T is
90 * not an MPL type sequence, or <tt>value_ref< T, TagT ></tt> otherwise. In the latter
91 * case the value reference shall never be empty.
93 template< typename T, typename TagT >
94 struct extract_or_throw
96 typedef typename mpl::if_<
97 mpl::is_sequence< T >,
104 * \brief A metafunction that allows to acquire the result of the value extraction
106 * The metafunction results in a type that is in form of <tt>value_ref< T, TagT ></tt>.
108 template< typename T, typename TagT >
111 typedef value_ref< T, TagT > type;
114 } // namespace result_of
118 //! The function object initializes the value reference
119 template< typename RefT >
120 struct value_ref_initializer
122 typedef void result_type;
124 value_ref_initializer(RefT& ref) : m_ref(ref)
128 template< typename ArgT >
129 result_type operator() (ArgT const& arg) const
138 //! The function unwraps \c value_ref, if possible
139 template< typename T, typename TagT >
140 BOOST_FORCEINLINE typename boost::enable_if_c< mpl::is_sequence< T >::value, value_ref< T, TagT > >::type
141 unwrap_value_ref(value_ref< T, TagT > const& r)
146 template< typename T, typename TagT >
147 BOOST_FORCEINLINE typename boost::disable_if_c< mpl::is_sequence< T >::value, T const& >::type
148 unwrap_value_ref(value_ref< T, TagT > const& r)
156 * \brief Generic attribute value extractor
158 * Attribute value extractor is a functional object that attempts to find and extract the stored
159 * attribute value from the attribute values view or a log record. The extracted value is returned
160 * from the extractor.
162 template< typename T, typename FallbackPolicyT, typename TagT >
163 class value_extractor :
164 private FallbackPolicyT
168 typedef FallbackPolicyT fallback_policy;
169 //! Attribute value types
170 typedef T value_type;
171 //! Function object result type
172 typedef value_ref< value_type, TagT > result_type;
176 * Default constructor
178 BOOST_DEFAULTED_FUNCTION(value_extractor(), {})
183 value_extractor(value_extractor const& that) : fallback_policy(static_cast< fallback_policy const& >(that))
190 * \param arg Fallback policy constructor argument
192 template< typename U >
193 explicit value_extractor(U const& arg) : fallback_policy(arg) {}
196 * Extraction operator. Attempts to acquire the stored value of one of the supported types. If extraction succeeds,
197 * the extracted value is returned.
199 * \param attr The attribute value to extract from.
200 * \return The extracted value, if extraction succeeded, an empty value otherwise.
202 result_type operator() (attribute_value const& attr) const
205 aux::value_ref_initializer< result_type > initializer(res);
208 static_type_dispatcher< value_type > disp(initializer);
209 if (!attr.dispatch(disp) && !fallback_policy::apply_default(initializer))
210 fallback_policy::on_invalid_type(attr.get_type());
212 else if (!fallback_policy::apply_default(initializer))
214 fallback_policy::on_missing_value();
220 * Extraction operator. Looks for an attribute value with the specified name
221 * and tries to acquire the stored value of one of the supported types. If extraction succeeds,
222 * the extracted value is returned.
224 * \param name Attribute value name.
225 * \param attrs A set of attribute values in which to look for the specified attribute value.
226 * \return The extracted value, if extraction succeeded, an empty value otherwise.
228 result_type operator() (attribute_name const& name, attribute_value_set const& attrs) const
232 attribute_value_set::const_iterator it = attrs.find(name);
233 if (it != attrs.end())
234 return operator() (it->second);
236 return operator() (attribute_value());
240 // Attach the attribute name to the exception
241 boost::log::aux::attach_attribute_name_info(e, name);
247 * Extraction operator. Looks for an attribute value with the specified name
248 * and tries to acquire the stored value of one of the supported types. If extraction succeeds,
249 * the extracted value is returned.
251 * \param name Attribute value name.
252 * \param rec A log record. The attribute value will be sought among those associated with the record.
253 * \return The extracted value, if extraction succeeded, an empty value otherwise.
255 result_type operator() (attribute_name const& name, record const& rec) const
257 return operator() (name, rec.attribute_values());
261 * Extraction operator. Looks for an attribute value with the specified name
262 * and tries to acquire the stored value of one of the supported types. If extraction succeeds,
263 * the extracted value is returned.
265 * \param name Attribute value name.
266 * \param rec A log record view. The attribute value will be sought among those associated with the record.
267 * \return The extracted value, if extraction succeeded, an empty value otherwise.
269 result_type operator() (attribute_name const& name, record_view const& rec) const
271 return operator() (name, rec.attribute_values());
275 * \returns Fallback policy
277 fallback_policy const& get_fallback_policy() const
279 return *static_cast< fallback_policy const* >(this);
283 #if !defined(BOOST_LOG_DOXYGEN_PASS)
284 #if !defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS)
285 #define BOOST_LOG_AUX_VOID_DEFAULT = void
287 #define BOOST_LOG_AUX_VOID_DEFAULT
289 #endif // !defined(BOOST_LOG_DOXYGEN_PASS)
292 * The function extracts an attribute value from the view. The user has to explicitly specify the
293 * type or set of possible types of the attribute value to be extracted.
295 * \param name The name of the attribute value to extract.
296 * \param attrs A set of attribute values in which to look for the specified attribute value.
297 * \return A \c value_ref that refers to the extracted value, if found. An empty value otherwise.
299 template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT >
300 inline typename result_of::extract< T, TagT >::type extract(attribute_name const& name, attribute_value_set const& attrs)
302 value_extractor< T, fallback_to_none, TagT > extractor;
303 return extractor(name, attrs);
307 * The function extracts an attribute value from the view. The user has to explicitly specify the
308 * type or set of possible types of the attribute value to be extracted.
310 * \param name The name of the attribute value to extract.
311 * \param rec A log record. The attribute value will be sought among those associated with the record.
312 * \return A \c value_ref that refers to the extracted value, if found. An empty value otherwise.
314 template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT >
315 inline typename result_of::extract< T, TagT >::type extract(attribute_name const& name, record const& rec)
317 value_extractor< T, fallback_to_none, TagT > extractor;
318 return extractor(name, rec);
322 * The function extracts an attribute value from the view. The user has to explicitly specify the
323 * type or set of possible types of the attribute value to be extracted.
325 * \param name The name of the attribute value to extract.
326 * \param rec A log record view. The attribute value will be sought among those associated with the record.
327 * \return A \c value_ref that refers to the extracted value, if found. An empty value otherwise.
329 template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT >
330 inline typename result_of::extract< T, TagT >::type extract(attribute_name const& name, record_view const& rec)
332 value_extractor< T, fallback_to_none, TagT > extractor;
333 return extractor(name, rec);
337 * The function extracts an attribute value from the view. The user has to explicitly specify the
338 * type or set of possible types of the attribute value to be extracted.
340 * \param value Attribute value.
341 * \return A \c value_ref that refers to the extracted value, if found. An empty value otherwise.
343 template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT >
344 inline typename result_of::extract< T, TagT >::type extract(attribute_value const& value)
346 value_extractor< T, fallback_to_none, TagT > extractor;
347 return extractor(value);
351 * The function extracts an attribute value from the view. The user has to explicitly specify the
352 * type or set of possible types of the attribute value to be extracted.
354 * \param name The name of the attribute value to extract.
355 * \param attrs A set of attribute values in which to look for the specified attribute value.
356 * \return The extracted value or a non-empty \c value_ref that refers to the value.
357 * \throws An exception is thrown if the requested value cannot be extracted.
359 template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT >
360 inline typename result_of::extract_or_throw< T, TagT >::type extract_or_throw(attribute_name const& name, attribute_value_set const& attrs)
362 value_extractor< T, fallback_to_throw, TagT > extractor;
363 return aux::unwrap_value_ref(extractor(name, attrs));
367 * The function extracts an attribute value from the view. The user has to explicitly specify the
368 * type or set of possible types of the attribute value to be extracted.
370 * \param name The name of the attribute value to extract.
371 * \param rec A log record. The attribute value will be sought among those associated with the record.
372 * \return The extracted value or a non-empty \c value_ref that refers to the value.
373 * \throws An exception is thrown if the requested value cannot be extracted.
375 template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT >
376 inline typename result_of::extract_or_throw< T, TagT >::type extract_or_throw(attribute_name const& name, record const& rec)
378 value_extractor< T, fallback_to_throw, TagT > extractor;
379 return aux::unwrap_value_ref(extractor(name, rec));
383 * The function extracts an attribute value from the view. The user has to explicitly specify the
384 * type or set of possible types of the attribute value to be extracted.
386 * \param name The name of the attribute value to extract.
387 * \param rec A log record view. The attribute value will be sought among those associated with the record.
388 * \return The extracted value or a non-empty \c value_ref that refers to the value.
389 * \throws An exception is thrown if the requested value cannot be extracted.
391 template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT >
392 inline typename result_of::extract_or_throw< T, TagT >::type extract_or_throw(attribute_name const& name, record_view const& rec)
394 value_extractor< T, fallback_to_throw, TagT > extractor;
395 return aux::unwrap_value_ref(extractor(name, rec));
399 * The function extracts an attribute value from the view. The user has to explicitly specify the
400 * type or set of possible types of the attribute value to be extracted.
402 * \param value Attribute value.
403 * \return The extracted value or a non-empty \c value_ref that refers to the value.
404 * \throws An exception is thrown if the requested value cannot be extracted.
406 template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT >
407 inline typename result_of::extract_or_throw< T, TagT >::type extract_or_throw(attribute_value const& value)
409 value_extractor< T, fallback_to_throw, TagT > extractor;
410 return aux::unwrap_value_ref(extractor(value));
414 * The function extracts an attribute value from the view. The user has to explicitly specify the
415 * type or set of possible types of the attribute value to be extracted.
417 * \note Caution must be exercised if the default value is a temporary object. Because the function returns
418 * a reference, if the temporary object is destroyed, the reference may become dangling.
420 * \param name The name of the attribute value to extract.
421 * \param attrs A set of attribute values in which to look for the specified attribute value.
422 * \param def_val The default value
423 * \return The extracted value, if found. The default value otherwise.
425 template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT, typename DefaultT >
426 inline typename result_of::extract_or_default< T, DefaultT, TagT >::type
427 extract_or_default(attribute_name const& name, attribute_value_set const& attrs, DefaultT const& def_val)
429 typedef typename result_of::extract_or_default< T, DefaultT, TagT >::extracted_type extracted_type;
430 value_extractor< extracted_type, fallback_to_default< DefaultT const& >, TagT > extractor(def_val);
431 return aux::unwrap_value_ref(extractor(name, attrs));
435 * The function extracts an attribute value from the view. The user has to explicitly specify the
436 * type or set of possible types of the attribute value to be visited.
438 * \note Caution must be exercised if the default value is a temporary object. Because the function returns
439 * a reference, if the temporary object is destroyed, the reference may become dangling.
441 * \param name The name of the attribute value to extract.
442 * \param rec A log record. The attribute value will be sought among those associated with the record.
443 * \param def_val The default value
444 * \return The extracted value, if found. The default value otherwise.
446 template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT, typename DefaultT >
447 inline typename result_of::extract_or_default< T, DefaultT, TagT >::type
448 extract_or_default(attribute_name const& name, record const& rec, DefaultT const& def_val)
450 typedef typename result_of::extract_or_default< T, DefaultT, TagT >::extracted_type extracted_type;
451 value_extractor< extracted_type, fallback_to_default< DefaultT const& >, TagT > extractor(def_val);
452 return aux::unwrap_value_ref(extractor(name, rec));
456 * The function extracts an attribute value from the view. The user has to explicitly specify the
457 * type or set of possible types of the attribute value to be visited.
459 * \note Caution must be exercised if the default value is a temporary object. Because the function returns
460 * a reference, if the temporary object is destroyed, the reference may become dangling.
462 * \param name The name of the attribute value to extract.
463 * \param rec A log record view. The attribute value will be sought among those associated with the record.
464 * \param def_val The default value
465 * \return The extracted value, if found. The default value otherwise.
467 template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT, typename DefaultT >
468 inline typename result_of::extract_or_default< T, DefaultT, TagT >::type
469 extract_or_default(attribute_name const& name, record_view const& rec, DefaultT const& def_val)
471 typedef typename result_of::extract_or_default< T, DefaultT, TagT >::extracted_type extracted_type;
472 value_extractor< extracted_type, fallback_to_default< DefaultT const& >, TagT > extractor(def_val);
473 return aux::unwrap_value_ref(extractor(name, rec));
477 * The function extracts an attribute value from the view. The user has to explicitly specify the
478 * type or set of possible types of the attribute value to be visited.
480 * \note Caution must be exercised if the default value is a temporary object. Because the function returns
481 * a reference, if the temporary object is destroyed, the reference may become dangling.
483 * \param value Attribute value.
484 * \param def_val The default value
485 * \return The extracted value, if found. The default value otherwise.
487 template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT, typename DefaultT >
488 inline typename result_of::extract_or_default< T, DefaultT, TagT >::type extract_or_default(attribute_value const& value, DefaultT const& def_val)
490 typedef typename result_of::extract_or_default< T, DefaultT, TagT >::extracted_type extracted_type;
491 value_extractor< extracted_type, fallback_to_default< DefaultT const& >, TagT > extractor(def_val);
492 return aux::unwrap_value_ref(extractor(value));
495 #if defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS)
497 template< typename T >
498 inline typename result_of::extract< T >::type extract(attribute_name const& name, attribute_value_set const& attrs)
500 value_extractor< T, fallback_to_none > extractor;
501 return extractor(name, attrs);
504 template< typename T >
505 inline typename result_of::extract< T >::type extract(attribute_name const& name, record const& rec)
507 value_extractor< T, fallback_to_none > extractor;
508 return extractor(name, rec);
511 template< typename T >
512 inline typename result_of::extract< T >::type extract(attribute_name const& name, record_view const& rec)
514 value_extractor< T, fallback_to_none > extractor;
515 return extractor(name, rec);
518 template< typename T >
519 inline typename result_of::extract< T >::type extract(attribute_value const& value)
521 value_extractor< T, fallback_to_none > extractor;
522 return extractor(value);
525 template< typename T >
526 inline typename result_of::extract_or_throw< T >::type extract_or_throw(attribute_name const& name, attribute_value_set const& attrs)
528 value_extractor< T, fallback_to_throw > extractor;
529 return aux::unwrap_value_ref(extractor(name, attrs));
532 template< typename T >
533 inline typename result_of::extract_or_throw< T >::type extract_or_throw(attribute_name const& name, record const& rec)
535 value_extractor< T, fallback_to_throw > extractor;
536 return aux::unwrap_value_ref(extractor(name, rec));
539 template< typename T >
540 inline typename result_of::extract_or_throw< T >::type extract_or_throw(attribute_name const& name, record_view const& rec)
542 value_extractor< T, fallback_to_throw > extractor;
543 return aux::unwrap_value_ref(extractor(name, rec));
546 template< typename T >
547 inline typename result_of::extract_or_throw< T >::type extract_or_throw(attribute_value const& value)
549 value_extractor< T, fallback_to_throw > extractor;
550 return aux::unwrap_value_ref(extractor(value));
553 template< typename T, typename DefaultT >
554 inline typename result_of::extract_or_default< T, DefaultT >::type extract_or_default(
555 attribute_name const& name, attribute_value_set const& attrs, DefaultT const& def_val)
557 typedef typename result_of::extract_or_default< T, DefaultT >::extracted_type extracted_type;
558 value_extractor< extracted_type, fallback_to_default< DefaultT const& > > extractor(def_val);
559 return aux::unwrap_value_ref(extractor(name, attrs));
562 template< typename T, typename DefaultT >
563 inline typename result_of::extract_or_default< T, DefaultT >::type extract_or_default(
564 attribute_name const& name, record const& rec, DefaultT const& def_val)
566 typedef typename result_of::extract_or_default< T, DefaultT >::extracted_type extracted_type;
567 value_extractor< extracted_type, fallback_to_default< DefaultT const& > > extractor(def_val);
568 return aux::unwrap_value_ref(extractor(name, rec));
571 template< typename T, typename DefaultT >
572 inline typename result_of::extract_or_default< T, DefaultT >::type extract_or_default(
573 attribute_name const& name, record_view const& rec, DefaultT const& def_val)
575 typedef typename result_of::extract_or_default< T, DefaultT >::extracted_type extracted_type;
576 value_extractor< extracted_type, fallback_to_default< DefaultT const& > > extractor(def_val);
577 return aux::unwrap_value_ref(extractor(name, rec));
580 template< typename T, typename DefaultT >
581 inline typename result_of::extract_or_default< T, DefaultT >::type extract_or_default(attribute_value const& value, DefaultT const& def_val)
583 typedef typename result_of::extract_or_default< T, DefaultT >::extracted_type extracted_type;
584 value_extractor< extracted_type, fallback_to_default< DefaultT const& > > extractor(def_val);
585 return aux::unwrap_value_ref(extractor(value));
588 #endif // defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS)
591 * The function extracts an attribute value from the view. The user has to explicitly specify the
592 * type or set of possible types of the attribute value to be extracted.
594 * \param keyword The keyword of the attribute value to extract.
595 * \param attrs A set of attribute values in which to look for the specified attribute value.
596 * \return A \c value_ref that refers to the extracted value, if found. An empty value otherwise.
598 template< typename DescriptorT, template< typename > class ActorT >
599 inline typename result_of::extract< typename DescriptorT::value_type, DescriptorT >::type
600 extract(expressions::attribute_keyword< DescriptorT, ActorT > const& keyword, attribute_value_set const& attrs)
602 value_extractor< typename DescriptorT::value_type, fallback_to_none, DescriptorT > extractor;
603 return extractor(keyword.get_name(), attrs);
607 * The function extracts an attribute value from the view. The user has to explicitly specify the
608 * type or set of possible types of the attribute value to be extracted.
610 * \param keyword The keyword of the attribute value to extract.
611 * \param rec A log record. The attribute value will be sought among those associated with the record.
612 * \return A \c value_ref that refers to the extracted value, if found. An empty value otherwise.
614 template< typename DescriptorT, template< typename > class ActorT >
615 inline typename result_of::extract< typename DescriptorT::value_type, DescriptorT >::type
616 extract(expressions::attribute_keyword< DescriptorT, ActorT > const& keyword, record const& rec)
618 value_extractor< typename DescriptorT::value_type, fallback_to_none, DescriptorT > extractor;
619 return extractor(keyword.get_name(), rec);
623 * The function extracts an attribute value from the view. The user has to explicitly specify the
624 * type or set of possible types of the attribute value to be extracted.
626 * \param keyword The keyword of the attribute value to extract.
627 * \param rec A log record view. The attribute value will be sought among those associated with the record.
628 * \return A \c value_ref that refers to the extracted value, if found. An empty value otherwise.
630 template< typename DescriptorT, template< typename > class ActorT >
631 inline typename result_of::extract< typename DescriptorT::value_type, DescriptorT >::type
632 extract(expressions::attribute_keyword< DescriptorT, ActorT > const& keyword, record_view const& rec)
634 value_extractor< typename DescriptorT::value_type, fallback_to_none, DescriptorT > extractor;
635 return extractor(keyword.get_name(), rec);
639 * The function extracts an attribute value from the view. The user has to explicitly specify the
640 * type or set of possible types of the attribute value to be extracted.
642 * \param keyword The keyword of the attribute value to extract.
643 * \param attrs A set of attribute values in which to look for the specified attribute value.
644 * \return The extracted value or a non-empty \c value_ref that refers to the value.
645 * \throws An exception is thrown if the requested value cannot be extracted.
647 template< typename DescriptorT, template< typename > class ActorT >
648 inline typename result_of::extract_or_throw< typename DescriptorT::value_type, DescriptorT >::type
649 extract_or_throw(expressions::attribute_keyword< DescriptorT, ActorT > const& keyword, attribute_value_set const& attrs)
651 value_extractor< typename DescriptorT::value_type, fallback_to_throw, DescriptorT > extractor;
652 return aux::unwrap_value_ref(extractor(keyword.get_name(), attrs));
656 * The function extracts an attribute value from the view. The user has to explicitly specify the
657 * type or set of possible types of the attribute value to be extracted.
659 * \param keyword The keyword of the attribute value to extract.
660 * \param rec A log record. The attribute value will be sought among those associated with the record.
661 * \return The extracted value or a non-empty \c value_ref that refers to the value.
662 * \throws An exception is thrown if the requested value cannot be extracted.
664 template< typename DescriptorT, template< typename > class ActorT >
665 inline typename result_of::extract_or_throw< typename DescriptorT::value_type, DescriptorT >::type
666 extract_or_throw(expressions::attribute_keyword< DescriptorT, ActorT > const& keyword, record const& rec)
668 value_extractor< typename DescriptorT::value_type, fallback_to_throw, DescriptorT > extractor;
669 return aux::unwrap_value_ref(extractor(keyword.get_name(), rec));
673 * The function extracts an attribute value from the view. The user has to explicitly specify the
674 * type or set of possible types of the attribute value to be extracted.
676 * \param keyword The keyword of the attribute value to extract.
677 * \param rec A log record view. The attribute value will be sought among those associated with the record.
678 * \return The extracted value or a non-empty \c value_ref that refers to the value.
679 * \throws An exception is thrown if the requested value cannot be extracted.
681 template< typename DescriptorT, template< typename > class ActorT >
682 inline typename result_of::extract_or_throw< typename DescriptorT::value_type, DescriptorT >::type
683 extract_or_throw(expressions::attribute_keyword< DescriptorT, ActorT > const& keyword, record_view const& rec)
685 value_extractor< typename DescriptorT::value_type, fallback_to_throw, DescriptorT > extractor;
686 return aux::unwrap_value_ref(extractor(keyword.get_name(), rec));
690 * The function extracts an attribute value from the view. The user has to explicitly specify the
691 * type or set of possible types of the attribute value to be extracted.
693 * \note Caution must be exercised if the default value is a temporary object. Because the function returns
694 * a reference, if the temporary object is destroyed, the reference may become dangling.
696 * \param keyword The keyword of the attribute value to extract.
697 * \param attrs A set of attribute values in which to look for the specified attribute value.
698 * \param def_val The default value
699 * \return The extracted value, if found. The default value otherwise.
701 template< typename DescriptorT, template< typename > class ActorT, typename DefaultT >
702 inline typename result_of::extract_or_default< typename DescriptorT::value_type, DefaultT, DescriptorT >::type
703 extract_or_default(expressions::attribute_keyword< DescriptorT, ActorT > const& keyword, attribute_value_set const& attrs, DefaultT const& def_val)
705 typedef typename result_of::extract_or_default< typename DescriptorT::value_type, DefaultT, DescriptorT >::extracted_type extracted_type;
706 value_extractor< extracted_type, fallback_to_default< DefaultT const& >, DescriptorT > extractor(def_val);
707 return aux::unwrap_value_ref(extractor(keyword.get_name(), attrs));
711 * The function extracts an attribute value from the view. The user has to explicitly specify the
712 * type or set of possible types of the attribute value to be visited.
714 * \note Caution must be exercised if the default value is a temporary object. Because the function returns
715 * a reference, if the temporary object is destroyed, the reference may become dangling.
717 * \param keyword The keyword of the attribute value to extract.
718 * \param rec A log record. The attribute value will be sought among those associated with the record.
719 * \param def_val The default value
720 * \return The extracted value, if found. The default value otherwise.
722 template< typename DescriptorT, template< typename > class ActorT, typename DefaultT >
723 inline typename result_of::extract_or_default< typename DescriptorT::value_type, DefaultT, DescriptorT >::type
724 extract_or_default(expressions::attribute_keyword< DescriptorT, ActorT > const& keyword, record const& rec, DefaultT const& def_val)
726 typedef typename result_of::extract_or_default< typename DescriptorT::value_type, DefaultT, DescriptorT >::extracted_type extracted_type;
727 value_extractor< extracted_type, fallback_to_default< DefaultT const& >, DescriptorT > extractor(def_val);
728 return aux::unwrap_value_ref(extractor(keyword.get_name(), rec));
732 * The function extracts an attribute value from the view. The user has to explicitly specify the
733 * type or set of possible types of the attribute value to be visited.
735 * \note Caution must be exercised if the default value is a temporary object. Because the function returns
736 * a reference, if the temporary object is destroyed, the reference may become dangling.
738 * \param keyword The keyword of the attribute value to extract.
739 * \param rec A log record view. The attribute value will be sought among those associated with the record.
740 * \param def_val The default value
741 * \return The extracted value, if found. The default value otherwise.
743 template< typename DescriptorT, template< typename > class ActorT, typename DefaultT >
744 inline typename result_of::extract_or_default< typename DescriptorT::value_type, DefaultT, DescriptorT >::type
745 extract_or_default(expressions::attribute_keyword< DescriptorT, ActorT > const& keyword, record_view const& rec, DefaultT const& def_val)
747 typedef typename result_of::extract_or_default< typename DescriptorT::value_type, DefaultT, DescriptorT >::extracted_type extracted_type;
748 value_extractor< extracted_type, fallback_to_default< DefaultT const& >, DescriptorT > extractor(def_val);
749 return aux::unwrap_value_ref(extractor(keyword.get_name(), rec));
752 #if !defined(BOOST_LOG_DOXYGEN_PASS)
754 template< typename T, typename TagT >
755 inline typename result_of::extract< T, TagT >::type attribute_value::extract() const
757 return boost::log::extract< T, TagT >(*this);
760 template< typename T, typename TagT >
761 inline typename result_of::extract_or_throw< T, TagT >::type attribute_value::extract_or_throw() const
763 return boost::log::extract_or_throw< T, TagT >(*this);
766 template< typename T, typename TagT >
767 inline typename result_of::extract_or_default< T, T, TagT >::type attribute_value::extract_or_default(T const& def_value) const
769 return boost::log::extract_or_default< T, TagT >(*this, def_value);
772 template< typename T, typename TagT, typename DefaultT >
773 inline typename result_of::extract_or_default< T, DefaultT, TagT >::type attribute_value::extract_or_default(DefaultT const& def_value) const
775 return boost::log::extract_or_default< T, TagT >(*this, def_value);
778 #if defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS)
780 template< typename T >
781 inline typename result_of::extract< T >::type attribute_value::extract() const
783 return boost::log::extract< T >(*this);
786 template< typename T >
787 inline typename result_of::extract_or_throw< T >::type attribute_value::extract_or_throw() const
789 return boost::log::extract_or_throw< T >(*this);
792 template< typename T >
793 inline typename result_of::extract_or_default< T, T >::type attribute_value::extract_or_default(T const& def_value) const
795 return boost::log::extract_or_default< T >(*this, def_value);
798 template< typename T, typename DefaultT >
799 inline typename result_of::extract_or_default< T, DefaultT >::type attribute_value::extract_or_default(DefaultT const& def_value) const
801 return boost::log::extract_or_default< T >(*this, def_value);
804 #endif // defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS)
806 #endif // !defined(BOOST_LOG_DOXYGEN_PASS)
808 #undef BOOST_LOG_AUX_VOID_DEFAULT
810 BOOST_LOG_CLOSE_NAMESPACE // namespace log
814 #include <boost/log/detail/footer.hpp>
816 #endif // BOOST_LOG_ATTRIBUTES_VALUE_EXTRACTION_HPP_INCLUDED_