Collage  1.0.1
Object-Oriented C++ Network Library
serializable.h
1 
2 /* Copyright (c) 2009-2013, 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 virtual bool isDirty() const;
46 
48  CO_API virtual bool isDirty( const uint64_t dirtyBits ) const;
49 
51  CO_API virtual uint128_t commit( const uint32_t incarnation =
52  CO_COMMIT_NEXT );
53 
54 protected:
56  CO_API Serializable();
57 
62  CO_API Serializable( const Serializable& );
63 
65  CO_API virtual ~Serializable();
66 
78  virtual void serialize( co::DataOStream&, const uint64_t ){}
79 
90  virtual void deserialize( co::DataIStream&, const uint64_t ){}
91 
98  enum DirtyBits
99  {
100  DIRTY_NONE = 0,
101  DIRTY_CUSTOM = 1,
102  DIRTY_ALL = 0xFFFFFFFFFFFFFFFFull
103  };
104 
106  CO_API virtual void setDirty( const uint64_t bits );
107 
109  CO_API virtual void unsetDirty( const uint64_t bits );
110 
112  virtual ChangeType getChangeType() const { return DELTA; }
113 
115  CO_API virtual void notifyAttached();
116 
117 private:
118  detail::Serializable* const _impl;
119  friend class detail::Serializable;
120 
121  virtual void getInstanceData( co::DataOStream& os )
122  { serialize( os, DIRTY_ALL ); }
123 
124  CO_API virtual void applyInstanceData( co::DataIStream& is );
125 
126  CO_API virtual void pack( co::DataOStream& os );
127  CO_API virtual void unpack( co::DataIStream& is );
128 };
129 }
130 #endif // CO_SERIALIZABLE_H
virtual CO_API ~Serializable()
Destruct the serializable.
virtual void serialize(co::DataOStream &, const uint64_t)
Worker for pack() and getInstanceData().
Definition: serializable.h:78
virtual CO_API uint128_t commit(const uint32_t incarnation=CO_COMMIT_NEXT)
Base class for distributed, inheritable objects.
Definition: serializable.h:38
virtual CO_API bool isDirty() const
CO_API uint64_t getDirty() const
virtual CO_API void notifyAttached()
virtual void deserialize(co::DataIStream &, const uint64_t)
Worker for unpack() and applyInstanceData().
Definition: serializable.h:90
ChangeType
Object change handling characteristics, see Programming Guide.
Definition: object.h:49
use pack/unpack delta
Definition: object.h:54
A std::istream-like input data stream for binary data.
Definition: dataIStream.h:40
A distributed object.
Definition: object.h:45
virtual ChangeType getChangeType() const
Definition: serializable.h:112
DirtyBits
The changed parts of the serializable since the last pack().
Definition: serializable.h:98
virtual CO_API void unsetDirty(const uint64_t bits)
Remove dirty flags to clear data from distribution.
A std::ostream-like interface for object serialization.
Definition: dataOStream.h:46
virtual CO_API void setDirty(const uint64_t bits)
Add dirty flags to mark data for distribution.
CO_API Serializable()
Construct a new Serializable.