Made Vector have a size() function, to make it more STL-alike.

Bug: 17316346
Change-Id: I52377b7fa51adccadc4e867d45666e683bc2c1ae
Tested: on Linux.
parent 84f86be7
...@@ -247,12 +247,15 @@ public: ...@@ -247,12 +247,15 @@ public:
typedef VectorIterator<T, false> iterator; typedef VectorIterator<T, false> iterator;
typedef VectorIterator<T, true> const_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; typedef typename IndirectHelper<T>::return_type return_type;
return_type Get(uoffset_t i) const { return_type Get(uoffset_t i) const {
assert(i < Length()); assert(i < size());
return IndirectHelper<T>::Read(Data(), i); return IndirectHelper<T>::Read(Data(), i);
} }
...@@ -727,7 +730,7 @@ class Verifier { ...@@ -727,7 +730,7 @@ class Verifier {
// Special case for string contents, after the above has been called. // Special case for string contents, after the above has been called.
bool VerifyVectorOfStrings(const Vector<Offset<String>> *vec) const { bool VerifyVectorOfStrings(const Vector<Offset<String>> *vec) const {
if (vec) { 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; if (!Verify(vec->Get(i))) return false;
} }
} }
...@@ -737,7 +740,7 @@ class Verifier { ...@@ -737,7 +740,7 @@ class Verifier {
// Special case for table contents, after the above has been called. // Special case for table contents, after the above has been called.
template<typename T> bool VerifyVectorOfTables(const Vector<Offset<T>> *vec) { template<typename T> bool VerifyVectorOfTables(const Vector<Offset<T>> *vec) {
if (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; if (!vec->Get(i)->Verify(*this)) return false;
} }
} }
......
...@@ -70,7 +70,7 @@ template<typename T> void PrintVector(const Vector<T> &v, Type type, ...@@ -70,7 +70,7 @@ template<typename T> void PrintVector(const Vector<T> &v, Type type,
std::string &text = *_text; std::string &text = *_text;
text += "["; text += "[";
text += NewLine(opts); text += NewLine(opts);
for (uoffset_t i = 0; i < v.Length(); i++) { for (uoffset_t i = 0; i < v.size(); i++) {
if (i) { if (i) {
text += ","; text += ",";
text += NewLine(opts); text += NewLine(opts);
...@@ -91,7 +91,7 @@ template<typename T> void PrintVector(const Vector<T> &v, Type type, ...@@ -91,7 +91,7 @@ template<typename T> void PrintVector(const Vector<T> &v, Type type,
static void EscapeString(const String &s, std::string *_text) { static void EscapeString(const String &s, std::string *_text) {
std::string &text = *_text; std::string &text = *_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); char c = s.Get(i);
switch (c) { switch (c) {
case '\n': text += "\\n"; break; case '\n': text += "\\n"; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment