* Add constant accessors to C++ unions
* Remove redundant const pointer return type
* Update generate_code.bat to reflect generate_code.sh
* Add updated generated files
* Remove extra space from generated code
* Update generated files
* Change directory back to tests after generating code
This is something the format supports, but none of the builders
were doing. Can save 10-20% on FlatBuffer binary size!
Also fixed the Go tests.
Change-Id: I616c56ce9bbcfcaee23aa24f0532fcb60b6a8c75
Tested: on Linux.
* Added internal - limited - implementation of flatbuffers::unique_ptr
for STLs that don't ship with std::unique_ptr. In C++11 and beyond
this is just an alias for std::unique_ptr.
* Aliased used type traits structs is_scalar is_floating_point is_unsigned
into flatbuffers namespace so they can be replaced in C++98 implementations.
Right now these point at stlport's TR1 implementations.
* Wrapped vector::data() in vector_data().
* Wrapped vector::emplace_back() in vector_emplace_back().
* Wrapper string::back() in string_back().
* Added variants of FlatBufferBuilder::CreateVector() and
FlatBufferBuilder::CreateVectorOfStructs() that allow the use of plain
function pointers.
Generated code has also been modified to use plain functions to build objects
rather than std::function() so all generated code will work in C++98
applications.
* Added flexbuffers::Builder::Vector(), flexbuffers::Builder::TypedVector()
and flexbuffers::Builder::Map() methods that allow the use of plain function
pointers.
* Changed Parser to internally use plain function pointers when parsing table
and vector delimiters.
* Added specializations of NumToString() for 64-bit types that aren't supported
by stringstream in stlport.
* Overloaded numeric_limits for 64-bit types not supported by stlport.
* Replaced build_apk.sh (which was broken by deprecation of the
"android" tool in the Android SDK) with build.gradle and the
appropriate gradle wrapper to build an APK.
* Switched Android build to build against all STL variants.
* Updated travis configuration to build Android test and sample.
Tested:
* Verified all tests continue to work on Linux, OSX and Android.
* Verified Travis build is green.
Change-Id: I9e634363793f85b9f141d21454b10686020a2065
Zero offsets are non-sensical in FlatBuffers (since offsets are
relative to themselves) but were allowed by the verifier. This could
cause buffers made up of all zeroes to be interpreted as correct
buffers with an empty root object.
Generally, not allowing such offsets will make the verifier more
likely to catch problems earlier.
Change-Id: I54010bea29721b326ff8e5348fcd9fe78e5e7506
Tested: on Linux.
Move constructors are present, which it should use instead.
This is a temp fix to make it compile, but eventually we should
generate a proper copy constructor just in-case people want to
copy objects with unions.
Tested on: Linux, OS X.
Change-Id: Idf85419995c96f5959061882157541573e306083
(C++ only for now).
Also fixed vector of union support in the object API.
Bug: 36902939
Change-Id: I935f4cc2c303a4728e26c7916a8ec0adcd6f84cb
Tested: on Linux.
* Use noexcept in union type move ctor/Add move assingment
* Add NOEXCEPT macro to deal with _MS_VER/Remove delegating ctor in union type class
* Add FLATBUFFERS_NOEXCEPT to generated union class
* Add default value handling to mutation/SetField code
* Shorten reflection SetField impl
* Modify impl to work with C++03
* Add more mutation tests
* Fail SetField if non-scalar
* Add IsScalar/IsInteger/IsFloat for reflection::BaseType
* Use new IsScalar/IsInteger/IsFloat in reflection SetField
* Assume scalar is either int or float
Allow tables to be mapped to native types directly. For example, a table
representing a vector3 (eg. table Vec3 { x:float; y:float; z:float; }) can
be mapped to a "mathfu::vec3" native type in NativeTables. This requires
users to provide Pack and UnPack functions that convert between the
Table and native types. This is done by adding the "native_type" attribute
to the table definition.
To support user-defined flatbuffers::Pack and flatbuffers::UnPack functions,
support a "native_include" markup that will generate a corresponding
Also add an UnPackTo function which allows users to pass in a pointer to
a NativeTable object into which to UnPack the Table. The existing UnPack
function is now simply:
NativeTable* UnPack() {
NativeTable* obj = new NativeTable();
Table::UnPackTo(obj);
return obj;
}
Finally, allow native types to be given a default value as well which are
set in the NativeTable constructor. This is done by providing a
"native_default" attribute to the member of a table.
Change-Id: Ic45cb48b0e6d7cfa5734b24819e54aa96d847cfd
Helps simplify code generation code. Instead of this:
code += "inline const " + cpp_qualified_name + " *Get";
code += name;
code += "(const void *buf) {\n return flatbuffers::GetRoot<";
code += cpp_qualified_name + ">(buf);\n}\n\n";
You do this:
code.SetValue("NAME", struct_def.name);
code.SetValue("CPP_NAME", cpp_qualified_name);
code += "inline const {{CPP_NAME}} *Get{{NAME}}(const void *buf) {";
code += " return flatbuffers::GetRoot<{{CPP_NAME}}>(buf);";
code += "}";
code += "";
Updated the CPP code generator to use the CodeWriter class. Most of the
changes in the generated code are white-space changes, esp. around new
lines (since the code generator class automatically appends new lines
when appending a string). Actual code changes include:
* Renamed "rehasher" to "_rehasher" for consistency with other args in
Pack function.
* Renamed "union_obj" to "obj: in UnPack function.
* Always do "(void)_o;" to prevent unused variable warning in Create
function (instead of only doing it if there are no fields) in order
to avoid two-passes.
* Renamed padding variables from __paddingX to paddingX__.
"Each name that contains a double underscore (_ _) [...] is reserved
to the implementation for any use." C++ standards 17.4.3.1.2.
* Add braces around switch cases.
* Calculate index as a separate statement in EnumName function, eg.
const size_t index = ...;
return EnumNamesX()[index];
vs.
return EnumNamesX()[...];
* Stored end table offset in variable in Finish() functions, eg.
const auto end = fbb_.EndTable(start_, ...);
auto o = flatbuffers::Offset<T>(end);
vs.
auto o = flatbuffers::Offset<T>(fbb_.EndTable(start, ...));
* Separate reinterpret_cast calls from function calls in Union
functions, eg.
auto ptr = reinterpret_cast<const T *>(obj);
return ptr->UnPack(resolver);
vs.
return reinterpret_cast<const T *>(obj)->UnPack(resolver);
* Removed unecessary (void)(padding__X) no-ops from constructors, eg.
Test(int16_t a, int8_t b) : ... {
(void)__padding0; // <-- Removed this line.
}
In the idl_gen_cpp.cpp file itself, I refactored some code generation into
new functions: GenParam, GenNativeTable, GenVerifyCall, GenBuilders,
GenUnpackFieldStatement, and GenCreateParam.
Change-Id: I727b1bd8719d05b7ce33cbce00eb58fda817b25d
- Update to be const-correct where possible.
- Consistently pass |code| as pointer instead of non-const-ref.
- No newlines (\n) characters in the middle of code strings.
- Use if-else if-else statements instead of nested ternary operators.
- Ensure all lines end at 80 chars.
- Make utility functions static.
From cl/143505731.
Change-Id: If0fab9ee75de5af963367a948dddf53af93f73b4
Unions own the NativeTable* value member because they need to destroy them
when the Union goes out of scope. Currently, the data is destroyed by calling
delete, which means that the member needs to be allocated with new. However,
making the allocation the responsibility of the client and the destruction
the responsibility of the Union can lead to potential errors. Adding a
Set function will ensure that the memory is allocated correctly so that it
can be deleted later.
From cl/142161569.
Change-Id: I4605f26d2749164819bfae0140e5fae08442b50a
The following changes have been made to the C++ codegen to enable writing generic code
that uses the Table and NativeTable types.
- Adds TableType and NativeTableType typedefs to NativeTable and Table structs.
- Adds GetFullyQualifiedName() to NativeTables if --gen-name-strings is set.
- Adds a static Pack function to Tables that simply calls the global CreateX functions.
See cr/140391505 as an example of improved usage.
From cl/140529288.
Change-Id: Idec137c16129e15c1783f94fabdcea24aeeaaef6
This allows hashed string fields to be used for lookup of any
C++ objects, a pointer to which are then stored in the object
besides the original hash for easy access.
Change-Id: I2247a13c349b905f1c54660becde2c818ad23e97
Tested: on Linux.
Bug: 30204449
They were overloaded, but also had default arguments, so would
become ambiguous when used with few arguments.
Change-Id: Ifac7f3ea3a6391d971dfeda8e33129c8c38d6f12
Tested: on Linux.
When built for release, builds were failing with unused
variable warnings, since they were only used in `assert()`
calls.
I added explicit void casting to any potentially unused variables.
Change-Id: I9947ba46891fdda5aa925caa950642dedd4e009f
Adding an API reference for the supported languages.
General docs cleanup, including a new `tutorial` section that
supports all of the supported languages.
Added samples for each supported language to mirror the new
tutorial page.
Cleaned up all the links by making them `@ref` style links,
instead of referencing the names of the generated `.html` files.
Removed all generated files that were unnecessarily committed.
Also fixed the C# tests (two were failing due to a missing file).
Bug: b/25801305
Tested: Tested all samples on Ubuntu, Mac, and Android. Docs were
generated using doxygen and viewed on Chrome.
Change-Id: I2acaba6e332a15ae2deff5f26a4a25da7bd2c954