fixed the last of the compiler errors

This commit is contained in:
Phil Smith 2017-09-22 16:58:42 -07:00
Родитель 366f334178
Коммит 0dfd472747
2 изменённых файлов: 24 добавлений и 19 удалений

Просмотреть файл

@ -20,8 +20,8 @@ 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 reinterpret_cast<T&>(o->v); }
template <class T> static void SetValue(ObjectBase* o, T& value) { o->v = reinterpret_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); }
@ -85,16 +85,16 @@ namespace xPlat {
virtual void Write()
{
stream.Write(sizeof(T), static_cast<std::uint8_t>(const_cast<T>(&value)));
stream->Write(sizeof(T), reinterpret_cast<std::uint8_t*>(const_cast<T*>(&value)));
}
virtual void Read()
{
stream.Read(sizeof(T), static_cast<std::uint8_t>(const_cast<T>(&value)));
stream->Read(sizeof(T), reinterpret_cast<std::uint8_t*>(const_cast<T*>(&value)));
Validate();
}
void Validate() { validate(Value()); }
void Validate() { validate(ObjectBase::GetValue<T>(this)); }
virtual size_t Size() { return sizeof(T); }
@ -122,24 +122,31 @@ namespace xPlat {
Field8Bytes(StreamBase* stream, Lambda&& validator) : FieldBase<std::uint64_t>(stream, validator) {}
};
class FieldNBytes : public FieldBase<std::vector<std::uint8_t>>
class FieldNBytes : public ObjectBase
{
public:
using Lambda = std::function<void(std::vector<std::uint8_t>& v)>;
FieldNBytes(StreamBase* stream, Lambda validator) : FieldBase(stream, validator) {}
FieldNBytes(StreamBase* stream, Lambda validator) : stream(stream), validate(validator), ObjectBase(&value) {}
size_t Size() { return GetValue().size(); }
size_t Size() { return value.size(); }
virtual void Write()
{
stream->Write(Size(), GetValue().data());
stream->Write(Size(), value.data());
}
virtual void Read()
{
stream->Read(Size(), GetValue().data());
stream->Read(Size(), value.data());
Validate();
}
void Validate() { validate(value); }
protected:
std::vector<std::uint8_t> value;
StreamBase* stream;
Lambda validate;
};
}
}

Просмотреть файл

@ -173,14 +173,14 @@ namespace xPlat {
std::uint32_t GetUncompressedSize() { return ObjectBase::GetValue<std::uint32_t>(Field(2)); }
void SetUncompressedSize(std::uint32_t value) { ObjectBase::SetValue(Field(2), value); }
DataDescriptor(StreamBase& stream) : StructuredObject(
DataDescriptor(StreamBase* stream) : StructuredObject(
{
// 0 - crc - 32 4 bytes
std::make_shared<Meta::Field4Bytes>(stream, [this](std::uint32_t& v) {}),
std::make_shared<Meta::Field4Bytes>(stream, [](std::uint32_t& v) {}),
// 1 - compressed size 4 bytes
std::make_shared<Meta::Field4Bytes>(stream, [this](std::uint32_t& v) {}),
std::make_shared<Meta::Field4Bytes>(stream, [](std::uint32_t& v) {}),
// 2 - uncompressed size 4 bytes
std::make_shared<Meta::Field4Bytes>(stream, [this](std::uint32_t& v) {})
std::make_shared<Meta::Field4Bytes>(stream, [](std::uint32_t& v) {})
})
{/*constructor*/}
@ -467,10 +467,10 @@ namespace xPlat {
std::uint16_t GetSignature() { return ObjectBase::GetValue<std::uint32_t>(Field(0)); }
void GetSignature(std::uint32_t value) { ObjectBase::SetValue(Field(0), value); }
std::uint16_t GetNumberOfDisk() { return ObjectBase::GetValue<std::uint16_t>(Field(1)); }
std::uint32_t GetNumberOfDisk() { return ObjectBase::GetValue<std::uint32_t>(Field(1)); }
void SetNumberOfDisk(std::uint32_t value) { ObjectBase::SetValue(Field(1), value); }
std::uint16_t GetRelativeOffset() { return ObjectBase::GetValue<std::uint64_t>(Field(2)); }
std::uint64_t GetRelativeOffset() { return ObjectBase::GetValue<std::uint64_t>(Field(2)); }
void SetTotalNumberOfEntries(std::uint64_t value) { ObjectBase::SetValue(Field(2), value); }
std::uint32_t GetTotalNumberOfDisks() { return ObjectBase::GetValue<std::uint32_t>(Field(3)); }
@ -499,9 +499,6 @@ namespace xPlat {
class EndCentralDirectoryRecord : public StructuredObject
{
public:
std::uint16_t GetNumberOfDisk() { return ObjectBase::GetValue<std::uint16_t>(Field(1)); }
void SetNumberOfDisk(std::uint16_t value) { ObjectBase::SetValue(Field(1), value); }
std::uint32_t GetSignature() { return ObjectBase::GetValue<std::uint32_t>(Field(0)); }
void SetSignature(std::uint32_t value) { ObjectBase::SetValue(Field(0), value); }
@ -587,3 +584,4 @@ namespace xPlat {
protected:
StreamPtr stream;
};//class ZipStream
}