mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-01 10:51:37 +00:00
Added "final" to generated types to block inheritance.
People sometimes accidentally inherit from these types. Bug: 18224703 Change-Id: Ia09489a834ac4941f9b4a46f240cbdcf456f03a1 Tested: on Windows and Linux.
This commit is contained in:
@@ -61,6 +61,13 @@
|
|||||||
#define FLATBUFFERS_STRING_EXPAND(X) #X
|
#define FLATBUFFERS_STRING_EXPAND(X) #X
|
||||||
#define FLATBUFFERS_STRING(X) FLATBUFFERS_STRING_EXPAND(X)
|
#define FLATBUFFERS_STRING(X) FLATBUFFERS_STRING_EXPAND(X)
|
||||||
|
|
||||||
|
#if (!defined(_MSC_VER) || _MSC_VER > 1600) && \
|
||||||
|
(!defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 407))
|
||||||
|
#define FLATBUFFERS_FINAL_CLASS final
|
||||||
|
#else
|
||||||
|
#define FLATBUFFERS_FINAL_CLASS
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace flatbuffers {
|
namespace flatbuffers {
|
||||||
|
|
||||||
// Our default offset / size type, 32bit on purpose on 64bit systems.
|
// Our default offset / size type, 32bit on purpose on 64bit systems.
|
||||||
@@ -394,7 +401,7 @@ inline size_t PaddingBytes(size_t buf_size, size_t scalar_size) {
|
|||||||
// AddElement/EndTable, or the builtin CreateString/CreateVector functions.
|
// AddElement/EndTable, or the builtin CreateString/CreateVector functions.
|
||||||
// Do this is depth-first order to build up a tree to the root.
|
// Do this is depth-first order to build up a tree to the root.
|
||||||
// Finish() wraps up the buffer ready for transport.
|
// Finish() wraps up the buffer ready for transport.
|
||||||
class FlatBufferBuilder {
|
class FlatBufferBuilder FLATBUFFERS_FINAL_CLASS {
|
||||||
public:
|
public:
|
||||||
explicit FlatBufferBuilder(uoffset_t initial_size = 1024,
|
explicit FlatBufferBuilder(uoffset_t initial_size = 1024,
|
||||||
const simple_allocator *allocator = nullptr)
|
const simple_allocator *allocator = nullptr)
|
||||||
@@ -715,7 +722,7 @@ inline bool BufferHasIdentifier(const void *buf, const char *identifier) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Helper class to verify the integrity of a FlatBuffer
|
// Helper class to verify the integrity of a FlatBuffer
|
||||||
class Verifier {
|
class Verifier FLATBUFFERS_FINAL_CLASS {
|
||||||
public:
|
public:
|
||||||
Verifier(const uint8_t *buf, size_t buf_len, size_t _max_depth = 64,
|
Verifier(const uint8_t *buf, size_t buf_len, size_t _max_depth = 64,
|
||||||
size_t _max_tables = 1000000)
|
size_t _max_tables = 1000000)
|
||||||
@@ -833,7 +840,7 @@ class Verifier {
|
|||||||
// always have all members present and do not support forwards/backwards
|
// always have all members present and do not support forwards/backwards
|
||||||
// compatible extensions.
|
// compatible extensions.
|
||||||
|
|
||||||
class Struct {
|
class Struct FLATBUFFERS_FINAL_CLASS {
|
||||||
public:
|
public:
|
||||||
template<typename T> T GetField(uoffset_t o) const {
|
template<typename T> T GetField(uoffset_t o) const {
|
||||||
return ReadScalar<T>(&data_[o]);
|
return ReadScalar<T>(&data_[o]);
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ inline const char **EnumNamesAny() {
|
|||||||
|
|
||||||
inline const char *EnumNameAny(Any e) { return EnumNamesAny()[e]; }
|
inline const char *EnumNameAny(Any e) { return EnumNamesAny()[e]; }
|
||||||
|
|
||||||
inline bool VerifyAny(flatbuffers::Verifier &verifier, const void *union_obj, uint8_t type);
|
inline bool VerifyAny(flatbuffers::Verifier &verifier, const void *union_obj, Any type);
|
||||||
|
|
||||||
MANUALLY_ALIGNED_STRUCT(4) Vec3 {
|
MANUALLY_ALIGNED_STRUCT(4) Vec3 {
|
||||||
private:
|
private:
|
||||||
@@ -110,7 +110,7 @@ inline flatbuffers::Offset<Monster> CreateMonster(flatbuffers::FlatBufferBuilder
|
|||||||
return builder_.Finish();
|
return builder_.Finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool VerifyAny(flatbuffers::Verifier &verifier, const void *union_obj, uint8_t type) {
|
inline bool VerifyAny(flatbuffers::Verifier &verifier, const void *union_obj, Any type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Any_NONE: return true;
|
case Any_NONE: return true;
|
||||||
case Any_Monster: return verifier.VerifyTable(reinterpret_cast<const Monster *>(union_obj));
|
case Any_Monster: return verifier.VerifyTable(reinterpret_cast<const Monster *>(union_obj));
|
||||||
|
|||||||
@@ -208,7 +208,8 @@ static void GenTable(const Parser &parser, StructDef &struct_def,
|
|||||||
// Generate an accessor struct, with methods of the form:
|
// Generate an accessor struct, with methods of the form:
|
||||||
// type name() const { return GetField<type>(offset, defaultval); }
|
// type name() const { return GetField<type>(offset, defaultval); }
|
||||||
GenComment(struct_def.doc_comment, code_ptr);
|
GenComment(struct_def.doc_comment, code_ptr);
|
||||||
code += "struct " + struct_def.name + " : private flatbuffers::Table";
|
code += "struct " + struct_def.name;
|
||||||
|
code += " FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table";
|
||||||
code += " {\n";
|
code += " {\n";
|
||||||
for (auto it = struct_def.fields.vec.begin();
|
for (auto it = struct_def.fields.vec.begin();
|
||||||
it != struct_def.fields.vec.end();
|
it != struct_def.fields.vec.end();
|
||||||
@@ -414,7 +415,7 @@ static void GenStruct(const Parser &parser, StructDef &struct_def,
|
|||||||
// platforms.
|
// platforms.
|
||||||
GenComment(struct_def.doc_comment, code_ptr);
|
GenComment(struct_def.doc_comment, code_ptr);
|
||||||
code += "MANUALLY_ALIGNED_STRUCT(" + NumToString(struct_def.minalign) + ") ";
|
code += "MANUALLY_ALIGNED_STRUCT(" + NumToString(struct_def.minalign) + ") ";
|
||||||
code += struct_def.name + " {\n private:\n";
|
code += struct_def.name + " FLATBUFFERS_FINAL_CLASS {\n private:\n";
|
||||||
int padding_id = 0;
|
int padding_id = 0;
|
||||||
for (auto it = struct_def.fields.vec.begin();
|
for (auto it = struct_def.fields.vec.begin();
|
||||||
it != struct_def.fields.vec.end();
|
it != struct_def.fields.vec.end();
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ inline const char *EnumNameAny(Any e) { return EnumNamesAny()[e]; }
|
|||||||
|
|
||||||
inline bool VerifyAny(flatbuffers::Verifier &verifier, const void *union_obj, Any type);
|
inline bool VerifyAny(flatbuffers::Verifier &verifier, const void *union_obj, Any type);
|
||||||
|
|
||||||
MANUALLY_ALIGNED_STRUCT(2) Test {
|
MANUALLY_ALIGNED_STRUCT(2) Test FLATBUFFERS_FINAL_CLASS {
|
||||||
private:
|
private:
|
||||||
int16_t a_;
|
int16_t a_;
|
||||||
int8_t b_;
|
int8_t b_;
|
||||||
@@ -61,7 +61,7 @@ MANUALLY_ALIGNED_STRUCT(2) Test {
|
|||||||
};
|
};
|
||||||
STRUCT_END(Test, 4);
|
STRUCT_END(Test, 4);
|
||||||
|
|
||||||
MANUALLY_ALIGNED_STRUCT(16) Vec3 {
|
MANUALLY_ALIGNED_STRUCT(16) Vec3 FLATBUFFERS_FINAL_CLASS {
|
||||||
private:
|
private:
|
||||||
float x_;
|
float x_;
|
||||||
float y_;
|
float y_;
|
||||||
@@ -86,7 +86,7 @@ MANUALLY_ALIGNED_STRUCT(16) Vec3 {
|
|||||||
};
|
};
|
||||||
STRUCT_END(Vec3, 32);
|
STRUCT_END(Vec3, 32);
|
||||||
|
|
||||||
struct Stat : private flatbuffers::Table {
|
struct Stat FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||||
const flatbuffers::String *id() const { return GetPointer<const flatbuffers::String *>(4); }
|
const flatbuffers::String *id() const { return GetPointer<const flatbuffers::String *>(4); }
|
||||||
int64_t val() const { return GetField<int64_t>(6, 0); }
|
int64_t val() const { return GetField<int64_t>(6, 0); }
|
||||||
bool Verify(flatbuffers::Verifier &verifier) const {
|
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||||
@@ -120,7 +120,7 @@ inline flatbuffers::Offset<Stat> CreateStat(flatbuffers::FlatBufferBuilder &_fbb
|
|||||||
return builder_.Finish();
|
return builder_.Finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Monster : private flatbuffers::Table {
|
struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||||
const Vec3 *pos() const { return GetStruct<const Vec3 *>(4); }
|
const Vec3 *pos() const { return GetStruct<const Vec3 *>(4); }
|
||||||
int16_t mana() const { return GetField<int16_t>(6, 150); }
|
int16_t mana() const { return GetField<int16_t>(6, 150); }
|
||||||
int16_t hp() const { return GetField<int16_t>(8, 100); }
|
int16_t hp() const { return GetField<int16_t>(8, 100); }
|
||||||
|
|||||||
Reference in New Issue
Block a user