Clarified the semantics of the Offset type.
Change-Id: Iccc36d24321ac4d556692ac715c0cc69a2c9e09e Tested: on Linux.
This commit is contained in:
parent
a0a313b101
commit
d7ac3788e8
|
@ -158,11 +158,13 @@ typedef std::unique_ptr<uint8_t, std::function<void(uint8_t * /* unused */)>>
|
|||
#endif
|
||||
|
||||
// Wrapper for uoffset_t to allow safe template specialization.
|
||||
// Value is allowed to be 0 to indicate a null object (see e.g. AddOffset).
|
||||
template<typename T> struct Offset {
|
||||
uoffset_t o;
|
||||
Offset() : o(0) {}
|
||||
Offset(uoffset_t _o) : o(_o) {}
|
||||
Offset<void> Union() const { return Offset<void>(o); }
|
||||
bool IsNull() const { return !o; }
|
||||
};
|
||||
|
||||
inline void EndianCheck() {
|
||||
|
@ -855,7 +857,7 @@ FLATBUFFERS_FINAL_CLASS
|
|||
}
|
||||
|
||||
template<typename T> void AddOffset(voffset_t field, Offset<T> off) {
|
||||
if (!off.o) return; // An offset of 0 means NULL, don't store.
|
||||
if (off.IsNull()) return; // Don't store.
|
||||
AddElement(field, ReferTo(off.o), static_cast<uoffset_t>(0));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue