LCOV - code coverage report
Current view: top level - co - serializable.cpp (source / functions) Hit Total Coverage
Test: Collage Lines: 32 49 65.3 %
Date: 2018-01-09 16:37:03 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()
      34           2 :         : dirty(co::Serializable::DIRTY_NONE)
      35             :     {
      36           2 :     }
      37           2 :     ~Serializable() {}
      38             :     /** The current dirty bits. */
      39             :     uint64_t dirty;
      40             : };
      41             : }
      42             : 
      43           2 : Serializable::Serializable()
      44           2 :     : _impl(new detail::Serializable)
      45             : {
      46           2 : }
      47             : 
      48           0 : Serializable::Serializable(const Serializable&)
      49             :     : co::Object()
      50           0 :     , _impl(new detail::Serializable)
      51             : {
      52           0 : }
      53             : 
      54           4 : Serializable::~Serializable()
      55             : {
      56           2 :     delete _impl;
      57           2 : }
      58             : 
      59           0 : uint64_t Serializable::getDirty() const
      60             : {
      61           0 :     return _impl->dirty;
      62             : }
      63             : 
      64           3 : bool Serializable::isDirty() const
      65             : {
      66           3 :     return (_impl->dirty != DIRTY_NONE);
      67             : }
      68             : 
      69           0 : bool Serializable::isDirty(const uint64_t dirtyBits) const
      70             : {
      71           0 :     return (_impl->dirty & dirtyBits) == dirtyBits;
      72             : }
      73             : 
      74           3 : uint128_t Serializable::commit(const uint32_t incarnation)
      75             : {
      76           3 :     const uint128_t& version = co::Object::commit(incarnation);
      77           3 :     _impl->dirty = DIRTY_NONE;
      78           3 :     return version;
      79             : }
      80             : 
      81           7 : void Serializable::setDirty(const uint64_t bits)
      82             : {
      83           7 :     _impl->dirty |= bits;
      84           7 : }
      85             : 
      86           0 : void Serializable::unsetDirty(const uint64_t bits)
      87             : {
      88           0 :     _impl->dirty &= ~bits;
      89           0 : }
      90             : 
      91           0 : void Serializable::notifyAttached()
      92             : {
      93           0 :     if (isMaster())
      94           0 :         _impl->dirty = DIRTY_NONE;
      95           0 : }
      96             : 
      97           1 : void Serializable::applyInstanceData(co::DataIStream& is)
      98             : {
      99           1 :     if (!is.hasData())
     100           0 :         return;
     101           1 :     deserialize(is, DIRTY_ALL);
     102             : }
     103             : 
     104           3 : void Serializable::pack(co::DataOStream& os)
     105             : {
     106           3 :     if (_impl->dirty == DIRTY_NONE)
     107           0 :         return;
     108             : 
     109           3 :     os << _impl->dirty;
     110           3 :     serialize(os, _impl->dirty);
     111             : }
     112             : 
     113           3 : void Serializable::unpack(co::DataIStream& is)
     114             : {
     115           3 :     LBASSERT(is.hasData());
     116           3 :     if (!is.hasData())
     117           0 :         return;
     118             : 
     119             :     uint64_t dirty;
     120           3 :     is >> dirty;
     121           3 :     deserialize(is, dirty);
     122             : }
     123          63 : }

Generated by: LCOV version 1.11