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

Generated by: LCOV version 1.11