Add more apis to query vector types from a reference (#4823)
authorShivendra Agarwal <shiva.agarwal0@gmail.com>
Thu, 27 Sep 2018 19:34:27 +0000 (01:04 +0530)
committerWouter van Oortmerssen <aardappel@gmail.com>
Thu, 27 Sep 2018 19:34:27 +0000 (12:34 -0700)
* Add more apis to query vector types from a reference

https://github.com/google/flatbuffers/issues/4818

* changing order of apis

* another reordering

* removed vector element type api as not needed as for now

include/flatbuffers/flexbuffers.h

index 99345d9..1874859 100644 (file)
@@ -368,6 +368,9 @@ class Reference {
   bool IsString() const { return type_ == FBT_STRING; }
   bool IsKey() const { return type_ == FBT_KEY; }
   bool IsVector() const { return type_ == FBT_VECTOR || type_ == FBT_MAP; }
+  bool IsTypedVector() const { return flexbuffers::IsTypedVector(type_); }
+  bool IsFixedTypedVector() const { return flexbuffers::IsFixedTypedVector(type_); }
+  bool IsAnyVector() const { return (IsTypedVector() || IsFixedTypedVector() || IsVector());}
   bool IsMap() const { return type_ == FBT_MAP; }
   bool IsBlob() const { return type_ == FBT_BLOB; }
 
@@ -562,7 +565,7 @@ class Reference {
   }
 
   TypedVector AsTypedVector() const {
-    if (IsTypedVector(type_)) {
+    if (IsTypedVector()) {
       return TypedVector(Indirect(), byte_width_,
                          ToTypedVectorElementType(type_));
     } else {
@@ -571,7 +574,7 @@ class Reference {
   }
 
   FixedTypedVector AsFixedTypedVector() const {
-    if (IsFixedTypedVector(type_)) {
+    if (IsFixedTypedVector()) {
       uint8_t len = 0;
       auto vtype = ToFixedTypedVectorElementType(type_, &len);
       return FixedTypedVector(Indirect(), byte_width_, vtype, len);