AGX Dynamics 2.42.1.1
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>
22#include <agx/Uuid.h>
23
24namespace agxStream
25{
26 class InputArchive;
27 class OutputArchive;
28 class StorageAgent;
29 class StorageStream;
30
44 {
45 public:
46
47#if !defined(SWIG)
49 virtual ~Serializable();
50#endif
51
56
60 bool isFinished() const;
61
63 agx::Uuid getUuid() const;
64
69 void setUuid( const agx::Uuid& uuid );
70
78 agx::UInt32 getIndex() const;
79
84 void setEnableSerialization( bool flag );
85
89 bool getEnableSerialization( ) const;
90
91#ifndef SWIG
95 virtual StorageAgent* getStorageAgent() const = 0;
96
98 virtual const char* getClassName() const;
99#endif // SWIG
100
102 static void setEnableUuidGeneration( bool flag );
103
106
107 public:
109
110#ifndef SWIG
114 virtual void storeLightData( agxStream::StorageStream& ) const {}
115
119 virtual void restoreLightData( agxStream::StorageStream& ) {}
120
121 bool _store( agxStream::OutputArchive& out ) const;
122 void _restore( agxStream::InputArchive& in );
124#endif
125 protected:
126
131#if defined(SWIG)
132 virtual ~Serializable();
133#endif
134
136
137
142 void setDynamicallyAllocated();
143
144 bool isDynamicallyAllocated() const;
145
146
147#ifndef SWIG
148 virtual void store( agxStream::OutputArchive& out ) const = 0;
149 virtual void restore( agxStream::InputArchive& in ) = 0;
150#endif
151
152 friend class InputArchive;
153 friend class OutputArchive;
154
156 void setArchive( InputArchive* archive );
157
159 InputArchive* getArchive( );
161
162 private:
163 int m_flags;
164 static StorageAgent* s_storageAgent;
165
166 enum {
167 FINISHED = 1,
168 DYNAMICALLY_ALLOCATED = 2
169 };
170
171 protected:
174
176
179
180 private:
182
183 agx::Uuid m_uuid;
184 agx::UInt32 m_index;
185 bool m_serializationEnabled;
186 static bool s_uuidGeneration_enabled;
187 };
188#ifndef SWIG
190#define AGXSTREAM_CLASS_NAME(T) \
191 \
192 inline const char* getClassName() const override { return #T; } \
193
194
195#define AGXSTREAM_DECLARE_SERIALIZABLE_BASE( T ) \
196 inline agxStream::StorageAgent* getStorageAgent() const override { return agxStream::StorageManager::instance()->find( #T ); } \
197 inline static const char* getConstructClassId() { return #T; } \
198 friend class agxStream::DefStorageAgent<T>; \
199 AGXSTREAM_CLASS_NAME(T) \
200 static agxStream::Serializable *create() { return new T(); } \
201 virtual void store( agxStream::OutputArchive& out ) const override;\
202 virtual void restore( agxStream::InputArchive& in ) override
203
207#define AGXSTREAM_DECLARE_SERIALIZABLE( T ) \
208 AGXSTREAM_DECLARE_SERIALIZABLE_BASE(T); \
209 static agxStream::Serializable *create(agxStream::InputArchive& /*in*/) { return new T(); }
210
214#define AGXSTREAM_DECLARE_SERIALIZABLE_CUSTOM_CREATE( T ) \
215 AGXSTREAM_DECLARE_SERIALIZABLE_BASE(T); \
216 static agxStream::Serializable *create(agxStream::InputArchive& in)
217
221#define AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE( T ) \
222 inline agxStream::StorageAgent* getStorageAgent() const override { return agxStream::StorageManager::instance()->find(#T); } \
223 inline static const char* getConstructClassId() { return #T; } \
224 AGXSTREAM_CLASS_NAME(T)
225
227#define AGXSTREAM_INSTANTIATE_STORAGE( C ) \
228 static agxStream::Storage<C> storage ## C;
229
231#define AGXSTREAM_INSTANTIATE_STORAGE_VARIABLE( V,C ) \
232 static agxStream::Storage<C> storage ## V;
233
234 // Macro for delaying expansion of comma (,) in a macro argument. This allows for submitting arguments such as: "first", "second" etc..
235#define AGXARCHIVE_MODIFICATIONS(...) {__VA_ARGS__}
236
237
244#define AGXSTREAM_INSTANTIATE_STORAGE_DEPRECATION_CHECK_VARIABLE( VARIABLE, NEW_CLASS, DEPRECATED_CLASS, MODIFICATION_LIST ) \
245 static agxStream::DeprecatedStorage<NEW_CLASS, DEPRECATED_CLASS> VARIABLE(MODIFICATION_LIST);
246
253#define AGXSTREAM_INSTANTIATE_STORAGE_DEPRECATED_CLASS( VARIABLE, NAMESPACE, CLASS_NAME, DEPRECATED_CLASS_NAME ) \
254namespace NAMESPACE { \
255\
256 class CLASS_NAME : public DEPRECATED_CLASS_NAME \
257 { \
258 public: \
259 CLASS_NAME() {} \
260 AGXSTREAM_DECLARE_SERIALIZABLE(NAMESPACE::CLASS_NAME); \
261 }; \
262 void CLASS_NAME::store(agxStream::OutputArchive&) const { LOGGER_ERROR() << #NAMESPACE << "::" << #CLASS_NAME << " is deprecated and should never be stored" << LOGGER_ENDL(); } \
263 void CLASS_NAME::restore(agxStream::InputArchive&) { LOGGER_ERROR() << #NAMESPACE << "::" << #CLASS_NAME << " is deprecated and should never be restored" << LOGGER_ENDL(); } \
264} \
265static agxStream::DeprecatedStorage<NAMESPACE::CLASS_NAME, DEPRECATED_CLASS_NAME> VARIABLE(AGXARCHIVE_MODIFICATIONS("\\-##-//83ddfJ4Dj"));
266
267
268
270 {
271 return m_index;
272 }
273
275 {
276 return (m_flags & FINISHED) != 0;
277 }
278
279 AGX_FORCE_INLINE bool Serializable::isDynamicallyAllocated() const
280 {
281 return (m_flags & DYNAMICALLY_ALLOCATED) != 0;
282 }
283
284
285
286
288 {
289 return m_uuid;
290 }
291
293 {
294 return m_serializationEnabled;
295 }
296
297#else
298
299 // Prevent swig from seeing macro usage of hidden macros
300 #define AGXSTREAM_DECLARE_SERIALIZABLE( T )
301 #define AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE( T )
302 #define AGXSTREAM_DECLARE_SERIALIZABLE_CUSTOM_CREATE( T )
303
304#endif // SWIG
305} // 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:44
virtual const char * getClassName() const
agx::Uuid getUuid() const
Definition: Serializable.h:287
agx::UInt32 getIndex() const
This index is given at creation of this object.
Definition: Serializable.h:269
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:292
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