diff --git a/src/main.cpp b/src/main.cpp index 13a2568..8687263 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,11 +9,11 @@ class Foo : public Serializable { public: - INT (myInt) - STRING (myString) - VECTOR_FLOAT(myFloatArray) - VEC3 (myVec3) - REFERENCE (Foo, myFoo) + P_INT (myInt) + P_STRING (myString) + P_VECTOR_FLOAT(myFloatArray) + P_VEC3 (myVec3) + P_REFERENCE (Foo, myFoo) SERIALIZABLE(Foo, CAST(myInt), diff --git a/src/property.cpp b/src/property.cpp index 409187e..6417b23 100644 --- a/src/property.cpp +++ b/src/property.cpp @@ -2,107 +2,107 @@ #include "serializable.h" // INTEGER PROPERTY -template <> std::ostream& Property::saveBinary(std::ostream& os) { return os.write((char*)&value, sizeof(int)); } -template <> std::ostream& Property::saveAscii(std::ostream& os) { return os << value; } -template <> std::istream& Property::loadBinary(std::istream& is) { return is.read((char*)&value, sizeof(int)); } -template <> std::istream& Property::loadAscii(std::istream& is) { return is >> value; } +template <> std::ostream& Property::saveBinary(std::ostream& os) { return os.write((char*)&m_value, sizeof(int)); } +template <> std::ostream& Property::saveAscii(std::ostream& os) { return os << m_value; } +template <> std::istream& Property::loadBinary(std::istream& is) { return is.read((char*)&m_value, sizeof(int)); } +template <> std::istream& Property::loadAscii(std::istream& is) { return is >> m_value; } template <> AbstractProperty::PropertyType Property::getStaticPropertyType() { return AbstractProperty::INTEGER; } // FLOAT PROPERTY -template <> std::ostream& Property::saveBinary(std::ostream& os) { return os.write((char*)&value, sizeof(float)); } -template <> std::ostream& Property::saveAscii(std::ostream& os) { return os << value; } -template <> std::istream& Property::loadBinary(std::istream& is) { return is.read((char*)&value, sizeof(float)); } -template <> std::istream& Property::loadAscii(std::istream& is) { return is >> value; } +template <> std::ostream& Property::saveBinary(std::ostream& os) { return os.write((char*)&m_value, sizeof(float)); } +template <> std::ostream& Property::saveAscii(std::ostream& os) { return os << m_value; } +template <> std::istream& Property::loadBinary(std::istream& is) { return is.read((char*)&m_value, sizeof(float)); } +template <> std::istream& Property::loadAscii(std::istream& is) { return is >> m_value; } template <> AbstractProperty::PropertyType Property::getStaticPropertyType() { return AbstractProperty::FLOAT; } // BOOLEAN PROPERTY -template <> std::ostream& Property::saveBinary(std::ostream& os) { return os.write((char*)&value, sizeof(bool)); } -template <> std::ostream& Property::saveAscii(std::ostream& os) { return os << value; } -template <> std::istream& Property::loadBinary(std::istream& is) { return is.read((char*)&value, sizeof(bool)); } -template <> std::istream& Property::loadAscii(std::istream& is) { return is >> value; } +template <> std::ostream& Property::saveBinary(std::ostream& os) { return os.write((char*)&m_value, sizeof(bool)); } +template <> std::ostream& Property::saveAscii(std::ostream& os) { return os << m_value; } +template <> std::istream& Property::loadBinary(std::istream& is) { return is.read((char*)&m_value, sizeof(bool)); } +template <> std::istream& Property::loadAscii(std::istream& is) { return is >> m_value; } template <> AbstractProperty::PropertyType Property::getStaticPropertyType() { return AbstractProperty::BOOLEAN; } // UNSIGNED INTEGER PROPERTY -template <> std::ostream& Property::saveBinary(std::ostream& os) { return os.write((char*)&value, sizeof(unsigned int)); } -template <> std::ostream& Property::saveAscii(std::ostream& os) { return os << value; } -template <> std::istream& Property::loadBinary(std::istream& is) { return is.read((char*)&value, sizeof(unsigned int)); } -template <> std::istream& Property::loadAscii(std::istream& is) { return is >> value; } +template <> std::ostream& Property::saveBinary(std::ostream& os) { return os.write((char*)&m_value, sizeof(unsigned int)); } +template <> std::ostream& Property::saveAscii(std::ostream& os) { return os << m_value; } +template <> std::istream& Property::loadBinary(std::istream& is) { return is.read((char*)&m_value, sizeof(unsigned int)); } +template <> std::istream& Property::loadAscii(std::istream& is) { return is >> m_value; } template <> AbstractProperty::PropertyType Property::getStaticPropertyType() { return AbstractProperty::UNSIGNED_INTEGER; } // BYTE PROPERTY -template <> std::ostream& Property::saveBinary(std::ostream& os) { return os.write((char*)&value, sizeof(char)); } -template <> std::ostream& Property::saveAscii(std::ostream& os) { return os << value; } -template <> std::istream& Property::loadBinary(std::istream& is) { return is.read((char*)&value, sizeof(char)); } -template <> std::istream& Property::loadAscii(std::istream& is) { return is >> value; } +template <> std::ostream& Property::saveBinary(std::ostream& os) { return os.write((char*)&m_value, sizeof(char)); } +template <> std::ostream& Property::saveAscii(std::ostream& os) { return os << m_value; } +template <> std::istream& Property::loadBinary(std::istream& is) { return is.read((char*)&m_value, sizeof(char)); } +template <> std::istream& Property::loadAscii(std::istream& is) { return is >> m_value; } template <> AbstractProperty::PropertyType Property::getStaticPropertyType() { return AbstractProperty::BYTE; } // SHORT PROPERTY -template <> std::ostream& Property::saveBinary(std::ostream& os) { return os.write((char*)&value, sizeof(short)); } -template <> std::ostream& Property::saveAscii(std::ostream& os) { return os << value; } -template <> std::istream& Property::loadBinary(std::istream& is) { return is.read((char*)&value, sizeof(short)); } -template <> std::istream& Property::loadAscii(std::istream& is) { return is >> value; } +template <> std::ostream& Property::saveBinary(std::ostream& os) { return os.write((char*)&m_value, sizeof(short)); } +template <> std::ostream& Property::saveAscii(std::ostream& os) { return os << m_value; } +template <> std::istream& Property::loadBinary(std::istream& is) { return is.read((char*)&m_value, sizeof(short)); } +template <> std::istream& Property::loadAscii(std::istream& is) { return is >> m_value; } template <> AbstractProperty::PropertyType Property::getStaticPropertyType() { return AbstractProperty::SHORT; } // LONG PROPERTY -template <> std::ostream& Property::saveBinary(std::ostream& os) { return os.write((char*)&value, sizeof(long)); } -template <> std::ostream& Property::saveAscii(std::ostream& os) { return os << value; } -template <> std::istream& Property::loadBinary(std::istream& is) { return is.read((char*)&value, sizeof(long)); } -template <> std::istream& Property::loadAscii(std::istream& is) { return is >> value; } +template <> std::ostream& Property::saveBinary(std::ostream& os) { return os.write((char*)&m_value, sizeof(long)); } +template <> std::ostream& Property::saveAscii(std::ostream& os) { return os << m_value; } +template <> std::istream& Property::loadBinary(std::istream& is) { return is.read((char*)&m_value, sizeof(long)); } +template <> std::istream& Property::loadAscii(std::istream& is) { return is >> m_value; } template <> AbstractProperty::PropertyType Property::getStaticPropertyType() { return AbstractProperty::LONG; } // DOUBLE PROPERTY -template <> std::ostream& Property::saveBinary(std::ostream& os) { return os.write((char*)&value, sizeof(double)); } -template <> std::ostream& Property::saveAscii(std::ostream& os) { return os << value; } -template <> std::istream& Property::loadBinary(std::istream& is) { return is.read((char*)&value, sizeof(double)); } -template <> std::istream& Property::loadAscii(std::istream& is) { return is >> value; } +template <> std::ostream& Property::saveBinary(std::ostream& os) { return os.write((char*)&m_value, sizeof(double)); } +template <> std::ostream& Property::saveAscii(std::ostream& os) { return os << m_value; } +template <> std::istream& Property::loadBinary(std::istream& is) { return is.read((char*)&m_value, sizeof(double)); } +template <> std::istream& Property::loadAscii(std::istream& is) { return is >> m_value; } template <> AbstractProperty::PropertyType Property::getStaticPropertyType() { return AbstractProperty::DOUBLE; } // VEC2 PROPERTY -template <> std::ostream& Property::saveBinary(std::ostream& os) { return os.write((char*)glm::value_ptr(value), sizeof(float)*value.length()); } -template <> std::ostream& Property::saveAscii(std::ostream& os) { os << "["; for(int i=0; i std::istream& Property::loadBinary(std::istream& is) { return is.read((char*)glm::value_ptr(value), sizeof(float)*value.length()); } -template <> std::istream& Property::loadAscii(std::istream& is) { is.ignore(1); for(int i=0; i> (glm::value_ptr(value)[i]), is.ignore(1); return is; } +template <> std::ostream& Property::saveBinary(std::ostream& os) { return os.write((char*)glm::value_ptr(m_value), sizeof(float)*m_value.length()); } +template <> std::ostream& Property::saveAscii(std::ostream& os) { os << "["; for(int i=0; i std::istream& Property::loadBinary(std::istream& is) { return is.read((char*)glm::value_ptr(m_value), sizeof(float)*m_value.length()); } +template <> std::istream& Property::loadAscii(std::istream& is) { is.ignore(1); for(int i=0; i> (glm::value_ptr(m_value)[i]), is.ignore(1); return is; } template <> AbstractProperty::PropertyType Property::getStaticPropertyType() { return AbstractProperty::VEC2; } // VEC3 PROPERTY -template <> std::ostream& Property::saveBinary(std::ostream& os) { return os.write((char*)glm::value_ptr(value), sizeof(float)*value.length()); } -template <> std::ostream& Property::saveAscii(std::ostream& os) { os << "["; for(int i=0; i std::istream& Property::loadBinary(std::istream& is) { return is.read((char*)glm::value_ptr(value), sizeof(float)*value.length()); } -template <> std::istream& Property::loadAscii(std::istream& is) { is.ignore(1); for(int i=0; i> (glm::value_ptr(value)[i]), is.ignore(1); return is; } +template <> std::ostream& Property::saveBinary(std::ostream& os) { return os.write((char*)glm::value_ptr(m_value), sizeof(float)*m_value.length()); } +template <> std::ostream& Property::saveAscii(std::ostream& os) { os << "["; for(int i=0; i std::istream& Property::loadBinary(std::istream& is) { return is.read((char*)glm::value_ptr(m_value), sizeof(float)*m_value.length()); } +template <> std::istream& Property::loadAscii(std::istream& is) { is.ignore(1); for(int i=0; i> (glm::value_ptr(m_value)[i]), is.ignore(1); return is; } template <> AbstractProperty::PropertyType Property::getStaticPropertyType() { return AbstractProperty::VEC3; } // VEC4 PROPERTY -template <> std::ostream& Property::saveBinary(std::ostream& os) { return os.write((char*)glm::value_ptr(value), sizeof(float)*value.length()); } -template <> std::ostream& Property::saveAscii(std::ostream& os) { os << "["; for(int i=0; i std::istream& Property::loadBinary(std::istream& is) { return is.read((char*)glm::value_ptr(value), sizeof(float)*value.length()); } -template <> std::istream& Property::loadAscii(std::istream& is) { is.ignore(1); for(int i=0; i> (glm::value_ptr(value)[i]), is.ignore(1); return is; } +template <> std::ostream& Property::saveBinary(std::ostream& os) { return os.write((char*)glm::value_ptr(m_value), sizeof(float)*m_value.length()); } +template <> std::ostream& Property::saveAscii(std::ostream& os) { os << "["; for(int i=0; i std::istream& Property::loadBinary(std::istream& is) { return is.read((char*)glm::value_ptr(m_value), sizeof(float)*m_value.length()); } +template <> std::istream& Property::loadAscii(std::istream& is) { is.ignore(1); for(int i=0; i> (glm::value_ptr(m_value)[i]), is.ignore(1); return is; } template <> AbstractProperty::PropertyType Property::getStaticPropertyType() { return AbstractProperty::VEC4; } // MAT3 PROPERTY -template <> std::ostream& Property::saveBinary(std::ostream& os) { return os.write((char*)glm::value_ptr(value), sizeof(float)*value.length()); } -template <> std::ostream& Property::saveAscii(std::ostream& os) { os << "["; for(int i=0; i std::istream& Property::loadBinary(std::istream& is) { return is.read((char*)glm::value_ptr(value), sizeof(float)*value.length()); } -template <> std::istream& Property::loadAscii(std::istream& is) { is.ignore(1); for(int i=0; i> (glm::value_ptr(value)[i]), is.ignore(1); return is; } +template <> std::ostream& Property::saveBinary(std::ostream& os) { return os.write((char*)glm::value_ptr(m_value), sizeof(float)*m_value.length()); } +template <> std::ostream& Property::saveAscii(std::ostream& os) { os << "["; for(int i=0; i std::istream& Property::loadBinary(std::istream& is) { return is.read((char*)glm::value_ptr(m_value), sizeof(float)*m_value.length()); } +template <> std::istream& Property::loadAscii(std::istream& is) { is.ignore(1); for(int i=0; i> (glm::value_ptr(m_value)[i]), is.ignore(1); return is; } template <> AbstractProperty::PropertyType Property::getStaticPropertyType() { return AbstractProperty::MAT3; } // MAT4 PROPERTY -template <> std::ostream& Property::saveBinary(std::ostream& os) { return os.write((char*)glm::value_ptr(value), sizeof(float)*value.length()); } -template <> std::ostream& Property::saveAscii(std::ostream& os) { os << "["; for(int i=0; i std::istream& Property::loadBinary(std::istream& is) { return is.read((char*)glm::value_ptr(value), sizeof(float)*value.length()); } -template <> std::istream& Property::loadAscii(std::istream& is) { is.ignore(1); for(int i=0; i> (glm::value_ptr(value)[i]), is.ignore(1); return is; } +template <> std::ostream& Property::saveBinary(std::ostream& os) { return os.write((char*)glm::value_ptr(m_value), sizeof(float)*m_value.length()); } +template <> std::ostream& Property::saveAscii(std::ostream& os) { os << "["; for(int i=0; i std::istream& Property::loadBinary(std::istream& is) { return is.read((char*)glm::value_ptr(m_value), sizeof(float)*m_value.length()); } +template <> std::istream& Property::loadAscii(std::istream& is) { is.ignore(1); for(int i=0; i> (glm::value_ptr(m_value)[i]), is.ignore(1); return is; } template <> AbstractProperty::PropertyType Property::getStaticPropertyType() { return AbstractProperty::MAT4; } // STRING PROPERTY template <> std::ostream& Property::saveBinary(std::ostream& os) { static const char endChar = '\0'; - os.write(value.data(), sizeof(char)*value.size()); + os.write(m_value.data(), sizeof(char)*m_value.size()); return os.write(&endChar, sizeof(char));; } template <> std::ostream& Property::saveAscii(std::ostream& os) { os << "\""; - for(char c : value) + for(char c : m_value) { switch(c) { @@ -129,14 +129,14 @@ template <> std::ostream& Property::saveAscii(std::ostream& os) } template <> std::istream& Property::loadBinary(std::istream& is) { - value = ""; + m_value = ""; for(char c = is.get(); c != '\0'; c = is.get()) - value.push_back(c); + m_value.push_back(c); return is; } template <> std::istream& Property::loadAscii(std::istream& is) { - value = ""; + m_value = ""; is.ignore(1); // " for(char c = is.get(); c != '"'; c = is.get()) { @@ -146,27 +146,27 @@ template <> std::istream& Property::loadAscii(std::istream& is) switch(c) { case 't' : - value.push_back('\t'); + m_value.push_back('\t'); break; case '\\' : - value.push_back('\\'); + m_value.push_back('\\'); break; case 'n' : - value.push_back('\n'); + m_value.push_back('\n'); break; case 'r' : - value.push_back('\r'); + m_value.push_back('\r'); break; case '"' : - value.push_back('"'); + m_value.push_back('"'); c = 'c'; break; default: - value.push_back(c); + m_value.push_back(c); } } else - value.push_back(c); + m_value.push_back(c); } return is; } @@ -175,17 +175,17 @@ template <> AbstractProperty::PropertyType Property::getStaticPrope // ARRAY PROPERTY SPECIAL BOOL HANDLING template <> std::ostream& ArrayProperty::saveBinary(std::ostream& os) { - unsigned int size = value.size(); + unsigned int size = m_value.size(); os.write((char*)&size, sizeof(unsigned int)); - for(bool it : value) + for(bool it : m_value) Property(it).saveBinary(os); return os; } template <> std::ostream& ArrayProperty::saveAscii(std::ostream& os) { - os << "{ " << value.size() << ", [" << std::endl; - for(bool it : value) + os << "{ " << m_value.size() << ", [" << std::endl; + for(bool it : m_value) { Property(it).saveAscii(os); os << "," << std::endl; diff --git a/src/property.h b/src/property.h index 17118ab..81614db 100644 --- a/src/property.h +++ b/src/property.h @@ -11,23 +11,23 @@ Property var##Property;\ type &var = var##Property.getValueRef();\ -#define INT(var) PROPERTY(int, var) -#define UINT(var) PROPERTY(unsigned int, var) -#define LONG(var) PROPERTY(long, var) -#define SHORT(var) PROPERTY(short, var) -#define BYTE(var) PROPERTY(char, var) -#define DOUBLE(var) PROPERTY(double, var) -#define FLOAT(var) PROPERTY(float, var) -#define BOOL(var) PROPERTY(bool, var) -#define VEC2(var) PROPERTY(glm::vec2, var) -#define VEC3(var) PROPERTY(glm::vec3, var) -#define VEC4(var) PROPERTY(glm::vec4, var) -#define MAT3(var) PROPERTY(glm::mat3, var) -#define MAT4(var) PROPERTY(glm::mat4, var) -#define STRING(var) PROPERTY(std::string, var) +#define P_INT(var) PROPERTY(int, var) +#define P_UINT(var) PROPERTY(unsigned int, var) +#define P_LONG(var) PROPERTY(long, var) +#define P_SHORT(var) PROPERTY(short, var) +#define P_BYTE(var) PROPERTY(char, var) +#define P_DOUBLE(var) PROPERTY(double, var) +#define P_FLOAT(var) PROPERTY(float, var) +#define P_BOOL(var) PROPERTY(bool, var) +#define P_VEC2(var) PROPERTY(glm::vec2, var) +#define P_VEC3(var) PROPERTY(glm::vec3, var) +#define P_VEC4(var) PROPERTY(glm::vec4, var) +#define P_MAT3(var) PROPERTY(glm::mat3, var) +#define P_MAT4(var) PROPERTY(glm::mat4, var) +#define P_STRING(var) PROPERTY(std::string, var) // the provided type must be a class inheriting Serializable -#define REFERENCE(type, var)\ +#define P_REFERENCE(type, var)\ Property var##Property;\ type*& var = (type*&)(var##Property.getValueRef());\ @@ -36,21 +36,21 @@ std::vector &var = var##Property.getValueRef();\ -#define VECTOR_INT(var) VECTOR_PROPERTY(int, var) -#define VECTOR_UINT(var) VECTOR_PROPERTY(unsigned int, var) -#define VECTOR_FLOAT(var) VECTOR_PROPERTY(float, var) -#define VECTOR_BOOL(var) VECTOR_PROPERTY(bool, var) -#define VECTOR_SHORT(var) VECTOR_PROPERTY(short, var) -#define VECTOR_BYTE(var) VECTOR_PROPERTY(char, var) -#define VECTOR_LONG(var) VECTOR_PROPERTY(long, var) -#define VECTOR_DOUBLE(var) VECTOR_PROPERTY(double, var) -#define VECTOR_VEC2(var) VECTOR_PROPERTY(glm::vec2, var) -#define VECTOR_VEC3(var) VECTOR_PROPERTY(glm::vec3, var) -#define VECTOR_VEC4(var) VECTOR_PROPERTY(glm::vec4, var) -#define VECTOR_MAT3(var) VECTOR_PROPERTY(glm::mat3, var) -#define VECTOR_MAT4(var) VECTOR_PROPERTY(glm::mat4, var) -#define VECTOR_STRING(var) VECTOR_PROPERTY(std::string, var) -#define VECTOR_REFERENCE(type, var) VECTOR_PROPERTY(type*, var) +#define P_VECTOR_INT(var) VECTOR_PROPERTY(int, var) +#define P_VECTOR_UINT(var) VECTOR_PROPERTY(unsigned int, var) +#define P_VECTOR_FLOAT(var) VECTOR_PROPERTY(float, var) +#define P_VECTOR_BOOL(var) VECTOR_PROPERTY(bool, var) +#define P_VECTOR_SHORT(var) VECTOR_PROPERTY(short, var) +#define P_VECTOR_BYTE(var) VECTOR_PROPERTY(char, var) +#define P_VECTOR_LONG(var) VECTOR_PROPERTY(long, var) +#define P_VECTOR_DOUBLE(var) VECTOR_PROPERTY(double, var) +#define P_VECTOR_VEC2(var) VECTOR_PROPERTY(glm::vec2, var) +#define P_VECTOR_VEC3(var) VECTOR_PROPERTY(glm::vec3, var) +#define P_VECTOR_VEC4(var) VECTOR_PROPERTY(glm::vec4, var) +#define P_VECTOR_MAT3(var) VECTOR_PROPERTY(glm::mat3, var) +#define P_VECTOR_MAT4(var) VECTOR_PROPERTY(glm::mat4, var) +#define P_VECTOR_STRING(var) VECTOR_PROPERTY(std::string, var) +#define P_VECTOR_REFERENCE(type, var) VECTOR_PROPERTY(type*, var) #define CAST(var) (AbstractProperty*)&var##Property @@ -110,9 +110,9 @@ public: template class Property : public AbstractProperty { - T value; + T m_value; public: - Property(T val) : value(val) {} + Property(T val) : m_value(val) {} Property() {} ~Property() {} @@ -125,7 +125,7 @@ public: PropertyType getPropertyType() { return getStaticPropertyType(); } static PropertyType getStaticPropertyType(); - T &getValueRef() { return value; } + T &getValueRef() { return m_value; } }; /** @@ -136,9 +136,9 @@ public: template class Property : public AbstractProperty { - T* value; + T* m_value; public: - Property(T* val) : value(val) {} + Property(T* val) : m_value(val) {} Property() {} ~Property() {} @@ -150,7 +150,7 @@ public: PropertyType getPropertyType() { return getStaticPropertyType(); } static PropertyType getStaticPropertyType() { return REFERENCE; } - T*& getValueRef() { return value; } + T*& getValueRef() { return m_value; } }; // GENERIC VECTOR PROPERTY @@ -166,17 +166,17 @@ public: template class ArrayProperty : public AbstractArrayProperty { - std::vector value; + std::vector m_value; public: - ArrayProperty(const std::vector &val) : value(val) {} + ArrayProperty(const std::vector &val) : m_value(val) {} ArrayProperty() {} ~ArrayProperty() {} std::ostream& saveBinary(std::ostream& os) { - Property size(value.size()); + Property size(m_value.size()); size.saveBinary(os); - for(T &it : value) + for(T &it : m_value) Property(it).saveBinary(os); return os; } @@ -184,8 +184,8 @@ public: std::ostream& saveAscii(std::ostream& os) { os << "["; - int i = value.size(); - for(T &it : value) + int i = m_value.size(); + for(T &it : m_value) { Property(it).saveAscii(os); if(--i) os << ", "; @@ -197,25 +197,25 @@ public: { Property size; size.loadBinary(is); - value.resize(size.getValueRef()); + m_value.resize(size.getValueRef()); Property p; for(int i=0; i p; while(is.peek() != ']') { p.loadAscii(is); - value.push_back(p.getValueRef()); + m_value.push_back(p.getValueRef()); if(is.peek() == ',') is.ignore(1); // , } @@ -226,10 +226,10 @@ public: PropertyType getDataType() { return Property::getStaticPropertyType(); } - std::vector &getValueRef() { return value; } - const std::vector &getValueRef() const { return value; } + std::vector &getValueRef() { return m_value; } + const std::vector &getValueRef() const { return m_value; } - unsigned int getArraySize() { return value.size(); } + unsigned int getArraySize() { return m_value.size(); } }; #endif // PROPERTY_H