]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/log/include/boost/log/attributes/value_extraction.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / log / include / boost / log / attributes / value_extraction.hpp
CommitLineData
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 value_extraction.hpp
9 * \author Andrey Semashev
10 * \date 01.03.2008
11 *
12 * The header contains implementation of tools for extracting an attribute value
13 * from the view.
14 */
15
16#ifndef BOOST_LOG_ATTRIBUTES_VALUE_EXTRACTION_HPP_INCLUDED_
17#define BOOST_LOG_ATTRIBUTES_VALUE_EXTRACTION_HPP_INCLUDED_
18
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>
42
43#ifdef BOOST_HAS_PRAGMA_ONCE
44#pragma once
45#endif
46
47namespace boost {
48
49BOOST_LOG_OPEN_NAMESPACE
50
51namespace result_of {
52
53/*!
54 * \brief A metafunction that allows to acquire the result of the value extraction
55 *
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.
61 */
62template< typename T, typename DefaultT, typename TagT >
63struct extract_or_default
64{
65 typedef typename mpl::eval_if<
66 mpl::is_sequence< T >,
67 mpl::eval_if<
68 mpl::contains< T, DefaultT >,
69 mpl::identity< T >,
70 mpl::push_back< T, DefaultT >
71 >,
72 mpl::if_<
73 is_same< T, DefaultT >,
74 T,
75 mpl::vector2< T, DefaultT >
76 >
77 >::type extracted_type;
78
79 typedef typename mpl::if_<
80 mpl::is_sequence< extracted_type >,
81 value_ref< extracted_type, TagT >,
82 extracted_type const&
83 >::type type;
84};
85
86/*!
87 * \brief A metafunction that allows to acquire the result of the value extraction
88 *
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.
92 */
93template< typename T, typename TagT >
94struct extract_or_throw
95{
96 typedef typename mpl::if_<
97 mpl::is_sequence< T >,
98 value_ref< T, TagT >,
99 T const&
100 >::type type;
101};
102
103/*!
104 * \brief A metafunction that allows to acquire the result of the value extraction
105 *
106 * The metafunction results in a type that is in form of <tt>value_ref< T, TagT ></tt>.
107 */
108template< typename T, typename TagT >
109struct extract
110{
111 typedef value_ref< T, TagT > type;
112};
113
114} // namespace result_of
115
116namespace aux {
117
118//! The function object initializes the value reference
119template< typename RefT >
120struct value_ref_initializer
121{
122 typedef void result_type;
123
124 value_ref_initializer(RefT& ref) : m_ref(ref)
125 {
126 }
127
128 template< typename ArgT >
129 result_type operator() (ArgT const& arg) const
130 {
131 m_ref = RefT(arg);
132 }
133
134private:
135 RefT& m_ref;
136};
137
138//! The function unwraps \c value_ref, if possible
139template< typename T, typename TagT >
140BOOST_FORCEINLINE typename boost::enable_if_c< mpl::is_sequence< T >::value, value_ref< T, TagT > >::type
141unwrap_value_ref(value_ref< T, TagT > const& r)
142{
143 return r;
144}
145
146template< typename T, typename TagT >
147BOOST_FORCEINLINE typename boost::disable_if_c< mpl::is_sequence< T >::value, T const& >::type
148unwrap_value_ref(value_ref< T, TagT > const& r)
149{
150 return r.get();
151}
152
153} // namespace aux
154
155/*!
156 * \brief Generic attribute value extractor
157 *
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.
161 */
162template< typename T, typename FallbackPolicyT, typename TagT >
163class value_extractor :
164 private FallbackPolicyT
165{
166public:
167 //! Fallback policy
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;
173
174public:
175 /*!
176 * Default constructor
177 */
178 BOOST_DEFAULTED_FUNCTION(value_extractor(), {})
179
180 /*!
181 * Copy constructor
182 */
183 value_extractor(value_extractor const& that) : fallback_policy(static_cast< fallback_policy const& >(that))
184 {
185 }
186
187 /*!
188 * Constructor
189 *
190 * \param arg Fallback policy constructor argument
191 */
192 template< typename U >
193 explicit value_extractor(U const& arg) : fallback_policy(arg) {}
194
195 /*!
196 * Extraction operator. Attempts to acquire the stored value of one of the supported types. If extraction succeeds,
197 * the extracted value is returned.
198 *
199 * \param attr The attribute value to extract from.
200 * \return The extracted value, if extraction succeeded, an empty value otherwise.
201 */
202 result_type operator() (attribute_value const& attr) const
203 {
204 result_type res;
205 aux::value_ref_initializer< result_type > initializer(res);
206 if (!!attr)
207 {
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());
211 }
212 else if (!fallback_policy::apply_default(initializer))
213 {
214 fallback_policy::on_missing_value();
215 }
216 return res;
217 }
218
219 /*!
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.
223 *
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.
227 */
228 result_type operator() (attribute_name const& name, attribute_value_set const& attrs) const
229 {
230 try
231 {
232 attribute_value_set::const_iterator it = attrs.find(name);
233 if (it != attrs.end())
234 return operator() (it->second);
235 else
236 return operator() (attribute_value());
237 }
238 catch (exception& e)
239 {
240 // Attach the attribute name to the exception
241 boost::log::aux::attach_attribute_name_info(e, name);
242 throw;
243 }
244 }
245
246 /*!
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.
250 *
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.
254 */
255 result_type operator() (attribute_name const& name, record const& rec) const
256 {
257 return operator() (name, rec.attribute_values());
258 }
259
260 /*!
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.
264 *
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.
268 */
269 result_type operator() (attribute_name const& name, record_view const& rec) const
270 {
271 return operator() (name, rec.attribute_values());
272 }
273
274 /*!
275 * \returns Fallback policy
276 */
277 fallback_policy const& get_fallback_policy() const
278 {
279 return *static_cast< fallback_policy const* >(this);
280 }
281};
282
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
286#else
287#define BOOST_LOG_AUX_VOID_DEFAULT
288#endif
289#endif // !defined(BOOST_LOG_DOXYGEN_PASS)
290
291/*!
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.
294 *
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.
298 */
299template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT >
300inline typename result_of::extract< T, TagT >::type extract(attribute_name const& name, attribute_value_set const& attrs)
301{
302 value_extractor< T, fallback_to_none, TagT > extractor;
303 return extractor(name, attrs);
304}
305
306/*!
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.
309 *
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.
313 */
314template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT >
315inline typename result_of::extract< T, TagT >::type extract(attribute_name const& name, record const& rec)
316{
317 value_extractor< T, fallback_to_none, TagT > extractor;
318 return extractor(name, rec);
319}
320
321/*!
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.
324 *
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.
328 */
329template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT >
330inline typename result_of::extract< T, TagT >::type extract(attribute_name const& name, record_view const& rec)
331{
332 value_extractor< T, fallback_to_none, TagT > extractor;
333 return extractor(name, rec);
334}
335
336/*!
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.
339 *
340 * \param value Attribute value.
341 * \return A \c value_ref that refers to the extracted value, if found. An empty value otherwise.
342 */
343template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT >
344inline typename result_of::extract< T, TagT >::type extract(attribute_value const& value)
345{
346 value_extractor< T, fallback_to_none, TagT > extractor;
347 return extractor(value);
348}
349
350/*!
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.
353 *
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.
358 */
359template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT >
360inline typename result_of::extract_or_throw< T, TagT >::type extract_or_throw(attribute_name const& name, attribute_value_set const& attrs)
361{
362 value_extractor< T, fallback_to_throw, TagT > extractor;
363 return aux::unwrap_value_ref(extractor(name, attrs));
364}
365
366/*!
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.
369 *
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.
374 */
375template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT >
376inline typename result_of::extract_or_throw< T, TagT >::type extract_or_throw(attribute_name const& name, record const& rec)
377{
378 value_extractor< T, fallback_to_throw, TagT > extractor;
379 return aux::unwrap_value_ref(extractor(name, rec));
380}
381
382/*!
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.
385 *
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.
390 */
391template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT >
392inline typename result_of::extract_or_throw< T, TagT >::type extract_or_throw(attribute_name const& name, record_view const& rec)
393{
394 value_extractor< T, fallback_to_throw, TagT > extractor;
395 return aux::unwrap_value_ref(extractor(name, rec));
396}
397
398/*!
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.
401 *
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.
405 */
406template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT >
407inline typename result_of::extract_or_throw< T, TagT >::type extract_or_throw(attribute_value const& value)
408{
409 value_extractor< T, fallback_to_throw, TagT > extractor;
410 return aux::unwrap_value_ref(extractor(value));
411}
412
413/*!
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.
416 *
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.
419 *
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.
424 */
425template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT, typename DefaultT >
426inline typename result_of::extract_or_default< T, DefaultT, TagT >::type
427extract_or_default(attribute_name const& name, attribute_value_set const& attrs, DefaultT const& def_val)
428{
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));
432}
433
434/*!
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.
437 *
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.
440 *
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.
445 */
446template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT, typename DefaultT >
447inline typename result_of::extract_or_default< T, DefaultT, TagT >::type
448extract_or_default(attribute_name const& name, record const& rec, DefaultT const& def_val)
449{
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));
453}
454
455/*!
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.
458 *
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.
461 *
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.
466 */
467template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT, typename DefaultT >
468inline typename result_of::extract_or_default< T, DefaultT, TagT >::type
469extract_or_default(attribute_name const& name, record_view const& rec, DefaultT const& def_val)
470{
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));
474}
475
476/*!
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.
479 *
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.
482 *
483 * \param value Attribute value.
484 * \param def_val The default value
485 * \return The extracted value, if found. The default value otherwise.
486 */
487template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT, typename DefaultT >
488inline typename result_of::extract_or_default< T, DefaultT, TagT >::type extract_or_default(attribute_value const& value, DefaultT const& def_val)
489{
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));
493}
494
495#if defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS)
496
497template< typename T >
498inline typename result_of::extract< T >::type extract(attribute_name const& name, attribute_value_set const& attrs)
499{
500 value_extractor< T, fallback_to_none > extractor;
501 return extractor(name, attrs);
502}
503
504template< typename T >
505inline typename result_of::extract< T >::type extract(attribute_name const& name, record const& rec)
506{
507 value_extractor< T, fallback_to_none > extractor;
508 return extractor(name, rec);
509}
510
511template< typename T >
512inline typename result_of::extract< T >::type extract(attribute_name const& name, record_view const& rec)
513{
514 value_extractor< T, fallback_to_none > extractor;
515 return extractor(name, rec);
516}
517
518template< typename T >
519inline typename result_of::extract< T >::type extract(attribute_value const& value)
520{
521 value_extractor< T, fallback_to_none > extractor;
522 return extractor(value);
523}
524
525template< typename T >
526inline typename result_of::extract_or_throw< T >::type extract_or_throw(attribute_name const& name, attribute_value_set const& attrs)
527{
528 value_extractor< T, fallback_to_throw > extractor;
529 return aux::unwrap_value_ref(extractor(name, attrs));
530}
531
532template< typename T >
533inline typename result_of::extract_or_throw< T >::type extract_or_throw(attribute_name const& name, record const& rec)
534{
535 value_extractor< T, fallback_to_throw > extractor;
536 return aux::unwrap_value_ref(extractor(name, rec));
537}
538
539template< typename T >
540inline typename result_of::extract_or_throw< T >::type extract_or_throw(attribute_name const& name, record_view const& rec)
541{
542 value_extractor< T, fallback_to_throw > extractor;
543 return aux::unwrap_value_ref(extractor(name, rec));
544}
545
546template< typename T >
547inline typename result_of::extract_or_throw< T >::type extract_or_throw(attribute_value const& value)
548{
549 value_extractor< T, fallback_to_throw > extractor;
550 return aux::unwrap_value_ref(extractor(value));
551}
552
553template< typename T, typename DefaultT >
554inline 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)
556{
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));
560}
561
562template< typename T, typename DefaultT >
563inline typename result_of::extract_or_default< T, DefaultT >::type extract_or_default(
564 attribute_name const& name, record const& rec, DefaultT const& def_val)
565{
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));
569}
570
571template< typename T, typename DefaultT >
572inline 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)
574{
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));
578}
579
580template< typename T, typename DefaultT >
581inline typename result_of::extract_or_default< T, DefaultT >::type extract_or_default(attribute_value const& value, DefaultT const& def_val)
582{
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));
586}
587
588#endif // defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS)
589
590/*!
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.
593 *
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.
597 */
598template< typename DescriptorT, template< typename > class ActorT >
599inline typename result_of::extract< typename DescriptorT::value_type, DescriptorT >::type
600extract(expressions::attribute_keyword< DescriptorT, ActorT > const& keyword, attribute_value_set const& attrs)
601{
602 value_extractor< typename DescriptorT::value_type, fallback_to_none, DescriptorT > extractor;
603 return extractor(keyword.get_name(), attrs);
604}
605
606/*!
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.
609 *
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.
613 */
614template< typename DescriptorT, template< typename > class ActorT >
615inline typename result_of::extract< typename DescriptorT::value_type, DescriptorT >::type
616extract(expressions::attribute_keyword< DescriptorT, ActorT > const& keyword, record const& rec)
617{
618 value_extractor< typename DescriptorT::value_type, fallback_to_none, DescriptorT > extractor;
619 return extractor(keyword.get_name(), rec);
620}
621
622/*!
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.
625 *
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.
629 */
630template< typename DescriptorT, template< typename > class ActorT >
631inline typename result_of::extract< typename DescriptorT::value_type, DescriptorT >::type
632extract(expressions::attribute_keyword< DescriptorT, ActorT > const& keyword, record_view const& rec)
633{
634 value_extractor< typename DescriptorT::value_type, fallback_to_none, DescriptorT > extractor;
635 return extractor(keyword.get_name(), rec);
636}
637
638/*!
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.
641 *
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.
646 */
647template< typename DescriptorT, template< typename > class ActorT >
648inline typename result_of::extract_or_throw< typename DescriptorT::value_type, DescriptorT >::type
649extract_or_throw(expressions::attribute_keyword< DescriptorT, ActorT > const& keyword, attribute_value_set const& attrs)
650{
651 value_extractor< typename DescriptorT::value_type, fallback_to_throw, DescriptorT > extractor;
652 return aux::unwrap_value_ref(extractor(keyword.get_name(), attrs));
653}
654
655/*!
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.
658 *
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.
663 */
664template< typename DescriptorT, template< typename > class ActorT >
665inline typename result_of::extract_or_throw< typename DescriptorT::value_type, DescriptorT >::type
666extract_or_throw(expressions::attribute_keyword< DescriptorT, ActorT > const& keyword, record const& rec)
667{
668 value_extractor< typename DescriptorT::value_type, fallback_to_throw, DescriptorT > extractor;
669 return aux::unwrap_value_ref(extractor(keyword.get_name(), rec));
670}
671
672/*!
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.
675 *
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.
680 */
681template< typename DescriptorT, template< typename > class ActorT >
682inline typename result_of::extract_or_throw< typename DescriptorT::value_type, DescriptorT >::type
683extract_or_throw(expressions::attribute_keyword< DescriptorT, ActorT > const& keyword, record_view const& rec)
684{
685 value_extractor< typename DescriptorT::value_type, fallback_to_throw, DescriptorT > extractor;
686 return aux::unwrap_value_ref(extractor(keyword.get_name(), rec));
687}
688
689/*!
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.
692 *
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.
695 *
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.
700 */
701template< typename DescriptorT, template< typename > class ActorT, typename DefaultT >
702inline typename result_of::extract_or_default< typename DescriptorT::value_type, DefaultT, DescriptorT >::type
703extract_or_default(expressions::attribute_keyword< DescriptorT, ActorT > const& keyword, attribute_value_set const& attrs, DefaultT const& def_val)
704{
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));
708}
709
710/*!
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.
713 *
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.
716 *
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.
721 */
722template< typename DescriptorT, template< typename > class ActorT, typename DefaultT >
723inline typename result_of::extract_or_default< typename DescriptorT::value_type, DefaultT, DescriptorT >::type
724extract_or_default(expressions::attribute_keyword< DescriptorT, ActorT > const& keyword, record const& rec, DefaultT const& def_val)
725{
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));
729}
730
731/*!
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.
734 *
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.
737 *
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.
742 */
743template< typename DescriptorT, template< typename > class ActorT, typename DefaultT >
744inline typename result_of::extract_or_default< typename DescriptorT::value_type, DefaultT, DescriptorT >::type
745extract_or_default(expressions::attribute_keyword< DescriptorT, ActorT > const& keyword, record_view const& rec, DefaultT const& def_val)
746{
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));
750}
751
752#if !defined(BOOST_LOG_DOXYGEN_PASS)
753
754template< typename T, typename TagT >
755inline typename result_of::extract< T, TagT >::type attribute_value::extract() const
756{
757 return boost::log::extract< T, TagT >(*this);
758}
759
760template< typename T, typename TagT >
761inline typename result_of::extract_or_throw< T, TagT >::type attribute_value::extract_or_throw() const
762{
763 return boost::log::extract_or_throw< T, TagT >(*this);
764}
765
766template< typename T, typename TagT >
767inline typename result_of::extract_or_default< T, T, TagT >::type attribute_value::extract_or_default(T const& def_value) const
768{
769 return boost::log::extract_or_default< T, TagT >(*this, def_value);
770}
771
772template< typename T, typename TagT, typename DefaultT >
773inline typename result_of::extract_or_default< T, DefaultT, TagT >::type attribute_value::extract_or_default(DefaultT const& def_value) const
774{
775 return boost::log::extract_or_default< T, TagT >(*this, def_value);
776}
777
778#if defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS)
779
780template< typename T >
781inline typename result_of::extract< T >::type attribute_value::extract() const
782{
783 return boost::log::extract< T >(*this);
784}
785
786template< typename T >
787inline typename result_of::extract_or_throw< T >::type attribute_value::extract_or_throw() const
788{
789 return boost::log::extract_or_throw< T >(*this);
790}
791
792template< typename T >
793inline typename result_of::extract_or_default< T, T >::type attribute_value::extract_or_default(T const& def_value) const
794{
795 return boost::log::extract_or_default< T >(*this, def_value);
796}
797
798template< typename T, typename DefaultT >
799inline typename result_of::extract_or_default< T, DefaultT >::type attribute_value::extract_or_default(DefaultT const& def_value) const
800{
801 return boost::log::extract_or_default< T >(*this, def_value);
802}
803
804#endif // defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS)
805
806#endif // !defined(BOOST_LOG_DOXYGEN_PASS)
807
808#undef BOOST_LOG_AUX_VOID_DEFAULT
809
810BOOST_LOG_CLOSE_NAMESPACE // namespace log
811
812} // namespace boost
813
814#include <boost/log/detail/footer.hpp>
815
816#endif // BOOST_LOG_ATTRIBUTES_VALUE_EXTRACTION_HPP_INCLUDED_