Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 96592d5

Browse files
author
Wouter van Oortmerssen
committed
Made Vector have a size() function, to make it more STL-alike.
Bug: 17316346 Change-Id: I52377b7fa51adccadc4e867d45666e683bc2c1ae Tested: on Linux.
1 parent 84f86be commit 96592d5

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

include/flatbuffers/flatbuffers.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,15 @@ template<typename T> class Vector {
247247
typedef VectorIterator<T, false> iterator;
248248
typedef VectorIterator<T, true> const_iterator;
249249

250-
uoffset_t Length() const { return EndianScalar(length_); }
250+
uoffset_t size() const { return EndianScalar(length_); }
251+
252+
// Deprecated: use size(). Here for backwards compatibility.
253+
uoffset_t Length() const { return size(); }
251254

252255
typedef typename IndirectHelper<T>::return_type return_type;
253256

254257
return_type Get(uoffset_t i) const {
255-
assert(i < Length());
258+
assert(i < size());
256259
return IndirectHelper<T>::Read(Data(), i);
257260
}
258261

@@ -727,7 +730,7 @@ class Verifier {
727730
// Special case for string contents, after the above has been called.
728731
bool VerifyVectorOfStrings(const Vector<Offset<String>> *vec) const {
729732
if (vec) {
730-
for (uoffset_t i = 0; i < vec->Length(); i++) {
733+
for (uoffset_t i = 0; i < vec->size(); i++) {
731734
if (!Verify(vec->Get(i))) return false;
732735
}
733736
}
@@ -737,7 +740,7 @@ class Verifier {
737740
// Special case for table contents, after the above has been called.
738741
template<typename T> bool VerifyVectorOfTables(const Vector<Offset<T>> *vec) {
739742
if (vec) {
740-
for (uoffset_t i = 0; i < vec->Length(); i++) {
743+
for (uoffset_t i = 0; i < vec->size(); i++) {
741744
if (!vec->Get(i)->Verify(*this)) return false;
742745
}
743746
}

src/idl_gen_text.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ template<typename T> void PrintVector(const Vector<T> &v, Type type,
7070
std::string &text = *_text;
7171
text += "[";
7272
text += NewLine(opts);
73-
for (uoffset_t i = 0; i < v.Length(); i++) {
73+
for (uoffset_t i = 0; i < v.size(); i++) {
7474
if (i) {
7575
text += ",";
7676
text += NewLine(opts);
@@ -91,7 +91,7 @@ template<typename T> void PrintVector(const Vector<T> &v, Type type,
9191
static void EscapeString(const String &s, std::string *_text) {
9292
std::string &text = *_text;
9393
text += "\"";
94-
for (uoffset_t i = 0; i < s.Length(); i++) {
94+
for (uoffset_t i = 0; i < s.size(); i++) {
9595
char c = s.Get(i);
9696
switch (c) {
9797
case '\n': text += "\\n"; break;

0 commit comments

Comments
 (0)