Collage  1.7.0
High-performance C++ library for developing object-oriented distributed applications.
serializable.h
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 
39 class Serializable : public Object
40 {
41 public:
43  CO_API uint64_t getDirty() const;
44 
46  CO_API bool isDirty() const override;
47 
49  CO_API virtual bool isDirty(const uint64_t dirtyBits) const;
50 
52  CO_API uint128_t
53  commit(const uint32_t incarnation = CO_COMMIT_NEXT) override;
54 
55 protected:
57  CO_API Serializable();
58 
63  CO_API Serializable(const Serializable&);
64 
66  CO_API virtual ~Serializable();
67 
69  Serializable& operator=(const Serializable& from)
70  {
71  Object::operator=(from);
72  return *this;
73  }
74 
86  virtual void serialize(co::DataOStream&, const uint64_t) = 0;
87 
98  virtual void deserialize(co::DataIStream&, const uint64_t) = 0;
99 
107  {
108  DIRTY_NONE = 0,
109  DIRTY_CUSTOM = 1,
110  DIRTY_ALL = 0xFFFFFFFFFFFFFFFFull
111  };
112 
114  CO_API virtual void setDirty(const uint64_t bits);
115 
117  CO_API virtual void unsetDirty(const uint64_t bits);
118 
120  ChangeType getChangeType() const override { return DELTA; }
122  CO_API void notifyAttached() override;
123 
124  void getInstanceData(co::DataOStream& os) override
125  {
126  serialize(os, DIRTY_ALL);
127  }
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
Base class for distributed, inheritable objects.
Definition: serializable.h:39
CO_API std::string serialize(const ConnectionDescriptions &)
Serialize a vector of connection descriptions to a string.
A distributed object.
Definition: object.h:47
ChangeType getChangeType() const override
Definition: serializable.h:120
Serializable & operator=(const Serializable &from)
NOP assignment operator.
Definition: serializable.h:69
ChangeType
Object change handling characteristics, see Programming Guide.
Definition: object.h:51
A std::ostream-like interface for object serialization.
Definition: dataOStream.h:56
DirtyBits
The changed parts of the serializable since the last pack().
Definition: serializable.h:106
void getInstanceData(co::DataOStream &os) override
Serialize all instance information of this distributed object.
Definition: serializable.h:124
Object-oriented network library.
Definition: barrier.h:27
Object & operator=(const Object &)
NOP assignment operator.
Definition: object.h:430
A std::istream-like input data stream for binary data.
Definition: dataIStream.h:45
CO_API bool deserialize(std::string &data, ConnectionDescriptions &descriptions)
Deserialize a vector or connection descriptions from a string.