Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r86582 - in trunk: boost/log/core libs/log/test/run
From: andrey.semashev_at_[hidden]
Date: 2013-11-07 16:22:28


Author: andysem
Date: 2013-11-07 16:22:27 EST (Thu, 07 Nov 2013)
New Revision: 86582
URL: http://svn.boost.org/trac/boost/changeset/86582

Log:
Added a test for add_value manipulator. Added operator[] overloads for attibute_name as key.

Added:
   trunk/libs/log/test/run/util_manip_add_value.cpp (contents, props changed)
Text files modified:
   trunk/boost/log/core/record.hpp | 11 ++++
   trunk/boost/log/core/record_view.hpp | 11 ++++
   trunk/libs/log/test/run/util_manip_add_value.cpp | 99 ++++++++++++++++++++++++++++++++++++++++
   trunk/libs/log/test/run/util_manip_dump.cpp | 2
   4 files changed, 122 insertions(+), 1 deletions(-)

Modified: trunk/boost/log/core/record.hpp
==============================================================================
--- trunk/boost/log/core/record.hpp Thu Nov 7 16:18:57 2013 (r86581)
+++ trunk/boost/log/core/record.hpp 2013-11-07 16:22:27 EST (Thu, 07 Nov 2013) (r86582)
@@ -158,6 +158,17 @@
     /*!
      * Attribute value lookup.
      *
+ * \param name Attribute name.
+ * \return An \c attribute_value, non-empty if it is found, empty otherwise.
+ */
+ attribute_value_set::mapped_type operator[] (attribute_value_set::key_type name) const
+ {
+ return m_impl->m_attribute_values[name];
+ }
+
+ /*!
+ * Attribute value lookup.
+ *
      * \param keyword Attribute keyword.
      * \return A \c value_ref with extracted attribute value if it is found, empty \c value_ref otherwise.
      */

Modified: trunk/boost/log/core/record_view.hpp
==============================================================================
--- trunk/boost/log/core/record_view.hpp Thu Nov 7 16:18:57 2013 (r86581)
+++ trunk/boost/log/core/record_view.hpp 2013-11-07 16:22:27 EST (Thu, 07 Nov 2013) (r86582)
@@ -221,6 +221,17 @@
     /*!
      * Attribute value lookup.
      *
+ * \param name Attribute name.
+ * \return An \c attribute_value, non-empty if it is found, empty otherwise.
+ */
+ attribute_value_set::mapped_type operator[] (attribute_value_set::key_type name) const
+ {
+ return m_impl->m_attribute_values[name];
+ }
+
+ /*!
+ * Attribute value lookup.
+ *
      * \param keyword Attribute keyword.
      * \return A \c value_ref with extracted attribute value if it is found, empty \c value_ref otherwise.
      */

Added: trunk/libs/log/test/run/util_manip_add_value.cpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libs/log/test/run/util_manip_add_value.cpp 2013-11-07 16:22:27 EST (Thu, 07 Nov 2013) (r86582)
@@ -0,0 +1,99 @@
+/*
+ * Copyright Andrey Semashev 2007 - 2013.
+ * Distributed under the Boost Software License, Version 1.0.
+ * (See accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ */
+/*!
+ * \file util_manip_add_value.cpp
+ * \author Andrey Semashev
+ * \date 07.11.2013
+ *
+ * \brief This header contains tests for the \c add_value manipulator.
+ */
+
+#define BOOST_TEST_MODULE util_manip_add_value
+
+#include <iomanip>
+#include <iostream>
+#include <boost/move/core.hpp>
+#include <boost/io/ios_state.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/log/core.hpp>
+#include <boost/log/sources/record_ostream.hpp>
+#include <boost/log/attributes/attribute_set.hpp>
+#include <boost/log/attributes/value_extraction.hpp>
+#include <boost/log/expressions/keyword.hpp>
+#include <boost/log/utility/manipulators/add_value.hpp>
+#include "make_record.hpp"
+
+namespace logging = boost::log;
+
+struct my_type
+{
+ BOOST_COPYABLE_AND_MOVABLE(my_type)
+
+public:
+ unsigned int value;
+
+ explicit my_type(unsigned int n = 0) : value(n) {}
+ my_type(my_type const& that) : value(that.value) {}
+ my_type(BOOST_RV_REF(my_type) that) : value(that.value) { that.value = 0xbaadbaad; }
+ ~my_type() { value = 0xdeaddead; }
+
+ my_type& operator= (BOOST_COPY_ASSIGN_REF(my_type) that) { value = that.value; return *this; }
+ my_type& operator= (BOOST_RV_REF(my_type) that) { value = that.value; that.value = 0xbaadbaad; return *this; }
+};
+
+inline bool operator== (my_type const& left, my_type const& right)
+{
+ return left.value == right.value;
+}
+
+inline bool operator!= (my_type const& left, my_type const& right)
+{
+ return left.value != right.value;
+}
+
+template< typename CharT, typename TraitsT >
+inline std::basic_ostream< CharT, TraitsT >& operator<< (std::basic_ostream< CharT, TraitsT >& strm, my_type const& val)
+{
+ if (strm.good())
+ {
+ boost::io::ios_flags_saver flags(strm);
+ boost::io::basic_ios_fill_saver< CharT, TraitsT > fill(strm);
+ strm << std::hex << std::internal << std::setfill(static_cast< CharT >('0')) << std::setw(10) << val.value;
+ }
+ return strm;
+}
+
+BOOST_AUTO_TEST_CASE(manual_add_attr)
+{
+ logging::record rec = make_record(logging::attribute_set());
+ BOOST_REQUIRE(!!rec);
+ logging::record_ostream strm(rec);
+
+ my_type val(0xaaaaaaaa);
+ strm << logging::add_value("MyAttr1", val) << logging::add_value("MyAttr2", my_type(0xbbbbbbbb));
+ strm.detach_from_record();
+
+ BOOST_CHECK_EQUAL(rec["MyAttr1"].extract< my_type >(), val);
+ BOOST_CHECK_EQUAL(rec["MyAttr2"].extract< my_type >(), my_type(0xbbbbbbbb));
+}
+
+BOOST_LOG_ATTRIBUTE_KEYWORD(a_my1, "MyAttr1", my_type)
+BOOST_LOG_ATTRIBUTE_KEYWORD(a_my2, "MyAttr2", my_type)
+
+BOOST_AUTO_TEST_CASE(keyword_add_attr)
+{
+ logging::record rec = make_record(logging::attribute_set());
+ BOOST_REQUIRE(!!rec);
+ logging::record_ostream strm(rec);
+
+ my_type val(0xaaaaaaaa);
+ strm << logging::add_value(a_my1, val) << logging::add_value(a_my2, my_type(0xbbbbbbbb));
+ strm.detach_from_record();
+
+ BOOST_CHECK_EQUAL(rec[a_my1], val);
+ BOOST_CHECK_EQUAL(rec[a_my2], my_type(0xbbbbbbbb));
+}

Modified: trunk/libs/log/test/run/util_manip_dump.cpp
==============================================================================
--- trunk/libs/log/test/run/util_manip_dump.cpp Thu Nov 7 16:18:57 2013 (r86581)
+++ trunk/libs/log/test/run/util_manip_dump.cpp 2013-11-07 16:22:27 EST (Thu, 07 Nov 2013) (r86582)
@@ -9,7 +9,7 @@
  * \author Andrey Semashev
  * \date 09.01.2009
  *
- * \brief This header contains tests for the string literals wrapper.
+ * \brief This header contains tests for the dump manipulator.
  */
 
 #define BOOST_TEST_MODULE util_manip_dump


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk