#ifndef Property_h__ #define Property_h__ #include "delegate/Delegate.h" #include "IProperty.h" #include "Utils.h" #include namespace LifeCore { #define DEFINE_PROPERTY(___name, ___type) \ Core::Property<##___type##>*## ___name; #define ALLOC_PROPERTY(_name, _type) \ new Core::Property<##_type##>(STR(#_name)); template class Property : public IProperty { public: Property() { } void Set(const void* src, size_t size){ //size must be equal assert(sizeof(T) == size); memcpy(&value, src, size); } const void* GetPtr(){ return &value; } bool Serialize(LifeCore::IMemoryStream* stm) { StringSerialize(name, stm); stm->Write(size_t(sizeof(value))); stm->Write(&value, sizeof(value)); return true; } bool Deserialize(LifeCore::IMemoryStream* stm) { name = StringDeserialize(stm); size_t data_len; stm->Read(&data_len, sizeof(data_len)); stm->Read(&value, data_len); return true; } const Property& operator=(const T& other) { value = other; OnValueChanged(); return *this; } const Property& operator=(const Property& other) { value = other.value; OnValueChanged(); return *this; } const T& operator()() { return value; } String ToString() { return STR(typeid(T).name()); }; void FromString(const String& str){} const String& GetName() { return name; } private: String name; T value; }; bool Property::Serialize(LifeCore::IMemoryStream* stm) { StringSerialize(name, stm); StringSerialize(value, stm); return true; } bool Property::Deserialize(LifeCore::IMemoryStream* stm) { name = StringDeserialize(stm); value = StringDeserialize(stm); return true; } void Property::FromString(const String& str) { *this = str; } void Property::FromString(const String& str) { *this = StringToInt8(str); } void Property::FromString(const String& str) { *this = StringToInt16(str); } void Property::FromString(const String& str) { *this = StringToInt32(str); } void Property::FromString(const String& str) { *this = StringToInt64(str); } void Property::FromString(const String& str) { *this = StringToUInt8(str); } void Property::FromString(const String& str) { *this = StringToUInt16(str); } void Property::FromString(const String& str) { *this = StringToUInt32(str); } void Property::FromString(const String& str) { *this = StringToUInt64(str); } void Property::FromString(const String& str) { *this = StringToFloat(str); } void Property::FromString(const String& str) { *this = StringToDouble(str); } String Property::ToString() { return value; } String Property::ToString() { return Int8ToString(value); } String Property::ToString() { return Int16ToString(value); } String Property::ToString() { return Int32ToString(value); } String Property::ToString() { return Int64ToString(value); } String Property::ToString() { return UInt8ToString(value); } String Property::ToString() { return UInt16ToString(value); } String Property::ToString() { return UInt32ToString(value); } String Property::ToString() { return UInt64ToString(value); } String Property::ToString() { return BoolToString(value); } String Property::ToString() { return FloatToString(value); } String Property::ToString() { return DoubleToString(value); } } #endif // Property_h__