LCOV - code coverage report
Current view: top level - lunchbox - any.cpp (source / functions) Hit Total Coverage
Test: Lunchbox Lines: 30 30 100.0 %
Date: 2018-10-03 05:33:11 Functions: 11 11 100.0 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2012, Daniel Nachbaur <daniel.nachbaur@gmail.com>
       3             :  *
       4             :  * This library is free software; you can redistribute it and/or modify it under
       5             :  * the terms of the GNU Lesser General Public License version 3.0 as published
       6             :  * by the Free Software Foundation.
       7             :  *
       8             :  * This library is distributed in the hope that it will be useful, but WITHOUT
       9             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      10             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      11             :  * details.
      12             :  *
      13             :  * You should have received a copy of the GNU Lesser General Public License
      14             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      15             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      16             :  */
      17             : 
      18             : #include "any.h"
      19             : 
      20             : #include <cstdio>
      21             : 
      22             : #ifdef WIN32
      23             : #define snprintf _snprintf_s
      24             : #endif
      25             : 
      26             : namespace lunchbox
      27             : {
      28          30 : Any::Any()
      29          30 :     : content()
      30             : {
      31          30 : }
      32             : 
      33          15 : Any::Any(const Any& other)
      34          15 :     : content(other.content ? other.content->clone() : 0)
      35             : {
      36          15 : }
      37             : 
      38          63 : Any::~Any()
      39             : {
      40          63 : }
      41             : 
      42           5 : Any& Any::swap(Any& rhs)
      43             : {
      44           5 :     std::swap(content, rhs.content);
      45           5 :     return *this;
      46             : }
      47             : 
      48           1 : Any& Any::operator=(Any rhs)
      49             : {
      50           1 :     rhs.swap(*this);
      51           1 :     return *this;
      52             : }
      53             : 
      54          96 : bool Any::empty() const
      55             : {
      56          96 :     return !content;
      57             : }
      58             : 
      59          70 : const std::type_info& Any::type() const
      60             : {
      61          70 :     return content ? content->type() : typeid(void);
      62             : }
      63             : 
      64          32 : bool Any::operator==(const Any& rhs) const
      65             : {
      66          32 :     if ((this == &rhs) || (empty() && rhs.empty()))
      67           1 :         return true;
      68             : 
      69          31 :     if (empty() != rhs.empty() || type() != rhs.type())
      70           1 :         return false;
      71             : 
      72          30 :     return *content == *rhs.content;
      73             : }
      74             : 
      75           1 : bad_any_cast::bad_any_cast(const std::string& from, const std::string& to)
      76             : {
      77           1 :     snprintf(data, 256,
      78             :              "boost::bad_any_cast: failed conversion from %s to %s\n",
      79           1 :              from.c_str(), to.c_str());
      80           1 :     data[255] = 0;
      81           1 : }
      82          75 : }

Generated by: LCOV version 1.11