Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:39:18

0001 /*
0002  *          Copyright Andrey Semashev 2007 - 2015.
0003  * Distributed under the Boost Software License, Version 1.0.
0004  *    (See accompanying file LICENSE_1_0.txt or copy at
0005  *          http://www.boost.org/LICENSE_1_0.txt)
0006  */
0007 /*!
0008  * \file   attribute_name.hpp
0009  * \author Andrey Semashev
0010  * \date   28.06.2010
0011  *
0012  * The header contains attribute name interface definition.
0013  */
0014 
0015 #ifndef BOOST_LOG_ATTRIBUTE_NAME_HPP_INCLUDED_
0016 #define BOOST_LOG_ATTRIBUTE_NAME_HPP_INCLUDED_
0017 
0018 #include <iosfwd>
0019 #include <string>
0020 #include <boost/assert.hpp>
0021 #include <boost/cstdint.hpp>
0022 #include <boost/core/explicit_operator_bool.hpp>
0023 #include <boost/log/detail/config.hpp>
0024 #include <boost/log/detail/header.hpp>
0025 
0026 #ifdef BOOST_HAS_PRAGMA_ONCE
0027 #pragma once
0028 #endif
0029 
0030 namespace boost {
0031 
0032 BOOST_LOG_OPEN_NAMESPACE
0033 
0034 /*!
0035  * \brief The class represents an attribute name in containers used by the library
0036  *
0037  * The class mostly serves for optimization purposes. Each attribute name that is used
0038  * with the library is automatically associated with a unique identifier, which is much
0039  * lighter in terms of memory footprint and operations complexity. This is done
0040  * transparently by this class, on object construction. Passing objects of this class
0041  * to other library methods, such as attribute lookup functions, will not require
0042  * this translation and/or string copying and thus will result in a more efficient code.
0043  */
0044 class attribute_name
0045 {
0046 public:
0047     //! String type
0048     typedef std::string string_type;
0049 #ifdef BOOST_LOG_DOXYGEN_PASS
0050     //! Associated identifier
0051     typedef unspecified id_type;
0052 #else
0053     typedef uint32_t id_type;
0054 
0055 private:
0056     class repository;
0057     friend class repository;
0058 
0059 private:
0060     //! Associated identifier
0061     id_type m_id;
0062     //! A special identifier value indicating unassigned attribute name
0063     static BOOST_CONSTEXPR_OR_CONST id_type uninitialized = ~static_cast< id_type >(0u);
0064 #endif
0065 
0066 public:
0067     /*!
0068      * Default constructor. Creates an object that does not refer to any attribute name.
0069      */
0070     BOOST_CONSTEXPR attribute_name() BOOST_NOEXCEPT : m_id(uninitialized)
0071     {
0072     }
0073     /*!
0074      * Constructs an attribute name from the specified string
0075      *
0076      * \param name An attribute name
0077      * \pre \a name is not NULL and points to a zero-terminated string
0078      */
0079     attribute_name(const char* name) :
0080         m_id(get_id_from_string(name))
0081     {
0082     }
0083     /*!
0084      * Constructs an attribute name from the specified string
0085      *
0086      * \param name An attribute name
0087      */
0088     attribute_name(string_type const& name) :
0089         m_id(get_id_from_string(name.c_str()))
0090     {
0091     }
0092 
0093     /*!
0094      * Compares the attribute names
0095      *
0096      * \return \c true if <tt>*this</tt> and \c that refer to the same attribute name,
0097      *         and \c false otherwise.
0098      */
0099     bool operator== (attribute_name const& that) const BOOST_NOEXCEPT { return m_id == that.m_id; }
0100     /*!
0101      * Compares the attribute names
0102      *
0103      * \return \c true if <tt>*this</tt> and \c that refer to different attribute names,
0104      *         and \c false otherwise.
0105      */
0106     bool operator!= (attribute_name const& that) const BOOST_NOEXCEPT { return m_id != that.m_id; }
0107 
0108     /*!
0109      * Compares the attribute names
0110      *
0111      * \return \c true if <tt>*this</tt> and \c that refer to the same attribute name,
0112      *         and \c false otherwise.
0113      */
0114     bool operator== (const char* that) const { return (m_id != uninitialized) && (this->string() == that); }
0115     /*!
0116      * Compares the attribute names
0117      *
0118      * \return \c true if <tt>*this</tt> and \c that refer to different attribute names,
0119      *         and \c false otherwise.
0120      */
0121     bool operator!= (const char* that) const { return !operator== (that); }
0122 
0123     /*!
0124      * Compares the attribute names
0125      *
0126      * \return \c true if <tt>*this</tt> and \c that refer to the same attribute name,
0127      *         and \c false otherwise.
0128      */
0129     bool operator== (string_type const& that) const { return (m_id != uninitialized) && (this->string() == that); }
0130     /*!
0131      * Compares the attribute names
0132      *
0133      * \return \c true if <tt>*this</tt> and \c that refer to different attribute names,
0134      *         and \c false otherwise.
0135      */
0136     bool operator!= (string_type const& that) const { return !operator== (that); }
0137 
0138     /*!
0139      * Checks if the object was default-constructed
0140      *
0141      * \return \c true if <tt>*this</tt> was constructed with an attribute name, \c false otherwise
0142      */
0143     BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()
0144     /*!
0145      * Checks if the object was default-constructed
0146      *
0147      * \return \c true if <tt>*this</tt> was default-constructed and does not refer to any attribute name,
0148      *         \c false otherwise
0149      */
0150     bool operator! () const BOOST_NOEXCEPT { return (m_id == uninitialized); }
0151 
0152     /*!
0153      * \return The associated id value
0154      * \pre <tt>(!*this) == false</tt>
0155      */
0156     id_type id() const BOOST_NOEXCEPT
0157     {
0158         BOOST_ASSERT(m_id != uninitialized);
0159         return m_id;
0160     }
0161     /*!
0162      * \return The attribute name string that was used during the object construction
0163      * \pre <tt>(!*this) == false</tt>
0164      */
0165     string_type const& string() const { return get_string_from_id(m_id); }
0166 
0167 private:
0168 #ifndef BOOST_LOG_DOXYGEN_PASS
0169     static BOOST_LOG_API id_type get_id_from_string(const char* name);
0170     static BOOST_LOG_API string_type const& get_string_from_id(id_type id);
0171 #endif
0172 };
0173 
0174 template< typename CharT, typename TraitsT >
0175 BOOST_LOG_API std::basic_ostream< CharT, TraitsT >& operator<< (
0176     std::basic_ostream< CharT, TraitsT >& strm,
0177     attribute_name const& name);
0178 
0179 BOOST_LOG_CLOSE_NAMESPACE // namespace log
0180 
0181 } // namespace boost
0182 
0183 #include <boost/log/detail/footer.hpp>
0184 
0185 #endif // BOOST_LOG_ATTRIBUTE_NAME_HPP_INCLUDED_