123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816 |
- #ifndef BOOST_LOG_ATTRIBUTES_VALUE_EXTRACTION_HPP_INCLUDED_
- #define BOOST_LOG_ATTRIBUTES_VALUE_EXTRACTION_HPP_INCLUDED_
- #include <boost/mpl/vector.hpp>
- #include <boost/mpl/joint_view.hpp>
- #include <boost/mpl/if.hpp>
- #include <boost/mpl/eval_if.hpp>
- #include <boost/mpl/identity.hpp>
- #include <boost/mpl/is_sequence.hpp>
- #include <boost/mpl/contains.hpp>
- #include <boost/mpl/push_back.hpp>
- #include <boost/type_traits/is_same.hpp>
- #include <boost/core/enable_if.hpp>
- #include <boost/log/detail/config.hpp>
- #include <boost/log/exceptions.hpp>
- #include <boost/log/core/record.hpp>
- #include <boost/log/attributes/attribute_name.hpp>
- #include <boost/log/attributes/attribute_value.hpp>
- #include <boost/log/attributes/attribute.hpp>
- #include <boost/log/attributes/attribute_value_set.hpp>
- #include <boost/log/attributes/value_extraction_fwd.hpp>
- #include <boost/log/attributes/fallback_policy.hpp>
- #include <boost/log/expressions/keyword_fwd.hpp>
- #include <boost/log/utility/value_ref.hpp>
- #include <boost/log/utility/type_dispatch/static_type_dispatcher.hpp>
- #include <boost/log/detail/header.hpp>
- #ifdef BOOST_HAS_PRAGMA_ONCE
- #pragma once
- #endif
- namespace boost {
- BOOST_LOG_OPEN_NAMESPACE
- namespace result_of {
- template< typename T, typename DefaultT, typename TagT >
- struct extract_or_default
- {
- typedef typename mpl::eval_if<
- mpl::is_sequence< T >,
- mpl::eval_if<
- mpl::contains< T, DefaultT >,
- mpl::identity< T >,
- mpl::push_back< T, DefaultT >
- >,
- mpl::if_<
- is_same< T, DefaultT >,
- T,
- mpl::vector2< T, DefaultT >
- >
- >::type extracted_type;
- typedef typename mpl::if_<
- mpl::is_sequence< extracted_type >,
- value_ref< extracted_type, TagT >,
- extracted_type const&
- >::type type;
- };
- template< typename T, typename TagT >
- struct extract_or_throw
- {
- typedef typename mpl::if_<
- mpl::is_sequence< T >,
- value_ref< T, TagT >,
- T const&
- >::type type;
- };
- template< typename T, typename TagT >
- struct extract
- {
- typedef value_ref< T, TagT > type;
- };
- }
- namespace aux {
- template< typename RefT >
- struct value_ref_initializer
- {
- typedef void result_type;
- value_ref_initializer(RefT& ref) : m_ref(ref)
- {
- }
- template< typename ArgT >
- result_type operator() (ArgT const& arg) const
- {
- m_ref = RefT(arg);
- }
- private:
- RefT& m_ref;
- };
- template< typename T, typename TagT >
- BOOST_FORCEINLINE typename boost::enable_if_c< mpl::is_sequence< T >::value, value_ref< T, TagT > >::type
- unwrap_value_ref(value_ref< T, TagT > const& r)
- {
- return r;
- }
- template< typename T, typename TagT >
- BOOST_FORCEINLINE typename boost::disable_if_c< mpl::is_sequence< T >::value, T const& >::type
- unwrap_value_ref(value_ref< T, TagT > const& r)
- {
- return r.get();
- }
- }
- template< typename T, typename FallbackPolicyT, typename TagT >
- class value_extractor :
- private FallbackPolicyT
- {
- public:
-
- typedef FallbackPolicyT fallback_policy;
-
- typedef T value_type;
-
- typedef value_ref< value_type, TagT > result_type;
- public:
-
- BOOST_DEFAULTED_FUNCTION(value_extractor(), {})
-
- value_extractor(value_extractor const& that) : fallback_policy(static_cast< fallback_policy const& >(that))
- {
- }
-
- template< typename U >
- explicit value_extractor(U const& arg) : fallback_policy(arg) {}
-
- result_type operator() (attribute_value const& attr) const
- {
- result_type res;
- aux::value_ref_initializer< result_type > initializer(res);
- if (!!attr)
- {
- static_type_dispatcher< value_type > disp(initializer);
- if (!attr.dispatch(disp) && !fallback_policy::apply_default(initializer))
- fallback_policy::on_invalid_type(attr.get_type());
- }
- else if (!fallback_policy::apply_default(initializer))
- {
- fallback_policy::on_missing_value();
- }
- return res;
- }
-
- result_type operator() (attribute_name const& name, attribute_value_set const& attrs) const
- {
- try
- {
- attribute_value_set::const_iterator it = attrs.find(name);
- if (it != attrs.end())
- return operator() (it->second);
- else
- return operator() (attribute_value());
- }
- catch (exception& e)
- {
-
- boost::log::aux::attach_attribute_name_info(e, name);
- throw;
- }
- }
-
- result_type operator() (attribute_name const& name, record const& rec) const
- {
- return operator() (name, rec.attribute_values());
- }
-
- result_type operator() (attribute_name const& name, record_view const& rec) const
- {
- return operator() (name, rec.attribute_values());
- }
-
- fallback_policy const& get_fallback_policy() const
- {
- return *static_cast< fallback_policy const* >(this);
- }
- };
- #if !defined(BOOST_LOG_DOXYGEN_PASS)
- #if !defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS)
- #define BOOST_LOG_AUX_VOID_DEFAULT = void
- #else
- #define BOOST_LOG_AUX_VOID_DEFAULT
- #endif
- #endif
- template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT >
- inline typename result_of::extract< T, TagT >::type extract(attribute_name const& name, attribute_value_set const& attrs)
- {
- value_extractor< T, fallback_to_none, TagT > extractor;
- return extractor(name, attrs);
- }
- template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT >
- inline typename result_of::extract< T, TagT >::type extract(attribute_name const& name, record const& rec)
- {
- value_extractor< T, fallback_to_none, TagT > extractor;
- return extractor(name, rec);
- }
- template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT >
- inline typename result_of::extract< T, TagT >::type extract(attribute_name const& name, record_view const& rec)
- {
- value_extractor< T, fallback_to_none, TagT > extractor;
- return extractor(name, rec);
- }
- template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT >
- inline typename result_of::extract< T, TagT >::type extract(attribute_value const& value)
- {
- value_extractor< T, fallback_to_none, TagT > extractor;
- return extractor(value);
- }
- template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT >
- inline typename result_of::extract_or_throw< T, TagT >::type extract_or_throw(attribute_name const& name, attribute_value_set const& attrs)
- {
- value_extractor< T, fallback_to_throw, TagT > extractor;
- return aux::unwrap_value_ref(extractor(name, attrs));
- }
- template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT >
- inline typename result_of::extract_or_throw< T, TagT >::type extract_or_throw(attribute_name const& name, record const& rec)
- {
- value_extractor< T, fallback_to_throw, TagT > extractor;
- return aux::unwrap_value_ref(extractor(name, rec));
- }
- template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT >
- inline typename result_of::extract_or_throw< T, TagT >::type extract_or_throw(attribute_name const& name, record_view const& rec)
- {
- value_extractor< T, fallback_to_throw, TagT > extractor;
- return aux::unwrap_value_ref(extractor(name, rec));
- }
- template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT >
- inline typename result_of::extract_or_throw< T, TagT >::type extract_or_throw(attribute_value const& value)
- {
- value_extractor< T, fallback_to_throw, TagT > extractor;
- return aux::unwrap_value_ref(extractor(value));
- }
- template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT, typename DefaultT >
- inline typename result_of::extract_or_default< T, DefaultT, TagT >::type
- extract_or_default(attribute_name const& name, attribute_value_set const& attrs, DefaultT const& def_val)
- {
- typedef typename result_of::extract_or_default< T, DefaultT, TagT >::extracted_type extracted_type;
- value_extractor< extracted_type, fallback_to_default< DefaultT const& >, TagT > extractor(def_val);
- return aux::unwrap_value_ref(extractor(name, attrs));
- }
- template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT, typename DefaultT >
- inline typename result_of::extract_or_default< T, DefaultT, TagT >::type
- extract_or_default(attribute_name const& name, record const& rec, DefaultT const& def_val)
- {
- typedef typename result_of::extract_or_default< T, DefaultT, TagT >::extracted_type extracted_type;
- value_extractor< extracted_type, fallback_to_default< DefaultT const& >, TagT > extractor(def_val);
- return aux::unwrap_value_ref(extractor(name, rec));
- }
- template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT, typename DefaultT >
- inline typename result_of::extract_or_default< T, DefaultT, TagT >::type
- extract_or_default(attribute_name const& name, record_view const& rec, DefaultT const& def_val)
- {
- typedef typename result_of::extract_or_default< T, DefaultT, TagT >::extracted_type extracted_type;
- value_extractor< extracted_type, fallback_to_default< DefaultT const& >, TagT > extractor(def_val);
- return aux::unwrap_value_ref(extractor(name, rec));
- }
- template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT, typename DefaultT >
- inline typename result_of::extract_or_default< T, DefaultT, TagT >::type extract_or_default(attribute_value const& value, DefaultT const& def_val)
- {
- typedef typename result_of::extract_or_default< T, DefaultT, TagT >::extracted_type extracted_type;
- value_extractor< extracted_type, fallback_to_default< DefaultT const& >, TagT > extractor(def_val);
- return aux::unwrap_value_ref(extractor(value));
- }
- #if defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS)
- template< typename T >
- inline typename result_of::extract< T >::type extract(attribute_name const& name, attribute_value_set const& attrs)
- {
- value_extractor< T, fallback_to_none > extractor;
- return extractor(name, attrs);
- }
- template< typename T >
- inline typename result_of::extract< T >::type extract(attribute_name const& name, record const& rec)
- {
- value_extractor< T, fallback_to_none > extractor;
- return extractor(name, rec);
- }
- template< typename T >
- inline typename result_of::extract< T >::type extract(attribute_name const& name, record_view const& rec)
- {
- value_extractor< T, fallback_to_none > extractor;
- return extractor(name, rec);
- }
- template< typename T >
- inline typename result_of::extract< T >::type extract(attribute_value const& value)
- {
- value_extractor< T, fallback_to_none > extractor;
- return extractor(value);
- }
- template< typename T >
- inline typename result_of::extract_or_throw< T >::type extract_or_throw(attribute_name const& name, attribute_value_set const& attrs)
- {
- value_extractor< T, fallback_to_throw > extractor;
- return aux::unwrap_value_ref(extractor(name, attrs));
- }
- template< typename T >
- inline typename result_of::extract_or_throw< T >::type extract_or_throw(attribute_name const& name, record const& rec)
- {
- value_extractor< T, fallback_to_throw > extractor;
- return aux::unwrap_value_ref(extractor(name, rec));
- }
- template< typename T >
- inline typename result_of::extract_or_throw< T >::type extract_or_throw(attribute_name const& name, record_view const& rec)
- {
- value_extractor< T, fallback_to_throw > extractor;
- return aux::unwrap_value_ref(extractor(name, rec));
- }
- template< typename T >
- inline typename result_of::extract_or_throw< T >::type extract_or_throw(attribute_value const& value)
- {
- value_extractor< T, fallback_to_throw > extractor;
- return aux::unwrap_value_ref(extractor(value));
- }
- template< typename T, typename DefaultT >
- inline typename result_of::extract_or_default< T, DefaultT >::type extract_or_default(
- attribute_name const& name, attribute_value_set const& attrs, DefaultT const& def_val)
- {
- typedef typename result_of::extract_or_default< T, DefaultT >::extracted_type extracted_type;
- value_extractor< extracted_type, fallback_to_default< DefaultT const& > > extractor(def_val);
- return aux::unwrap_value_ref(extractor(name, attrs));
- }
- template< typename T, typename DefaultT >
- inline typename result_of::extract_or_default< T, DefaultT >::type extract_or_default(
- attribute_name const& name, record const& rec, DefaultT const& def_val)
- {
- typedef typename result_of::extract_or_default< T, DefaultT >::extracted_type extracted_type;
- value_extractor< extracted_type, fallback_to_default< DefaultT const& > > extractor(def_val);
- return aux::unwrap_value_ref(extractor(name, rec));
- }
- template< typename T, typename DefaultT >
- inline typename result_of::extract_or_default< T, DefaultT >::type extract_or_default(
- attribute_name const& name, record_view const& rec, DefaultT const& def_val)
- {
- typedef typename result_of::extract_or_default< T, DefaultT >::extracted_type extracted_type;
- value_extractor< extracted_type, fallback_to_default< DefaultT const& > > extractor(def_val);
- return aux::unwrap_value_ref(extractor(name, rec));
- }
- template< typename T, typename DefaultT >
- inline typename result_of::extract_or_default< T, DefaultT >::type extract_or_default(attribute_value const& value, DefaultT const& def_val)
- {
- typedef typename result_of::extract_or_default< T, DefaultT >::extracted_type extracted_type;
- value_extractor< extracted_type, fallback_to_default< DefaultT const& > > extractor(def_val);
- return aux::unwrap_value_ref(extractor(value));
- }
- #endif
- template< typename DescriptorT, template< typename > class ActorT >
- inline typename result_of::extract< typename DescriptorT::value_type, DescriptorT >::type
- extract(expressions::attribute_keyword< DescriptorT, ActorT > const& keyword, attribute_value_set const& attrs)
- {
- value_extractor< typename DescriptorT::value_type, fallback_to_none, DescriptorT > extractor;
- return extractor(keyword.get_name(), attrs);
- }
- template< typename DescriptorT, template< typename > class ActorT >
- inline typename result_of::extract< typename DescriptorT::value_type, DescriptorT >::type
- extract(expressions::attribute_keyword< DescriptorT, ActorT > const& keyword, record const& rec)
- {
- value_extractor< typename DescriptorT::value_type, fallback_to_none, DescriptorT > extractor;
- return extractor(keyword.get_name(), rec);
- }
- template< typename DescriptorT, template< typename > class ActorT >
- inline typename result_of::extract< typename DescriptorT::value_type, DescriptorT >::type
- extract(expressions::attribute_keyword< DescriptorT, ActorT > const& keyword, record_view const& rec)
- {
- value_extractor< typename DescriptorT::value_type, fallback_to_none, DescriptorT > extractor;
- return extractor(keyword.get_name(), rec);
- }
- template< typename DescriptorT, template< typename > class ActorT >
- inline typename result_of::extract_or_throw< typename DescriptorT::value_type, DescriptorT >::type
- extract_or_throw(expressions::attribute_keyword< DescriptorT, ActorT > const& keyword, attribute_value_set const& attrs)
- {
- value_extractor< typename DescriptorT::value_type, fallback_to_throw, DescriptorT > extractor;
- return aux::unwrap_value_ref(extractor(keyword.get_name(), attrs));
- }
- template< typename DescriptorT, template< typename > class ActorT >
- inline typename result_of::extract_or_throw< typename DescriptorT::value_type, DescriptorT >::type
- extract_or_throw(expressions::attribute_keyword< DescriptorT, ActorT > const& keyword, record const& rec)
- {
- value_extractor< typename DescriptorT::value_type, fallback_to_throw, DescriptorT > extractor;
- return aux::unwrap_value_ref(extractor(keyword.get_name(), rec));
- }
- template< typename DescriptorT, template< typename > class ActorT >
- inline typename result_of::extract_or_throw< typename DescriptorT::value_type, DescriptorT >::type
- extract_or_throw(expressions::attribute_keyword< DescriptorT, ActorT > const& keyword, record_view const& rec)
- {
- value_extractor< typename DescriptorT::value_type, fallback_to_throw, DescriptorT > extractor;
- return aux::unwrap_value_ref(extractor(keyword.get_name(), rec));
- }
- template< typename DescriptorT, template< typename > class ActorT, typename DefaultT >
- inline typename result_of::extract_or_default< typename DescriptorT::value_type, DefaultT, DescriptorT >::type
- extract_or_default(expressions::attribute_keyword< DescriptorT, ActorT > const& keyword, attribute_value_set const& attrs, DefaultT const& def_val)
- {
- typedef typename result_of::extract_or_default< typename DescriptorT::value_type, DefaultT, DescriptorT >::extracted_type extracted_type;
- value_extractor< extracted_type, fallback_to_default< DefaultT const& >, DescriptorT > extractor(def_val);
- return aux::unwrap_value_ref(extractor(keyword.get_name(), attrs));
- }
- template< typename DescriptorT, template< typename > class ActorT, typename DefaultT >
- inline typename result_of::extract_or_default< typename DescriptorT::value_type, DefaultT, DescriptorT >::type
- extract_or_default(expressions::attribute_keyword< DescriptorT, ActorT > const& keyword, record const& rec, DefaultT const& def_val)
- {
- typedef typename result_of::extract_or_default< typename DescriptorT::value_type, DefaultT, DescriptorT >::extracted_type extracted_type;
- value_extractor< extracted_type, fallback_to_default< DefaultT const& >, DescriptorT > extractor(def_val);
- return aux::unwrap_value_ref(extractor(keyword.get_name(), rec));
- }
- template< typename DescriptorT, template< typename > class ActorT, typename DefaultT >
- inline typename result_of::extract_or_default< typename DescriptorT::value_type, DefaultT, DescriptorT >::type
- extract_or_default(expressions::attribute_keyword< DescriptorT, ActorT > const& keyword, record_view const& rec, DefaultT const& def_val)
- {
- typedef typename result_of::extract_or_default< typename DescriptorT::value_type, DefaultT, DescriptorT >::extracted_type extracted_type;
- value_extractor< extracted_type, fallback_to_default< DefaultT const& >, DescriptorT > extractor(def_val);
- return aux::unwrap_value_ref(extractor(keyword.get_name(), rec));
- }
- #if !defined(BOOST_LOG_DOXYGEN_PASS)
- template< typename T, typename TagT >
- inline typename result_of::extract< T, TagT >::type attribute_value::extract() const
- {
- return boost::log::extract< T, TagT >(*this);
- }
- template< typename T, typename TagT >
- inline typename result_of::extract_or_throw< T, TagT >::type attribute_value::extract_or_throw() const
- {
- return boost::log::extract_or_throw< T, TagT >(*this);
- }
- template< typename T, typename TagT >
- inline typename result_of::extract_or_default< T, T, TagT >::type attribute_value::extract_or_default(T const& def_value) const
- {
- return boost::log::extract_or_default< T, TagT >(*this, def_value);
- }
- template< typename T, typename TagT, typename DefaultT >
- inline typename result_of::extract_or_default< T, DefaultT, TagT >::type attribute_value::extract_or_default(DefaultT const& def_value) const
- {
- return boost::log::extract_or_default< T, TagT >(*this, def_value);
- }
- #if defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS)
- template< typename T >
- inline typename result_of::extract< T >::type attribute_value::extract() const
- {
- return boost::log::extract< T >(*this);
- }
- template< typename T >
- inline typename result_of::extract_or_throw< T >::type attribute_value::extract_or_throw() const
- {
- return boost::log::extract_or_throw< T >(*this);
- }
- template< typename T >
- inline typename result_of::extract_or_default< T, T >::type attribute_value::extract_or_default(T const& def_value) const
- {
- return boost::log::extract_or_default< T >(*this, def_value);
- }
- template< typename T, typename DefaultT >
- inline typename result_of::extract_or_default< T, DefaultT >::type attribute_value::extract_or_default(DefaultT const& def_value) const
- {
- return boost::log::extract_or_default< T >(*this, def_value);
- }
- #endif
- #endif
- #undef BOOST_LOG_AUX_VOID_DEFAULT
- BOOST_LOG_CLOSE_NAMESPACE
- }
- #include <boost/log/detail/footer.hpp>
- #endif
|