forked from BigfootDev/flatbuffers
Reworked reflection.h to be more general.
e.g. support generic reading/writing from structs/vectors etc. Change-Id: I2eb6e24db088a72da444d5c8df7e506e53d5bc2d Tested: on Linux. Bug: 22660837
This commit is contained in:
@@ -353,6 +353,24 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
// Represent a vector much like the template above, but in this case we
|
||||
// don't know what the element types are (used with reflection.h).
|
||||
class VectorOfAny {
|
||||
public:
|
||||
uoffset_t size() const { return EndianScalar(length_); }
|
||||
|
||||
const uint8_t *Data() const {
|
||||
return reinterpret_cast<const uint8_t *>(&length_ + 1);
|
||||
}
|
||||
uint8_t *Data() {
|
||||
return reinterpret_cast<uint8_t *>(&length_ + 1);
|
||||
}
|
||||
protected:
|
||||
VectorOfAny();
|
||||
|
||||
uoffset_t length_;
|
||||
};
|
||||
|
||||
// Convenient helper function to get the length of any vector, regardless
|
||||
// of wether it is null or not (the field is not set).
|
||||
template<typename T> static inline size_t VectorLength(const Vector<T> *v) {
|
||||
@@ -995,6 +1013,9 @@ class Struct FLATBUFFERS_FINAL_CLASS {
|
||||
return reinterpret_cast<T>(&data_[o]);
|
||||
}
|
||||
|
||||
const uint8_t *GetAddressOf(uoffset_t o) const { return &data_[o]; }
|
||||
uint8_t *GetAddressOf(uoffset_t o) { return &data_[o]; }
|
||||
|
||||
private:
|
||||
uint8_t data_[1];
|
||||
};
|
||||
@@ -1027,7 +1048,6 @@ class Table {
|
||||
? reinterpret_cast<P>(p + ReadScalar<uoffset_t>(p))
|
||||
: nullptr;
|
||||
}
|
||||
|
||||
template<typename P> P GetPointer(voffset_t field) const {
|
||||
return const_cast<Table *>(this)->GetPointer<P>(field);
|
||||
}
|
||||
@@ -1052,6 +1072,14 @@ class Table {
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t *GetAddressOf(voffset_t field) {
|
||||
auto field_offset = GetOptionalFieldOffset(field);
|
||||
return field_offset ? data_ + field_offset : nullptr;
|
||||
}
|
||||
const uint8_t *GetAddressOf(voffset_t field) const {
|
||||
return const_cast<Table *>(this)->GetAddressOf(field);
|
||||
}
|
||||
|
||||
uint8_t *GetVTable() { return data_ - ReadScalar<soffset_t>(data_); }
|
||||
|
||||
bool CheckField(voffset_t field) const {
|
||||
|
||||
Reference in New Issue
Block a user