fixed vnamed variadic macro not allowed
This commit is contained in:
parent
5d9bd6de45
commit
4d1c310489
10
src/main.cpp
10
src/main.cpp
@ -41,15 +41,15 @@ int main()
|
|||||||
{
|
{
|
||||||
// init
|
// init
|
||||||
Foo* f1 = new Foo();
|
Foo* f1 = new Foo();
|
||||||
f1->myString = "Fo1";
|
f1->myString = "Hello, i am foo 1";
|
||||||
Foo* f2 = new Foo();
|
Foo* f2 = new Foo();
|
||||||
f2->myString = "Fo2";
|
f2->myString = "How's it goin', my name is \"Foo 2\"";
|
||||||
f1->myFloatArray.clear();
|
f1->myFloatArray.clear();
|
||||||
f2->myVec3 = glm::vec3(1, 2, 3);
|
f2->myVec3 = glm::vec3(1, 2, 3);
|
||||||
f1->myFoo = f2;
|
f1->myFoo = f2;
|
||||||
f2->myFoo = nullptr;
|
f2->myFoo = nullptr;
|
||||||
|
|
||||||
// serialization
|
// saving as binary
|
||||||
ObjectSaver saver;
|
ObjectSaver saver;
|
||||||
saver.addObject(f1);
|
saver.addObject(f1);
|
||||||
std::fstream outFile;
|
std::fstream outFile;
|
||||||
@ -57,6 +57,7 @@ int main()
|
|||||||
saver.saveBinary(outFile);
|
saver.saveBinary(outFile);
|
||||||
outFile.close();
|
outFile.close();
|
||||||
|
|
||||||
|
// loading as binary
|
||||||
ObjectLoader loader;
|
ObjectLoader loader;
|
||||||
std::fstream inFile;
|
std::fstream inFile;
|
||||||
inFile.open("test.bin", std::ios_base::in);
|
inFile.open("test.bin", std::ios_base::in);
|
||||||
@ -64,9 +65,8 @@ int main()
|
|||||||
inFile.close();
|
inFile.close();
|
||||||
|
|
||||||
// print result
|
// print result
|
||||||
const std::vector<Foo*> fooVec = loader.getObjects<Foo>();
|
|
||||||
ObjectSaver printer;
|
ObjectSaver printer;
|
||||||
for(Foo* f : fooVec)
|
for(Foo* f : loader.getObjects<Foo>())
|
||||||
printer.addObject(f);
|
printer.addObject(f);
|
||||||
printer.saveAscii(std::cout);
|
printer.saveAscii(std::cout);
|
||||||
|
|
||||||
|
@ -31,10 +31,10 @@ INIT_SERIALIZABLE(MyClass)
|
|||||||
// ALTERNATIVE INITIALIZATION :
|
// ALTERNATIVE INITIALIZATION :
|
||||||
|
|
||||||
// use this if you really can't have a cpp file for your class
|
// use this if you really can't have a cpp file for your class
|
||||||
#define MANUAL_SERIALIZABLE(className, args...)\
|
#define MANUAL_SERIALIZABLE(className, ...)\
|
||||||
virtual const std::string &getType() const { return className::getStaticType(); }\
|
virtual const std::string &getType() const { return className::getStaticType(); }\
|
||||||
static const std::string &getStaticType() { static const std::string name = #className; return name; }\
|
static const std::string &getStaticType() { static const std::string name = #className; return name; }\
|
||||||
virtual PropertySet* getProperties() const { return initProperties(new PropertySet(), args); }\
|
virtual PropertySet* getProperties() const { return initProperties(new PropertySet(), __VA_ARGS__); }\
|
||||||
static Serializable* instantiate() { return (Serializable*)(new className()); }\
|
static Serializable* instantiate() { return (Serializable*)(new className()); }\
|
||||||
|
|
||||||
// can be called to init the class manually whenever you want in your program (before any deserialization of this class)
|
// can be called to init the class manually whenever you want in your program (before any deserialization of this class)
|
||||||
@ -42,10 +42,10 @@ INIT_SERIALIZABLE(MyClass)
|
|||||||
|
|
||||||
// RECOMMENDED INITIALIZATION
|
// RECOMMENDED INITIALIZATION
|
||||||
|
|
||||||
#define SERIALIZABLE(className, args...)\
|
#define SERIALIZABLE(className, ...)\
|
||||||
virtual const std::string &getType() const { return className::getStaticType(); }\
|
virtual const std::string &getType() const { return className::getStaticType(); }\
|
||||||
static const std::string &getStaticType() { static const std::string name = #className; return name; }\
|
static const std::string &getStaticType() { static const std::string name = #className; return name; }\
|
||||||
virtual PropertySet* getProperties() const { return initProperties(new PropertySet(), args); }\
|
virtual PropertySet* getProperties() const { return initProperties(new PropertySet(), __VA_ARGS__); }\
|
||||||
static bool init;\
|
static bool init;\
|
||||||
static Serializable* instantiate() { return (Serializable*)(new className()); }\
|
static Serializable* instantiate() { return (Serializable*)(new className()); }\
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user