mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-02 05:58:18 +00:00
Clarified the semantics of the Offset type.
Change-Id: Iccc36d24321ac4d556692ac715c0cc69a2c9e09e Tested: on Linux.
This commit is contained in:
@@ -158,11 +158,13 @@ typedef std::unique_ptr<uint8_t, std::function<void(uint8_t * /* unused */)>>
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Wrapper for uoffset_t to allow safe template specialization.
|
// 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 {
|
template<typename T> struct Offset {
|
||||||
uoffset_t o;
|
uoffset_t o;
|
||||||
Offset() : o(0) {}
|
Offset() : o(0) {}
|
||||||
Offset(uoffset_t _o) : o(_o) {}
|
Offset(uoffset_t _o) : o(_o) {}
|
||||||
Offset<void> Union() const { return Offset<void>(o); }
|
Offset<void> Union() const { return Offset<void>(o); }
|
||||||
|
bool IsNull() const { return !o; }
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void EndianCheck() {
|
inline void EndianCheck() {
|
||||||
@@ -855,7 +857,7 @@ FLATBUFFERS_FINAL_CLASS
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T> void AddOffset(voffset_t field, Offset<T> off) {
|
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));
|
AddElement(field, ReferTo(off.o), static_cast<uoffset_t>(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user