Skip to content

Commit

Permalink
Made Vector have a size() function, to make it more STL-alike.
Browse files Browse the repository at this point in the history
Bug: 17316346
Change-Id: I52377b7fa51adccadc4e867d45666e683bc2c1ae
Tested: on Linux.
  • Loading branch information
Wouter van Oortmerssen committed Sep 5, 2014
1 parent 84f86be commit 96592d5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions include/flatbuffers/flatbuffers.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,15 @@ template<typename T> class Vector {
typedef VectorIterator<T, false> iterator;
typedef VectorIterator<T, true> const_iterator;

uoffset_t Length() const { return EndianScalar(length_); }
uoffset_t size() const { return EndianScalar(length_); }

// Deprecated: use size(). Here for backwards compatibility.
uoffset_t Length() const { return size(); }

typedef typename IndirectHelper<T>::return_type return_type;

return_type Get(uoffset_t i) const {
assert(i < Length());
assert(i < size());
return IndirectHelper<T>::Read(Data(), i);
}

Expand Down Expand Up @@ -727,7 +730,7 @@ class Verifier {
// Special case for string contents, after the above has been called.
bool VerifyVectorOfStrings(const Vector<Offset<String>> *vec) const {
if (vec) {
for (uoffset_t i = 0; i < vec->Length(); i++) {
for (uoffset_t i = 0; i < vec->size(); i++) {
if (!Verify(vec->Get(i))) return false;
}
}
Expand All @@ -737,7 +740,7 @@ class Verifier {
// Special case for table contents, after the above has been called.
template<typename T> bool VerifyVectorOfTables(const Vector<Offset<T>> *vec) {
if (vec) {
for (uoffset_t i = 0; i < vec->Length(); i++) {
for (uoffset_t i = 0; i < vec->size(); i++) {
if (!vec->Get(i)->Verify(*this)) return false;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/idl_gen_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ template<typename T> void PrintVector(const Vector<T> &v, Type type,
std::string &text = *_text;
text += "[";
text += NewLine(opts);
for (uoffset_t i = 0; i < v.Length(); i++) {
for (uoffset_t i = 0; i < v.size(); i++) {
if (i) {
text += ",";
text += NewLine(opts);
Expand All @@ -91,7 +91,7 @@ template<typename T> void PrintVector(const Vector<T> &v, Type type,
static void EscapeString(const String &s, std::string *_text) {
std::string &text = *_text;
text += "\"";
for (uoffset_t i = 0; i < s.Length(); i++) {
for (uoffset_t i = 0; i < s.size(); i++) {
char c = s.Get(i);
switch (c) {
case '\n': text += "\\n"; break;
Expand Down

0 comments on commit 96592d5

Please sign in to comment.