LCOV - code coverage report
Current view: top level - co - serializable.cpp (source / functions) Hit Total Coverage
Test: Collage Lines: 30 47 63.8 %
Date: 2016-12-14 01:26:48 Functions: 12 18 66.7 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2012-2014, Stefan Eilemann <eile@eyescale.ch>
       3             :  *               2010, Daniel Nachbaur <danielnachbaur@gmail.com>
       4             :  *
       5             :  * This file is part of Collage <https://github.com/Eyescale/Collage>
       6             :  *
       7             :  * This library is free software; you can redistribute it and/or modify it under
       8             :  * the terms of the GNU Lesser General Public License version 2.1 as published
       9             :  * by the Free Software Foundation.
      10             :  *
      11             :  * This library is distributed in the hope that it will be useful, but WITHOUT
      12             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      13             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      14             :  * details.
      15             :  *
      16             :  * You should have received a copy of the GNU Lesser General Public License
      17             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      18             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      19             :  */
      20             : 
      21             : #include "serializable.h"
      22             : 
      23             : #include "dataIStream.h"
      24             : #include "dataOStream.h"
      25             : 
      26             : namespace co
      27             : {
      28             : namespace detail
      29             : {
      30             : class Serializable
      31             : {
      32             : public:
      33           2 :     Serializable() : dirty( co::Serializable::DIRTY_NONE ) {}
      34           2 :     ~Serializable() {}
      35             : 
      36             :     /** The current dirty bits. */
      37             :     uint64_t dirty;
      38             : };
      39             : }
      40             : 
      41           2 : Serializable::Serializable()
      42           2 :         : _impl( new detail::Serializable )
      43           2 : {}
      44             : 
      45           0 : Serializable::Serializable( const Serializable& )
      46             :     : co::Object()
      47           0 :     , _impl( new detail::Serializable )
      48           0 : {}
      49             : 
      50           4 : Serializable::~Serializable()
      51             : {
      52           2 :     delete _impl;
      53           2 : }
      54             : 
      55           0 : uint64_t Serializable::getDirty() const
      56             : {
      57           0 :     return _impl->dirty;
      58             : }
      59             : 
      60           3 : bool Serializable::isDirty() const
      61             : {
      62           3 :     return ( _impl->dirty != DIRTY_NONE );
      63             : }
      64             : 
      65           0 : bool Serializable::isDirty( const uint64_t dirtyBits ) const
      66             : {
      67           0 :     return (_impl->dirty & dirtyBits) == dirtyBits;
      68             : }
      69             : 
      70           3 : uint128_t Serializable::commit( const uint32_t incarnation )
      71             : {
      72           3 :     const uint128_t& version = co::Object::commit( incarnation );
      73           3 :     _impl->dirty = DIRTY_NONE;
      74           3 :     return version;
      75             : }
      76             : 
      77           7 : void Serializable::setDirty( const uint64_t bits )
      78             : {
      79           7 :     _impl->dirty |= bits;
      80           7 : }
      81             : 
      82           0 : void Serializable::unsetDirty( const uint64_t bits )
      83             : {
      84           0 :     _impl->dirty &= ~bits;
      85           0 : }
      86             : 
      87           0 : void Serializable::notifyAttached()
      88             : {
      89           0 :     if( isMaster( ))
      90           0 :         _impl->dirty = DIRTY_NONE;
      91           0 : }
      92             : 
      93           1 : void Serializable::applyInstanceData( co::DataIStream& is )
      94             : {
      95           1 :     if( !is.hasData( ))
      96           0 :         return;
      97           1 :     deserialize( is, DIRTY_ALL );
      98             : }
      99             : 
     100           3 : void Serializable::pack( co::DataOStream& os )
     101             : {
     102           3 :     if( _impl->dirty == DIRTY_NONE )
     103           0 :         return;
     104             : 
     105           3 :     os << _impl->dirty;
     106           3 :     serialize( os, _impl->dirty );
     107             : }
     108             : 
     109           3 : void Serializable::unpack( co::DataIStream& is )
     110             : {
     111           3 :     LBASSERT( is.hasData( ));
     112           3 :     if( !is.hasData( ))
     113           0 :         return;
     114             : 
     115             :     uint64_t dirty;
     116           3 :     is >> dirty;
     117           3 :     deserialize( is, dirty );
     118             : }
     119             : 
     120          66 : }

Generated by: LCOV version 1.11