5 #ifndef BALL_CONCEPT_PERSISTENCEMANAGER_H
6 #define BALL_CONCEPT_PERSISTENCEMANAGER_H
8 #ifndef BALL_COMMON_RTTI_H
12 #ifndef BALL_DATATYPE_HASHMAP_H
16 #ifndef BALL_DATATYPE_STRINGHASHMAP_H
20 #ifndef BALL_DATATYPE_HASHSET_H
24 #ifndef BALL_CONCEPT_PERSISTENTOBJECT_H
28 #ifndef BALL_COMMON_GLOBAL_H
35 #include <boost/shared_ptr.hpp>
37 #define BALL_WRITE_PRIMITIVE_MEMBER(pm,x) pm.writePrimitive(x,#x)
38 #define BALL_READ_PRIMITIVE_MEMBER(pm,x) pm.readPrimitive(x,#x)
91 typedef void * (*CreateMethod) ();
171 virtual void* createObject(
String signature)
const;
177 virtual Size getNumberOfClasses()
const;
182 virtual void setOstream(::std::ostream& s);
187 virtual void setIstream(::std::istream& s);
247 template <
typename T>
248 bool checkObjectHeader(
const T& ,
const char* name = 0);
254 bool checkObjectHeader(
const char* type_name);
262 template <
typename T>
263 void writeObjectHeader(
const T*
object,
const char* name = 0);
268 void writeObjectTrailer(
const char* name = 0);
273 bool checkObjectTrailer(
const char* name = 0);
281 template <
typename T>
282 void writePrimitive(
const T& t,
const char* name);
290 template <
typename T>
291 bool readPrimitive(T& t,
const char* name);
298 template <
typename T>
299 void writeStorableObject(
const T& t,
const char* name);
307 template <
typename T>
308 bool readStorableObject(T& t,
const char* name);
315 template <
typename T>
316 void writeObjectPointer(
const T*
object,
const char* name);
324 template <
typename T>
325 bool readObjectPointer(T*&
object,
const char* name);
334 template <
typename T>
335 bool readObjectSmartPointer(boost::shared_ptr<T>& s_ptr,
const char* name);
342 template <
typename T>
343 void writeObjectReference(
const T&
object,
const char* name);
351 template <
typename T>
352 bool readObjectReference(T&
object,
const char* name);
361 template <
typename T>
362 void writeObjectArray(
const T* array,
const char* name,
Size size);
371 template <
typename T>
372 bool readObjectArray(
const T* array,
const char* name,
Size& size);
381 template <
typename T>
382 void writeObjectPointerArray(T** arr,
const char* name,
const Size size);
391 template <
typename T>
392 bool readObjectPointerArray(T** array,
const char* name,
Size& size);
414 virtual void writeHeader(
const char* type_name,
const char* name,
426 virtual bool checkHeader(
const char* type_name,
const char* name,
432 virtual void writeTrailer(
const char* name = 0) = 0;
439 virtual bool checkTrailer(
const char* name = 0) = 0;
444 virtual void writeStreamHeader() = 0;
449 virtual void writeStreamTrailer() = 0;
455 virtual bool checkStreamHeader() = 0;
461 virtual bool checkStreamTrailer() = 0;
469 virtual bool getObjectHeader(
String& type_name,
LongSize& ptr) = 0;
475 virtual void writeName(
const char* name) = 0;
482 virtual bool checkName(
const char* name) = 0;
489 virtual void writeStorableHeader(
const char* type_name,
490 const char* name) = 0;
496 virtual bool checkStorableHeader(
const char* type_name,
497 const char* name) = 0;
501 virtual void writeStorableTrailer() = 0;
507 virtual bool checkStorableTrailer() = 0;
514 virtual void writePrimitiveHeader(
const char* type_name,
515 const char* name) = 0;
522 virtual bool checkPrimitiveHeader(
const char* type_name,
523 const char* name) = 0;
527 virtual void writePrimitiveTrailer() = 0;
533 virtual bool checkPrimitiveTrailer() = 0;
540 virtual void writeObjectPointerHeader(
const char* type_name,
541 const char* name) = 0;
549 virtual bool checkObjectPointerHeader(
const char* type_name,
550 const char* name) = 0;
557 virtual void writeObjectReferenceHeader(
const char* type_name,
558 const char* name) = 0;
566 virtual bool checkObjectReferenceHeader(
const char* type_name,
567 const char* name) = 0;
575 virtual void writeObjectPointerArrayHeader(
const char* type_name,
576 const char* name,
Size size) = 0;
585 virtual bool checkObjectPointerArrayHeader(
const char* type_name,
586 const char* name,
Size& size) = 0;
591 virtual void writeObjectPointerArrayTrailer() = 0;
597 virtual bool checkObjectPointerArrayTrailer() = 0;
602 virtual void initializeOutputStream();
607 virtual void finalizeOutputStream();
612 virtual void initializeInputStream();
617 virtual void finalizeInputStream();
642 virtual void put(
const char c) = 0;
646 virtual void put(
const Byte c) = 0;
650 virtual void put(
const Index i) = 0;
654 virtual void put(
const Size p) = 0;
658 virtual void put(
const bool b) = 0;
662 virtual void put(
const Real f) = 0;
670 virtual void put(
const string& s) = 0;
674 virtual void put(
const LongSize p) = 0;
684 virtual void get(
char&
c) = 0;
688 virtual void get(
Byte& b) = 0;
692 virtual void get(
Index& s) = 0;
696 virtual void get(
Size& s) = 0;
700 virtual void get(
bool& b) = 0;
704 virtual void get(
Real&
f) = 0;
712 virtual void get(
string& s) = 0;
725 void registerKernelClasses_();
729 void addPointerPair_(
LongSize old_ptr,
void* new_ptr);
734 void addNeededObjects_();
738 bool updatePointers_();
799 template <
typename T>
804 return checkHeader(RTTI::getStreamName<T>(), name, ptr);
808 template <
typename T>
813 writeHeader(RTTI::getStreamName<T>(), name, (
LongSize)reinterpret_cast<PointerSizeUInt>(
object));
817 template <
typename T>
826 template <
typename T>
839 template <
typename T>
848 template <
typename T>
856 template <
typename T>
865 put(static_cast<LongSize>(reinterpret_cast<PointerSizeUInt>(
object)));
870 template <
typename T>
883 pointer_list_.push_back(std::make_pair((
void**)&
object, ptr));
891 template <
typename T>
910 template <
typename T>
925 template <
typename T>
945 pointer_list_.push_back(std::make_pair((
void**)&
object, ptr));
951 template <
typename T>
965 template <
typename T>
967 (
const T* array,
const char* name,
Size& size)
969 if (!checkObjectPointerArrayHeader(RTTI::getStreamName<T>(), name, size))
974 T* ptr =
const_cast<T*
>(array);
980 bool result = checkObjectPointerArrayTrailer();
984 template <
typename T>
986 (T** arr,
const char* name,
const Size size)
988 writeObjectPointerArrayHeader(RTTI::getStreamName<T>(), name, size);
994 put(static_cast<LongSize>(reinterpret_cast<PointerSizeUInt>(ptr)));
995 if (ptr != 0 && !object_out_.has(ptr))
997 object_out_needed_.push_back(ptr);
1001 writeObjectPointerArrayTrailer();
1005 template <
typename T>
1015 for (
Position i = 0; i < size; i++)
1021 pointer_list_.push_back(std::make_pair((
void**)&(array[i]), ptr));
1030 #ifndef BALL_NO_INLINE_FUNCTIONS
1031 # include <BALL/CONCEPT/persistenceManager.iC>
1036 #endif // BALL_CONCEPT_PERSISTENCEMANAGER_H