Collage  1.6.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 { 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 ) = 0;
81 
92  virtual void deserialize( co::DataIStream&, const uint64_t ) = 0;
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 
119  void getInstanceData( co::DataOStream& os ) override
120  { serialize( os, DIRTY_ALL ); }
121 
122  CO_API void applyInstanceData( co::DataIStream& is ) override;
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
Base class for distributed, inheritable objects.
Definition: serializable.h:36
CO_API std::string serialize(const ConnectionDescriptions &)
Serialize a vector of connection descriptions to a string.
A distributed object.
Definition: object.h:45
ChangeType getChangeType() const override
Definition: serializable.h:114
ChangeType
Object change handling characteristics, see Programming Guide.
Definition: object.h:49
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
void getInstanceData(co::DataOStream &os) override
Serialize all instance information of this distributed object.
Definition: serializable.h:119
Object-oriented network library.
Definition: barrier.h:27
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 bool deserialize(std::string &data, ConnectionDescriptions &descriptions)
Deserialize a vector or connection descriptions from a string.