Added VectorLength helper function that works on nullptr.

Change-Id: Ie62096f7337a476bee7a6d46d652e594fb3124d2
Tested: on Linux.
Bug: 18201051
This commit is contained in:
Wouter van Oortmerssen
2014-12-08 17:32:26 -08:00
parent 318668aed6
commit 8833cff911
2 changed files with 7 additions and 0 deletions

View File

@@ -296,6 +296,12 @@ protected:
uoffset_t length_;
};
// Convenient helper function to get the length of any vector, regardless
// of wether it is null or not (the field is not set).
template<typename T> static inline size_t VectorLength(const Vector<T> *v) {
return v ? v->Length() : 0;
}
struct String : public Vector<char> {
const char *c_str() const { return reinterpret_cast<const char *>(Data()); }
};