diff --git a/src/main.cpp b/src/main.cpp index 4823388..13a2568 100644 --- a/src/main.cpp +++ b/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 fooVec = loader.getObjects(); ObjectSaver printer; - for(Foo* f : fooVec) + for(Foo* f : loader.getObjects()) printer.addObject(f); printer.saveAscii(std::cout); diff --git a/src/serializable.h b/src/serializable.h index 2968165..7a9cfcb 100644 --- a/src/serializable.h +++ b/src/serializable.h @@ -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()); }\