// Return a C++ type for any type (scalar/pointer) that reflects its
// serialized size.
std::string GenTypeSize(const Type &type) {
- return IsScalar(type.base_type)
- ? GenTypeBasic(type, false)
- : IsStruct(type) ? GenTypePointer(type)
- : "flatbuffers::uoffset_t";
+ return IsScalar(type.base_type) ? GenTypeBasic(type, false)
+ : IsStruct(type) ? GenTypePointer(type)
+ : "flatbuffers::uoffset_t";
}
+ // TODO(wvo): make this configurable.
+ std::string NativeName(const std::string &name) { return name + "T"; }
+
+ std::string GenTypeNative(const Type &type, bool invector) {
+ switch (type.base_type) {
+ case BASE_TYPE_STRING:
+ return "std::string";
+ case BASE_TYPE_VECTOR:
+ return "std::vector<" + GenTypeNative(type.VectorType(), true) + ">";
+ case BASE_TYPE_STRUCT:
+ if (IsStruct(type)) {
+ if (invector) {
+ return WrapInNameSpace(*type.struct_def);
+ } else {
+ return "std::unique_ptr<" +
+ WrapInNameSpace(*type.struct_def) + ">";
+ }
+ } else {
+ return "std::unique_ptr<" +
+ NativeName(WrapInNameSpace(*type.struct_def)) + ">";
+ }
+ case BASE_TYPE_UNION:
+ return type.enum_def->name + "Union";
+ default:
+ return GenTypeBasic(type, true);
+ }
+ }
+
// Return a C++ type for any type (scalar/pointer) specifically for
// using a flatbuffer.
- std::string GenTypeGet(const Type &type,
- const char *afterbasic, const char *beforeptr,
- const char *afterptr, bool user_facing_type) {
+ std::string GenTypeGet(const Type &type, const char *afterbasic,
+ const char *beforeptr, const char *afterptr,
+ bool user_facing_type) {
return IsScalar(type.base_type)
? GenTypeBasic(type, user_facing_type) + afterbasic
: beforeptr + GenTypePointer(type) + afterptr;