diff --git a/src/inc/ObjectBase.hpp b/src/inc/ObjectBase.hpp index f52ba87a..024bd18b 100644 --- a/src/inc/ObjectBase.hpp +++ b/src/inc/ObjectBase.hpp @@ -20,8 +20,10 @@ namespace xPlat { virtual void Validate() = 0; virtual size_t Size() = 0; - template static T& GetValue(ObjectBase& o) { return static_cast(o.v); } - template static void SetValue(ObjectBase& o, T& value) { o.v = static_cast(&value); } + template static T& GetValue(ObjectBase* o) { return static_cast(o->v); } + template static void SetValue(ObjectBase* o, T& value) { o->v = static_cast(&value); } + //template static T& GetValue(ObjectBase& o) { return static_cast(o.v); } + //template static void SetValue(ObjectBase& o, T& value) { o.v = static_cast(&value); } protected: void* value() { return v; } @@ -39,7 +41,6 @@ namespace xPlat { { for (auto field : fields) { - field->Validate(); field->Write(); } } @@ -77,14 +78,13 @@ namespace xPlat { public: using Lambda = std::function; - FieldBase(StreamBase* stream, Lambda validator) : stream(stream), validate(validator) {} + FieldBase(StreamBase* stream, Lambda validator) : stream(stream), validate(validator), ObjectBase(&value) {} - virtual T& Value() { return value; } + virtual T& GetValue() { return value; } virtual void SetValue(T& v) { value = v; } virtual void Write() { - Validate(); stream.Write(sizeof(T), static_cast(const_cast(&value))); } @@ -128,17 +128,16 @@ namespace xPlat { using Lambda = std::function& v)>; FieldNBytes(StreamBase* stream, Lambda validator) : FieldBase(stream, validator) {} - size_t Size() { return Value().size(); } + size_t Size() { return GetValue().size(); } virtual void Write() { - Validate(); - stream->Write(Size(), static_cast(const_cast(Value().data()))); + stream->Write(Size(), GetValue().data()); } virtual void Read() { - stream->Read(Size(), static_cast(const_cast(Value().data()))); + stream->Read(Size(), GetValue().data()); Validate(); } }; diff --git a/src/inc/ZipStream.hpp b/src/inc/ZipStream.hpp index c15c5eec..154669d7 100644 --- a/src/inc/ZipStream.hpp +++ b/src/inc/ZipStream.hpp @@ -81,11 +81,11 @@ namespace xPlat { class LocalFileHeader : public StructuredObject { public: - std::uint16_t GetFileNameLength() { return ObjectBase::GetValue(Field(9)); } + std::uint16_t GetFileNameLength() { return ObjectBase::GetValue(Field(9)); } void SetFileNameLength(std::uint16_t value) { ObjectBase::SetValue(Field(9), value); } - std::uint16_t GetExtraFieldLength() { return Field(10).Value(); } - void SetExtraFieldLength(std::uint16_t value) { Field(10).SetValue(value); } + std::uint16_t GetExtraFieldLength() { return ObjectBase::GetValue(Field(10)); } + void SetExtraFieldLength(std::uint16_t value) { ObjectBase::SetValue(Field(10), value); } std::uint32_t GetCompressedSize() { return Field(7).Value(); } void SetCompressedSize(std::uint32_t value) { Field(7).SetValue(value); } @@ -470,7 +470,7 @@ namespace xPlat { class EndCentralDirectoryRecord : public StructuredObject { public: - std::uint16_t GetNumberOfDisk() { return Field(1).Value(); } + std::uint16_t GetNumberOfDisk() { return Field(1)->GetValue(); } void SetNumberOfDisk(std::uint16_t value) { Field(1).SetValue(value); } std::uint16_t GetNumberOfDisk() { return Field(1).Value(); }