|
Shinya Kitaoka |
810553 |
#pragma once
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TPERSIST_INCLUDED
|
|
Toshihiro Shimizu |
890ddd |
#define TPERSIST_INCLUDED
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//#include "tsmartpointer.h"
|
|
Toshihiro Shimizu |
890ddd |
//#include "tpixel.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tcommon.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#undef DVAPI
|
|
Toshihiro Shimizu |
890ddd |
#undef DVVAR
|
|
Toshihiro Shimizu |
890ddd |
#ifdef TSTREAM_EXPORTS
|
|
Toshihiro Shimizu |
890ddd |
#define DVAPI DV_EXPORT_API
|
|
Toshihiro Shimizu |
890ddd |
#define DVVAR DV_EXPORT_VAR
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
#define DVAPI DV_IMPORT_API
|
|
Toshihiro Shimizu |
890ddd |
#define DVVAR DV_IMPORT_VAR
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//===================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class TPersistDeclaration;
|
|
Toshihiro Shimizu |
890ddd |
class TIStream;
|
|
Toshihiro Shimizu |
890ddd |
class TOStream;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//===================================================================
|
|
Shinya Kitaoka |
120a6e |
//! This is an abstract class for load and save data from and to the file system
|
|
Shinya Kitaoka |
120a6e |
//! (i.e files on the disk)
|
|
Shinya Kitaoka |
120a6e |
class DVAPI TPersist {
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
virtual ~TPersist(){};
|
|
Shinya Kitaoka |
120a6e |
/*!
|
|
Shinya Kitaoka |
120a6e |
This is a pure virtual function and must be overridden with a method
|
|
Shinya Kitaoka |
120a6e |
that implements
|
|
Shinya Kitaoka |
120a6e |
the object loading from a stream (i.e take the object's features from
|
|
Shinya Kitaoka |
120a6e |
a formatted data stream).
|
|
Shinya Kitaoka |
120a6e |
For example the TStageObject class use his implementation to take the
|
|
Shinya Kitaoka |
120a6e |
values of the parameters
|
|
Shinya Kitaoka |
120a6e |
that characterizes a stage object as name, coordinates, etc... from a
|
|
Shinya Kitaoka |
120a6e |
file.
|
|
Shinya Kitaoka |
120a6e |
\a is is an input file stream
|
|
Shinya Kitaoka |
120a6e |
*/
|
|
Shinya Kitaoka |
120a6e |
virtual void loadData(TIStream &is) = 0;
|
|
Shinya Kitaoka |
120a6e |
/*!
|
|
Shinya Kitaoka |
120a6e |
This is a pure virtual function and must be overridden with a method
|
|
Shinya Kitaoka |
120a6e |
that implements
|
|
Shinya Kitaoka |
120a6e |
the object saving to a data stream (i.e put the object's features on a
|
|
Shinya Kitaoka |
120a6e |
formatted data stream).
|
|
Shinya Kitaoka |
120a6e |
For example the TStageObject class use his implementation to save the
|
|
Shinya Kitaoka |
120a6e |
values of the parameters
|
|
Shinya Kitaoka |
120a6e |
that characterizes a stage object as name, coordinates, etc... on a
|
|
Shinya Kitaoka |
120a6e |
file
|
|
Shinya Kitaoka |
120a6e |
\a os is an output file stream.
|
|
Shinya Kitaoka |
120a6e |
*/
|
|
Shinya Kitaoka |
120a6e |
virtual void saveData(TOStream &os) = 0;
|
|
Shinya Kitaoka |
120a6e |
/*!
|
|
Shinya Kitaoka |
120a6e |
Returns the string identifier of the object. For example a TXsheet
|
|
Shinya Kitaoka |
120a6e |
object is identified by "xsheet",
|
|
Shinya Kitaoka |
120a6e |
a TStageObjectTree is identified by PegbarTree.
|
|
Shinya Kitaoka |
120a6e |
*/
|
|
Shinya Kitaoka |
120a6e |
inline std::string getStreamTag() const;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/*!
|
|
Shinya Kitaoka |
120a6e |
This pure virtual method is used to define a global pointer to the
|
|
Shinya Kitaoka |
120a6e |
object.
|
|
Shinya Kitaoka |
120a6e |
This method is overridden with the macro PERSIST_DECLARATION(T).
|
|
Shinya Kitaoka |
120a6e |
\n For example:
|
|
Shinya Kitaoka |
120a6e |
\code
|
|
Shinya Kitaoka |
d1f6c4 |
class DVAPI TStageObjectTree final : public TPersist {
|
|
Toshihiro Shimizu |
890ddd |
PERSIST_DECLARATION(TStageObjectTree)
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
...
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
\endcode
|
|
Shinya Kitaoka |
120a6e |
*/
|
|
Shinya Kitaoka |
120a6e |
virtual const TPersistDeclaration *getDeclaration() const = 0;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
typedef TPersist *CreateProc();
|
|
Shinya Kitaoka |
120a6e |
static void declare(CreateProc *);
|
|
Shinya Kitaoka |
120a6e |
/*!
|
|
Shinya Kitaoka |
120a6e |
If the object identified by \a name doesn't exist,
|
|
Shinya Kitaoka |
120a6e |
this method creates it through TPersistDeclarationT class template.
|
|
Shinya Kitaoka |
120a6e |
\sa getDeclaration()
|
|
Shinya Kitaoka |
120a6e |
*/
|
|
Shinya Kitaoka |
120a6e |
static TPersist *create(const std::string &name);
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//===================================================================
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Shinya Kitaoka |
120a6e |
This class is used to store and retrieve the id associated to an
|
|
Shinya Kitaoka |
120a6e |
object.
|
|
Shinya Kitaoka |
120a6e |
\sa TPersist::getStreamTag().
|
|
Shinya Kitaoka |
120a6e |
The class is istantiated by the macro PERSIST_DECLARATION(T).
|
|
Shinya Kitaoka |
120a6e |
*/
|
|
Shinya Kitaoka |
120a6e |
class DVAPI TPersistDeclaration {
|
|
Shinya Kitaoka |
120a6e |
std::string m_id;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
TPersistDeclaration(const std::string &id);
|
|
Shinya Kitaoka |
120a6e |
virtual ~TPersistDeclaration() {}
|
|
Shinya Kitaoka |
120a6e |
std::string getId() const { return m_id; };
|
|
Shinya Kitaoka |
120a6e |
virtual TPersist *create() const = 0;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
inline std::string TPersist::getStreamTag() const {
|
|
Shinya Kitaoka |
120a6e |
return getDeclaration()->getId();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Shinya Kitaoka |
120a6e |
This template class is used to create an istance of the class \a
|
|
Shinya Kitaoka |
120a6e |
T.
|
|
Shinya Kitaoka |
120a6e |
*/
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Shinya Kitaoka |
d1f6c4 |
class TPersistDeclarationT final : public TPersistDeclaration {
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
/*!
|
|
Shinya Kitaoka |
120a6e |
This is the constructor. Its argument is the id of the object.
|
|
Shinya Kitaoka |
120a6e |
\sa TPersist::getStreamTag()
|
|
Shinya Kitaoka |
120a6e |
*/
|
|
Shinya Kitaoka |
120a6e |
TPersistDeclarationT(const std::string &id) : TPersistDeclaration(id) {}
|
|
Shinya Kitaoka |
120a6e |
/*!
|
|
Shinya Kitaoka |
120a6e |
Returns a pointer to a newly created object of type TPersist.
|
|
Shinya Kitaoka |
120a6e |
This template class is called by the macro PERSIST_DECLARATION(T).
|
|
Shinya Kitaoka |
120a6e |
A class that calls PERSIST_DECLARATION(T) must inherits TPersist.
|
|
Shinya Kitaoka |
120a6e |
*/
|
|
Shinya Kitaoka |
473e70 |
TPersist *create() const override { return new T; };
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
/*! \file tpersist.h
|
|
Shinya Kitaoka |
120a6e |
*/
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Shinya Kitaoka |
120a6e |
This macro must be included at the beginning of a class
|
|
Shinya Kitaoka |
120a6e |
declaration,
|
|
Shinya Kitaoka |
120a6e |
and permits to create a new object of type T with the use of
|
|
Shinya Kitaoka |
120a6e |
template
|
|
Shinya Kitaoka |
120a6e |
class TPersistDeclarationT
|
|
Shinya Kitaoka |
120a6e |
*/
|
|
Shinya Kitaoka |
120a6e |
#define PERSIST_DECLARATION(T) \
|
|
Shinya Kitaoka |
120a6e |
\
|
|
Shinya Kitaoka |
120a6e |
private: \
|
|
Shinya Kitaoka |
120a6e |
static TPersistDeclarationT<t> m_declaration; \</t>
|
|
Shinya Kitaoka |
120a6e |
\
|
|
Shinya Kitaoka |
120a6e |
public: \
|
|
Shinya Kitaoka |
d1f6c4 |
const TPersistDeclaration *getDeclaration() const override { \
|
|
Shinya Kitaoka |
d1f6c4 |
return &m_declaration; \
|
|
Shinya Kitaoka |
d1f6c4 |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
#define PERSIST_IDENTIFIER(T, I) TPersistDeclarationT<t> T::m_declaration(I);</t>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//===================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif
|