AGX Dynamics 2.41.2.0
Loading...
Searching...
No Matches
Serializable.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16#pragma once
17
18#include <agx/agxCore_export.h>
19
20#include <agx/Integer.h>
21#include <functional>
23#include <agx/Uuid.h>
24
25namespace agxStream
26{
27 class InputArchive;
28 class OutputArchive;
29 class StorageAgent;
30 class StorageStream;
31
45 {
46 public:
47
48#if !defined(SWIG)
50 virtual ~Serializable();
51#endif
52
57
61 bool isFinished() const;
62
64 agx::Uuid getUuid() const;
65
70 void setUuid( const agx::Uuid& uuid );
71
79 agx::UInt32 getIndex() const;
80
85 void setEnableSerialization( bool flag );
86
90 bool getEnableSerialization( ) const;
91
92#ifndef SWIG
96 virtual StorageAgent* getStorageAgent() const = 0;
97
99 virtual const char* getClassName() const;
100#endif // SWIG
101
103 static void setEnableUuidGeneration( bool flag );
104
107
108 public:
110
111#ifndef SWIG
115 virtual void storeLightData( agxStream::StorageStream& ) const {}
116
120 virtual void restoreLightData( agxStream::StorageStream& ) {}
121
122 bool _store( agxStream::OutputArchive& out ) const;
123 void _restore( agxStream::InputArchive& in );
125#endif
126 protected:
127
132#if defined(SWIG)
133 virtual ~Serializable();
134#endif
135
137
138
143 void setDynamicallyAllocated();
144
145 bool isDynamicallyAllocated() const;
146
147
148#ifndef SWIG
149 virtual void store( agxStream::OutputArchive& out ) const = 0;
150 virtual void restore( agxStream::InputArchive& in ) = 0;
151#endif
152
153 friend class InputArchive;
154 friend class OutputArchive;
155
157 void setArchive( InputArchive* archive );
158
160 InputArchive* getArchive( );
162
163 private:
164 int m_flags;
165 static StorageAgent* s_storageAgent;
166
167 enum {
168 FINISHED = 1,
169 DYNAMICALLY_ALLOCATED = 2
170 };
171
172 protected:
175
177
180
181 private:
183
184 agx::Uuid m_uuid;
185 agx::UInt32 m_index;
186 bool m_serializationEnabled;
187 static bool s_uuidGeneration_enabled;
188 };
189#ifndef SWIG
191#define AGXSTREAM_CLASS_NAME(T) \
192 \
193 inline const char* getClassName() const override { return #T; } \
194
195
196#define AGXSTREAM_DECLARE_SERIALIZABLE_BASE( T ) \
197 inline agxStream::StorageAgent* getStorageAgent() const override { return agxStream::StorageManager::instance()->find( #T ); } \
198 inline static const char* getConstructClassId() { return #T; } \
199 friend class agxStream::DefStorageAgent<T>; \
200 AGXSTREAM_CLASS_NAME(T) \
201 static agxStream::Serializable *create() { return new T(); } \
202 virtual void store( agxStream::OutputArchive& out ) const override;\
203 virtual void restore( agxStream::InputArchive& in ) override
204
208#define AGXSTREAM_DECLARE_SERIALIZABLE( T ) \
209 AGXSTREAM_DECLARE_SERIALIZABLE_BASE(T); \
210 static agxStream::Serializable *create(agxStream::InputArchive& /*in*/) { return new T(); }
211
215#define AGXSTREAM_DECLARE_SERIALIZABLE_CUSTOM_CREATE( T ) \
216 AGXSTREAM_DECLARE_SERIALIZABLE_BASE(T); \
217 static agxStream::Serializable *create(agxStream::InputArchive& in)
218
222#define AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE( T ) \
223 inline agxStream::StorageAgent* getStorageAgent() const override { return agxStream::StorageManager::instance()->find(#T); } \
224 inline static const char* getConstructClassId() { return #T; } \
225 AGXSTREAM_CLASS_NAME(T)
226
228#define AGXSTREAM_INSTANTIATE_STORAGE( C ) \
229 static agxStream::Storage<C> storage ## C;
230
232#define AGXSTREAM_INSTANTIATE_STORAGE_VARIABLE( V,C ) \
233 static agxStream::Storage<C> storage ## V;
234
235 // Macro for delaying expansion of comma (,) in a macro argument. This allows for submitting arguments such as: "first", "second" etc..
236#define AGXARCHIVE_MODIFICATIONS(...) {__VA_ARGS__}
237
238
245#define AGXSTREAM_INSTANTIATE_STORAGE_DEPRECATION_CHECK_VARIABLE( VARIABLE, NEW_CLASS, DEPRECATED_CLASS, MODIFICATION_LIST ) \
246 static agxStream::DeprecatedStorage<NEW_CLASS, DEPRECATED_CLASS> VARIABLE(MODIFICATION_LIST);
247
254#define AGXSTREAM_INSTANTIATE_STORAGE_DEPRECATED_CLASS( VARIABLE, NAMESPACE, CLASS_NAME, DEPRECATED_CLASS_NAME ) \
255namespace NAMESPACE { \
256\
257 class CLASS_NAME : public DEPRECATED_CLASS_NAME \
258 { \
259 public: \
260 CLASS_NAME() {} \
261 AGXSTREAM_DECLARE_SERIALIZABLE(NAMESPACE::CLASS_NAME); \
262 }; \
263 void CLASS_NAME::store(agxStream::OutputArchive&) const { LOGGER_ERROR() << #NAMESPACE << "::" << #CLASS_NAME << " is deprecated and should never be stored" << LOGGER_ENDL(); } \
264 void CLASS_NAME::restore(agxStream::InputArchive&) { LOGGER_ERROR() << #NAMESPACE << "::" << #CLASS_NAME << " is deprecated and should never be restored" << LOGGER_ENDL(); } \
265} \
266static agxStream::DeprecatedStorage<NAMESPACE::CLASS_NAME, DEPRECATED_CLASS_NAME> VARIABLE(AGXARCHIVE_MODIFICATIONS("\\-##-//83ddfJ4Dj"));
267
268
269
271 {
272 return m_index;
273 }
274
276 {
277 return (m_flags & FINISHED) != 0;
278 }
279
280 AGX_FORCE_INLINE bool Serializable::isDynamicallyAllocated() const
281 {
282 return (m_flags & DYNAMICALLY_ALLOCATED) != 0;
283 }
284
285
286
287
289 {
290 return m_uuid;
291 }
292
294 {
295 return m_serializationEnabled;
296 }
297
298#else
299
300 // Prevent swig from seeing macro usage of hidden macros
301 #define AGXSTREAM_DECLARE_SERIALIZABLE( T )
302 #define AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE( T )
303 #define AGXSTREAM_DECLARE_SERIALIZABLE_CUSTOM_CREATE( T )
304
305#endif // SWIG
306} // Namespace agxStream
#define AGXCORE_EXPORT
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:51
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:57
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:45
virtual const char * getClassName() const
agx::Uuid getUuid() const
Definition: Serializable.h:288
agx::UInt32 getIndex() const
This index is given at creation of this object.
Definition: Serializable.h:270
void setFinished()
Tells this class that it is restored correctly and should not be deleted during destruction of an Arc...
Serializable()
Default constructor.
void setUuid(const agx::Uuid &uuid)
Explicitly set a Uuid on a serializable object.
void setEnableSerialization(bool flag)
Set to false to disable serialization of this object.
bool getEnableSerialization() const
Definition: Serializable.h:293
Serializable(const Serializable &other)
Copy constructor.
virtual ~Serializable()
Destructor for normal C++ use but hidden from SWIG bindings.
virtual StorageAgent * getStorageAgent() const =0
static void setEnableUuidGeneration(bool flag)
Specify if there should be UUID:s generated for each new Serializable object. By default it is enable...
Abstract base class for storing/restoring a line/drums with version control.
Definition: StorageStream.h:49
A UUID, or Universally unique identifier, is intended to uniquely identify information in a distribut...
Definition: Uuid.h:42
Smart pointer for observed objects, that automatically set pointers to them to null when they deleted...
Definition: observer_ptr.h:61
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:89
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:88
#define AGX_FORCE_INLINE
Definition: macros.h:58
This namespace contain classes for streaming classes into archives, ASCII, binary for storage (serial...
uint32_t UInt32
Definition: Integer.h:32