Collage  1.3.0
High-performance C++ library for developing object-oriented distributed applications.
serializable.h
1 
2 /* Copyright (c) 2009-2014, Stefan Eilemann <eile@equalizergraphics.com>
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 #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 
36 class Serializable : public Object
37 {
38 public:
40  CO_API uint64_t getDirty() const;
41 
43  CO_API bool isDirty() const override;
44 
46  CO_API virtual bool isDirty( const uint64_t dirtyBits ) const;
47 
49  CO_API uint128_t commit( const uint32_t incarnation = CO_COMMIT_NEXT )
50  override;
51 
52 protected:
54  CO_API Serializable();
55 
60  CO_API Serializable( const Serializable& );
61 
63  CO_API virtual ~Serializable();
64 
66  Serializable& operator = ( const Serializable& from )
67  { Object::operator = ( from ); return *this; }
68 
80  virtual void serialize( co::DataOStream&, const uint64_t ){}
81 
92  virtual void deserialize( co::DataIStream&, const uint64_t ){}
93 
101  {
102  DIRTY_NONE = 0,
103  DIRTY_CUSTOM = 1,
104  DIRTY_ALL = 0xFFFFFFFFFFFFFFFFull
105  };
106 
108  CO_API virtual void setDirty( const uint64_t bits );
109 
111  CO_API virtual void unsetDirty( const uint64_t bits );
112 
114  ChangeType getChangeType() const override { return DELTA; }
115 
117  CO_API void notifyAttached() override;
118 
120  { serialize( os, DIRTY_ALL ); }
121 
122  CO_API void applyInstanceData( co::DataIStream& is ) final;
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
CO_API void pack(co::DataOStream &os) final
Serialize the modifications since the last call to commit().
Base class for distributed, inheritable objects.
Definition: serializable.h:36
CO_API uint64_t getDirty() const
CO_API void notifyAttached() override
virtual CO_API ~Serializable()
Destruct the serializable.
A distributed object.
Definition: object.h:45
CO_API uint128_t commit(const uint32_t incarnation=CO_COMMIT_NEXT) override
virtual void deserialize(co::DataIStream &, const uint64_t)
Worker for unpack() and applyInstanceData().
Definition: serializable.h:92
virtual void serialize(co::DataOStream &, const uint64_t)
Worker for pack() and getInstanceData().
Definition: serializable.h:80
Serializable & operator=(const Serializable &from)
NOP assignment operator.
Definition: serializable.h:66
CO_API void applyInstanceData(co::DataIStream &is) final
Deserialize the instance data.
CO_API Serializable()
Construct a new Serializable.
ChangeType
Object change handling characteristics, see Programming Guide.
Definition: object.h:49
void getInstanceData(co::DataOStream &os) final
Serialize all instance information of this distributed object.
Definition: serializable.h:119
A std::ostream-like interface for object serialization.
Definition: dataOStream.h:48
DirtyBits
The changed parts of the serializable since the last pack().
Definition: serializable.h:100
Object-oriented network library.
Definition: barrier.h:27
ChangeType getChangeType() const override
Definition: serializable.h:114
virtual CO_API void unsetDirty(const uint64_t bits)
Remove dirty flags to clear data from distribution.
virtual CO_API void setDirty(const uint64_t bits)
Add dirty flags to mark data for distribution.
use pack/unpack delta
Definition: object.h:54
Object & operator=(const Object &)
NOP assignment operator.
Definition: object.h:434
A std::istream-like input data stream for binary data.
Definition: dataIStream.h:41
CO_API void unpack(co::DataIStream &is) final
Deserialize a change.
CO_API bool isDirty() const override