first major attempt at fix, move from Field(x).[Set]Value to ObjectBase::[G|S]etValue<T>(y));
This commit is contained in:
Родитель
d9c805ed64
Коммит
d9a35b8c24
|
@ -20,8 +20,10 @@ namespace xPlat {
|
|||
virtual void Validate() = 0;
|
||||
virtual size_t Size() = 0;
|
||||
|
||||
template <class T> static T& GetValue(ObjectBase& o) { return static_cast<T&>(o.v); }
|
||||
template <class T> static void SetValue(ObjectBase& o, T& value) { o.v = static_cast<void*>(&value); }
|
||||
template <class T> static T& GetValue(ObjectBase* o) { return static_cast<T&>(o->v); }
|
||||
template <class T> static void SetValue(ObjectBase* o, T& value) { o->v = static_cast<void*>(&value); }
|
||||
//template <class T> static T& GetValue(ObjectBase& o) { return static_cast<T&>(o.v); }
|
||||
//template <class T> static void SetValue(ObjectBase& o, T& value) { o.v = static_cast<void*>(&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<void(T& v)>;
|
||||
|
||||
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<std::uint8_t>(const_cast<T>(&value)));
|
||||
}
|
||||
|
||||
|
@ -128,17 +128,16 @@ namespace xPlat {
|
|||
using Lambda = std::function<void(std::vector<std::uint8_t>& 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<std::uint8_t>(const_cast<T>(Value().data())));
|
||||
stream->Write(Size(), GetValue().data());
|
||||
}
|
||||
|
||||
virtual void Read()
|
||||
{
|
||||
stream->Read(Size(), static_cast<std::uint8_t>(const_cast<T>(Value().data())));
|
||||
stream->Read(Size(), GetValue().data());
|
||||
Validate();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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<std::uint16_t>(Field(9)); }
|
||||
void SetFileNameLength(std::uint16_t value) { ObjectBase::SetValue(Field(9), value); }
|
||||
|
||||
std::uint16_t GetExtraFieldLength() { return Field(10).Value<std::uint16_t>(); }
|
||||
void SetExtraFieldLength(std::uint16_t value) { Field(10).SetValue(value); }
|
||||
std::uint16_t GetExtraFieldLength() { return ObjectBase::GetValue<std::uint16_t>(Field(10)); }
|
||||
void SetExtraFieldLength(std::uint16_t value) { ObjectBase::SetValue(Field(10), value); }
|
||||
|
||||
std::uint32_t GetCompressedSize() { return Field(7).Value<std::uint32_t>(); }
|
||||
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>(); }
|
||||
std::uint16_t GetNumberOfDisk() { return Field(1)->GetValue<std::uint16_t>(); }
|
||||
void SetNumberOfDisk(std::uint16_t value) { Field(1).SetValue(value); }
|
||||
|
||||
std::uint16_t GetNumberOfDisk() { return Field(1).Value<std::uint16_t>(); }
|
||||
|
|
Загрузка…
Ссылка в новой задаче