Collage  1.5.0
High-performance C++ library for developing object-oriented distributed applications.
objectMap.h
1 
2 /* Copyright (c) 2012-2013, Daniel Nachbaur <danielnachbaur@googlemail.com>
3  * 2012-2014, Stefan Eilemann <eile@eyescale.ch>
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_OBJECTMAP_H
22 #define CO_OBJECTMAP_H
23 
24 #include <co/serializable.h> // base class
25 
26 namespace co
27 {
28 namespace detail { class ObjectMap; }
29 
39 class ObjectMap : public Serializable
40 {
41 public:
49  CO_API ObjectMap( ObjectHandler& handler, ObjectFactory& factory );
50 
58  CO_API virtual ~ObjectMap();
59 
71  CO_API bool register_( Object* object, const uint32_t type );
72 
84  CO_API bool deregister( Object* object );
85 
102  CO_API Object* map( const uint128_t& identifier, Object* instance = 0 );
103 
115  CO_API bool unmap( Object* object );
116 
118  CO_API void clear();
119 
121  CO_API uint128_t commit( const uint32_t incarnation =
122  CO_COMMIT_NEXT ) override;
123 
124 protected:
125  CO_API bool isDirty() const override;
126 
128  CO_API void serialize( DataOStream& os,
129  const uint64_t dirtyBits ) override;
130 
132  CO_API void deserialize( DataIStream& is,
133  const uint64_t dirtyBits ) override;
135  ChangeType getChangeType() const override { return DELTA; }
136  CO_API void notifyAttached() override;
137 
139  enum DirtyBits
140  {
141  DIRTY_ADDED = Serializable::DIRTY_CUSTOM << 0, // 1
142  DIRTY_REMOVED = Serializable::DIRTY_CUSTOM << 1, // 2
143  DIRTY_CHANGED = Serializable::DIRTY_CUSTOM << 2, // 4
144  DIRTY_CUSTOM = Serializable::DIRTY_CUSTOM << 3 // 8
145  };
146 
147 private:
148  detail::ObjectMap* const _impl;
149 
151  void _commitMasters( const uint32_t incarnation );
152 };
153 }
154 #endif // CO_OBJECTMAP_H
CO_API void deserialize(DataIStream &is, const uint64_t dirtyBits) override
Worker for unpack() and applyInstanceData().
CO_API uint128_t commit(const uint32_t incarnation=CO_COMMIT_NEXT) override
Commit all registered objects.
CO_API bool unmap(Object *object)
Unmap an object from the object map.
Base class for distributed, inheritable objects.
Definition: serializable.h:36
A distributed object.
Definition: object.h:45
ChangeType getChangeType() const override
Definition: objectMap.h:135
CO_API bool register_(Object *object, const uint32_t type)
Add and register a new object as master instance to this object map.
ChangeType
Object change handling characteristics, see Programming Guide.
Definition: object.h:49
CO_API bool deregister(Object *object)
Remove and deregister an object from this object map.
virtual CO_API ~ObjectMap()
Destroy this object map.
A std::ostream-like interface for object serialization.
Definition: dataOStream.h:48
Object-oriented network library.
Definition: barrier.h:27
A distributed object registry.
Definition: objectMap.h:39
CO_API bool isDirty() const override
Return if this object needs a commit.
Interface for entities which map and register objects.
Definition: objectHandler.h:29
The interface to create objects, used by ObjectMap.
Definition: objectFactory.h:35
CO_API void serialize(DataOStream &os, const uint64_t dirtyBits) override
Worker for pack() and getInstanceData().
CO_API void clear()
Deregister or unmap all registered and mapped objects.
CO_API void notifyAttached() override
Notify that this object has been registered or mapped.
use pack/unpack delta
Definition: object.h:54
A std::istream-like input data stream for binary data.
Definition: dataIStream.h:41
CO_API ObjectMap(ObjectHandler &handler, ObjectFactory &factory)
Construct a new object map.
CO_API Object * map(const uint128_t &identifier, Object *instance=0)
Map and return an object.