LCOV - code coverage report
Current view: top level - co - serializable.h (source / functions) Hit Total Coverage
Test: Collage Lines: 2 3 66.7 %
Date: 2016-12-14 01:26:48 Functions: 1 2 50.0 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2009-2016, Stefan Eilemann <eile@equalizergraphics.com>
       3             :  *                          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             : #ifndef CO_SERIALIZABLE_H
      22             : #define CO_SERIALIZABLE_H
      23             : 
      24             : #include <co/object.h>        // base class
      25             : 
      26             : namespace co
      27             : {
      28             : namespace detail { class Serializable; }
      29             : 
      30             : /**
      31             :  * Base class for distributed, inheritable objects.
      32             :  *
      33             :  * This class implements one usage pattern of Object, which allows subclassing
      34             :  * and serialization of distributed Objects using dirty bits.
      35             :  */
      36             : class Serializable : public Object
      37             : {
      38             : public:
      39             :     /** @return the current dirty bit mask. @version 1.0 */
      40             :     CO_API uint64_t getDirty() const;
      41             : 
      42             :     /** @return true if the serializable has to be committed. @version 1.0 */
      43             :     CO_API bool isDirty() const override;
      44             : 
      45             :     /** @return true if the given dirty bits are set. @version 1.0 */
      46             :     CO_API virtual bool isDirty( const uint64_t dirtyBits ) const;
      47             : 
      48             :     /** @sa Object::commit() */
      49             :     CO_API uint128_t commit( const uint32_t incarnation = CO_COMMIT_NEXT )
      50             :         override;
      51             : 
      52             : protected:
      53             :     /** Construct a new Serializable. @version 1.0 */
      54             :     CO_API Serializable();
      55             : 
      56             :     /**
      57             :      * Construct an unmapped, unregistered copy of a serializable.
      58             :      * @version 1.0
      59             :      */
      60             :     CO_API Serializable( const Serializable& );
      61             : 
      62             :     /** Destruct the serializable. @version 1.0 */
      63             :     CO_API virtual ~Serializable();
      64             : 
      65             :     /** NOP assignment operator. @version 1.1.1 */
      66             :     Serializable& operator = ( const Serializable& from )
      67             :         { Object::operator = ( from ); return *this; }
      68             : 
      69             :     /**
      70             :      * Worker for pack() and getInstanceData().
      71             :      *
      72             :      * Override this and deserialize() to distribute subclassed data.
      73             :      *
      74             :      * This method is called with DIRTY_ALL from getInstanceData() and with
      75             :      * the actual dirty bits from pack(), which also resets the dirty state
      76             :      * afterwards. The dirty bits are transmitted beforehand, and do not
      77             :      * need to be transmitted by the overriding method.
      78             :      * @version 1.0
      79             :      */
      80             :     virtual void serialize( co::DataOStream&, const uint64_t ) = 0;
      81             : 
      82             :     /**
      83             :      * Worker for unpack() and applyInstanceData().
      84             :      *
      85             :      * This function is called with the dirty bits send by the master
      86             :      * instance. The dirty bits are received beforehand, and do not need to
      87             :      * be deserialized by the overriding method.
      88             :      *
      89             :      * @sa serialize()
      90             :      * @version 1.0
      91             :      */
      92             :     virtual void deserialize( co::DataIStream&, const uint64_t ) = 0;
      93             : 
      94             :     /**
      95             :      * The changed parts of the serializable since the last pack().
      96             :      *
      97             :      * Subclasses should define their own bits, starting at DIRTY_CUSTOM.
      98             :      * @version 1.0
      99             :      */
     100             :     enum DirtyBits
     101             :     {
     102             :         DIRTY_NONE       = 0,
     103             :         DIRTY_CUSTOM     = 1,
     104             :         DIRTY_ALL        = 0xFFFFFFFFFFFFFFFFull
     105             :     };
     106             : 
     107             :     /** Add dirty flags to mark data for distribution. @version 1.0 */
     108             :     CO_API virtual void setDirty( const uint64_t bits );
     109             : 
     110             :     /** Remove dirty flags to clear data from distribution. @version 1.0 */
     111             :     CO_API virtual void unsetDirty( const uint64_t bits );
     112             : 
     113             :     /** @sa Object::getChangeType() */
     114           0 :     ChangeType getChangeType() const override { return DELTA; }
     115             : 
     116             :     /** @sa Object::notifyAttached() */
     117             :     CO_API void notifyAttached() override;
     118             : 
     119           4 :     void getInstanceData( co::DataOStream& os ) override
     120           4 :         { serialize( os, DIRTY_ALL ); }
     121             : 
     122             :     CO_API void applyInstanceData( co::DataIStream& is ) override;
     123             : 
     124             :     CO_API void pack( co::DataOStream& os ) final;
     125             :     CO_API void unpack( co::DataIStream& is ) final;
     126             : 
     127             : private:
     128             :     detail::Serializable* const _impl;
     129             :     friend class detail::Serializable;
     130             : };
     131             : }
     132             : #endif // CO_SERIALIZABLE_H

Generated by: LCOV version 1.11