#include "property.h" #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 <> 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 <> 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 <> 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 <> 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 <> 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 <> 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 <> 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 <> 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 <> 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 <> AbstractProperty::PropertyType Property::getStaticPropertyType() { return AbstractProperty::VEC3; } // 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 <> 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()); return os.write(&endChar, sizeof(char));; } template <> std::ostream& Property::saveAscii(std::ostream& os) { os << "\""; for(char c : value) { switch(c) { case '\t' : os << "\\t"; break; case '\\' : os << "\\\\"; break; case '\n' : os << "\\n"; break; case '\r' : os << "\\r"; break; case '"' : os << "\\\""; break; default: os << c; } } return os << "\""; } template <> std::istream& Property::loadBinary(std::istream& is) { value = ""; for(char c = is.get(); c != '\0'; c = is.get()) value.push_back(c); return is; } template <> std::istream& Property::loadAscii(std::istream& is) { value = ""; is.ignore(1); // " for(char c = is.get(); c != '"'; c = is.get()) { if(c == '\\') { c = is.get(); switch(c) { case 't' : value.push_back('\t'); break; case '\\' : value.push_back('\\'); break; case 'n' : value.push_back('\n'); break; case 'r' : value.push_back('\r'); break; case '"' : value.push_back('"'); c = 'c'; break; default: value.push_back(c); } } else value.push_back(c); } return is; } template <> AbstractProperty::PropertyType Property::getStaticPropertyType() { return AbstractProperty::STRING; } // ARRAY PROPERTY SPECIAL BOOL HANDLING template <> std::ostream& ArrayProperty::saveBinary(std::ostream& os) { unsigned int size = value.size(); os.write((char*)&size, sizeof(unsigned int)); for(bool it : value) Property(it).saveBinary(os); return os; } template <> std::ostream& ArrayProperty::saveAscii(std::ostream& os) { os << "{ " << value.size() << ", [" << std::endl; for(bool it : value) { Property(it).saveAscii(os); os << "," << std::endl; } return os << "] }"; }