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
|
||||
Foo* f1 = new Foo();
|
||||
f1->myString = "Fo1";
|
||||
f1->myString = "Hello, i am foo 1";
|
||||
Foo* f2 = new Foo();
|
||||
f2->myString = "Fo2";
|
||||
f2->myString = "How's it goin', my name is \"Foo 2\"";
|
||||
f1->myFloatArray.clear();
|
||||
f2->myVec3 = glm::vec3(1, 2, 3);
|
||||
f1->myFoo = f2;
|
||||
f2->myFoo = nullptr;
|
||||
|
||||
// serialization
|
||||
// saving as binary
|
||||
ObjectSaver saver;
|
||||
saver.addObject(f1);
|
||||
std::fstream outFile;
|
||||
@ -57,6 +57,7 @@ int main()
|
||||
saver.saveBinary(outFile);
|
||||
outFile.close();
|
||||
|
||||
// loading as binary
|
||||
ObjectLoader loader;
|
||||
std::fstream inFile;
|
||||
inFile.open("test.bin", std::ios_base::in);
|
||||
@ -64,9 +65,8 @@ int main()
|
||||
inFile.close();
|
||||
|
||||
// print result
|
||||
const std::vector<Foo*> fooVec = loader.getObjects<Foo>();
|
||||
ObjectSaver printer;
|
||||
for(Foo* f : fooVec)
|
||||
for(Foo* f : loader.getObjects<Foo>())
|
||||
printer.addObject(f);
|
||||
printer.saveAscii(std::cout);
|
||||
|
||||
|
@ -31,10 +31,10 @@ INIT_SERIALIZABLE(MyClass)
|
||||
// ALTERNATIVE INITIALIZATION :
|
||||
|
||||
// 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(); }\
|
||||
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()); }\
|
||||
|
||||
// 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
|
||||
|
||||
#define SERIALIZABLE(className, args...)\
|
||||
#define SERIALIZABLE(className, ...)\
|
||||
virtual const std::string &getType() const { return className::getStaticType(); }\
|
||||
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 Serializable* instantiate() { return (Serializable*)(new className()); }\
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user