LCOV - code coverage report
Current view: top level - lunchbox - any.cpp (source / functions) Hit Total Coverage
Test: lcov2.info Lines: 29 29 100.0 %
Date: 2014-08-05 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             : 
      27             : namespace lunchbox
      28             : {
      29             : 
      30          30 : Any::Any()
      31          30 :   : content()
      32             : {
      33          30 : }
      34             : 
      35          15 : Any::Any(const Any & other)
      36          15 :   : content( other.content ? other.content->clone() : 0 )
      37             : {
      38          15 : }
      39             : 
      40          63 : Any::~Any()
      41             : {
      42          63 : }
      43             : 
      44           5 : Any& Any::swap( Any& rhs )
      45             : {
      46           5 :     std::swap( content, rhs.content );
      47           5 :     return *this;
      48             : }
      49             : 
      50           1 : Any& Any::operator=( Any rhs )
      51             : {
      52           1 :     rhs.swap(*this);
      53           1 :     return *this;
      54             : }
      55             : 
      56          96 : bool Any::empty() const
      57             : {
      58          96 :     return !content;
      59             : }
      60             : 
      61          70 : const std::type_info& Any::type() const
      62             : {
      63          70 :     return content ? content->type() : typeid(void);
      64             : }
      65             : 
      66          32 : bool Any::operator == ( const Any& rhs ) const
      67             : {
      68          32 :     if( (this == &rhs) || (empty() && rhs.empty( )))
      69           1 :         return true;
      70             : 
      71          31 :     if( empty() != rhs.empty() || type() != rhs.type( ))
      72           1 :         return false;
      73             : 
      74          30 :     return *content == *rhs.content;
      75             : }
      76             : 
      77             : 
      78           1 : bad_any_cast::bad_any_cast( const std::string& from, const std::string& to )
      79             : {
      80             :     snprintf( data, 256,
      81             :               "boost::bad_any_cast: failed conversion from %s to %s\n",
      82           1 :               from.c_str(), to.c_str( ));
      83           1 :     data[255] = 0;
      84           1 : }
      85             : 
      86          87 : }

Generated by: LCOV version 1.10