Collage  1.1.2
High-performance C++ library for developing object-oriented distributed applications.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
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 
38 class Serializable : public Object
39 {
40 public:
42  CO_API uint64_t getDirty() const;
43 
45  CO_API bool isDirty() const override;
46 
48  CO_API virtual bool isDirty( const uint64_t dirtyBits ) const;
49 
51  CO_API uint128_t commit( const uint32_t incarnation = CO_COMMIT_NEXT )
52  override;
53 
54 protected:
56  CO_API Serializable();
57 
62  CO_API Serializable( const Serializable& );
63 
65  CO_API virtual ~Serializable();
66 
68  Serializable& operator = ( const Serializable& from )
69  { Object::operator = ( from ); return *this; }
70 
82  virtual void serialize( co::DataOStream&, const uint64_t ){}
83 
94  virtual void deserialize( co::DataIStream&, const uint64_t ){}
95 
103  {
104  DIRTY_NONE = 0,
105  DIRTY_CUSTOM = 1,
106  DIRTY_ALL = 0xFFFFFFFFFFFFFFFFull
107  };
108 
110  CO_API virtual void setDirty( const uint64_t bits );
111 
113  CO_API virtual void unsetDirty( const uint64_t bits );
114 
116  ChangeType getChangeType() const override { return DELTA; }
117 
119  CO_API void notifyAttached() override;
120 
122  { serialize( os, DIRTY_ALL ); }
123 
124  CO_API void applyInstanceData( co::DataIStream& is ) final;
125 
126  CO_API void pack( co::DataOStream& os ) final;
127  CO_API void unpack( co::DataIStream& is ) final;
128 
129 private:
130  detail::Serializable* const _impl;
131  friend class detail::Serializable;
132 };
133 }
134 #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:38
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:94
virtual void serialize(co::DataOStream &, const uint64_t)
Worker for pack() and getInstanceData().
Definition: serializable.h:82
Serializable & operator=(const Serializable &from)
NOP assignment operator.
Definition: serializable.h:68
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:121
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:102
ChangeType getChangeType() const override
Definition: serializable.h:116
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