[C++] Fix for printing of enum in case output_enum_identifiers=1. (#5706)

* Add test-case for testing of the future Color in json (output_enum_identifiers = true)

* Refactoring of idl_gen_text.cpp. Fix for printing of bit-enum with active output_enum_identifiers=1.

* Move  GenerateText implementation into class

* Remove unnecessary code from flatbuffers.h
This commit is contained in:
Vladimir Glavnyy
2020-01-17 05:12:25 +07:00
committed by Wouter van Oortmerssen
parent c4b2b0a25d
commit 01189d7edd
3 changed files with 321 additions and 273 deletions

View File

@@ -443,6 +443,13 @@ template<typename T, uint16_t length> class Array {
return_type operator[](uoffset_t i) const { return Get(i); }
// If this is a Vector of enums, T will be its storage type, not the enum
// type. This function makes it convenient to retrieve value with enum
// type E.
template<typename E> E GetEnum(uoffset_t i) const {
return static_cast<E>(Get(i));
}
const_iterator begin() const { return const_iterator(Data(), 0); }
const_iterator end() const { return const_iterator(Data(), size()); }
@@ -518,10 +525,12 @@ template<typename T, uint16_t length> class Array<Offset<T>, length> {
static_assert(flatbuffers::is_same<T, void>::value, "unexpected type T");
public:
typedef const void* return_type;
const uint8_t *Data() const { return data_; }
// Make idl_gen_text.cpp::PrintContainer happy.
const void *operator[](uoffset_t) const {
return_type operator[](uoffset_t) const {
FLATBUFFERS_ASSERT(false);
return nullptr;
}