Fixed assigning a temporary to a non const reference

This commit is contained in:
Jordan Cristiano 2015-07-15 23:25:22 -04:00
parent 4e4186d49e
commit 42955b7e01
2 changed files with 37 additions and 16 deletions

View File

@ -218,14 +218,15 @@ namespace base
JsonWriterFile::WriteBits(name, data, numBytes * 8); JsonWriterFile::WriteBits(name, data, numBytes * 8);
} }
JsonReaderIterator::JsonReaderIterator(JsonValue* value): JsonReaderIterator::JsonReaderIterator(JsonValue* value, bool& hasReadError):
m_value(value) m_value(value),
m_hasReadError(hasReadError)
{ {
} }
JsonReaderObject JsonReaderIterator::operator*() const JsonReaderObject JsonReaderIterator::operator*() const
{ {
return JsonReaderObject(*m_value, false); return JsonReaderObject(*m_value, m_hasReadError);
} }
JsonReaderIterator& JsonReaderIterator::operator++() JsonReaderIterator& JsonReaderIterator::operator++()
@ -244,7 +245,7 @@ namespace base
return m_value != other.m_value; return m_value != other.m_value;
} }
JsonReaderArray::JsonReaderArray(JsonValue& value, bool parseError): JsonReaderArray::JsonReaderArray(JsonValue& value, bool& parseError):
m_value(value), m_value(value),
m_hasReadError(parseError) m_hasReadError(parseError)
{ {
@ -262,15 +263,15 @@ namespace base
JsonReaderIterator JsonReaderArray::begin() JsonReaderIterator JsonReaderArray::begin()
{ {
return JsonReaderIterator(m_value.Begin()); return JsonReaderIterator(m_value.Begin(), m_hasReadError);
} }
JsonReaderIterator JsonReaderArray::end() JsonReaderIterator JsonReaderArray::end()
{ {
return JsonReaderIterator(m_value.End()); return JsonReaderIterator(m_value.End(), m_hasReadError);
} }
JsonReaderObject::JsonReaderObject(JsonValue& value, bool parseError): JsonReaderObject::JsonReaderObject(JsonValue& value, bool& parseError):
m_value(value), m_value(value),
m_hasReadError(parseError) m_hasReadError(parseError)
{ {
@ -284,13 +285,15 @@ namespace base
JsonReaderObject JsonReaderObject::ReadObject(const char* name) const JsonReaderObject JsonReaderObject::ReadObject(const char* name) const
{ {
JsonValue& value = m_value[name]; JsonValue& value = m_value[name];
return JsonReaderObject(value, !value.IsObject()); m_hasReadError |= !value.IsObject();
return JsonReaderObject(value, m_hasReadError);
} }
JsonReaderArray JsonReaderObject::ReadArray(const char* name) const JsonReaderArray JsonReaderObject::ReadArray(const char* name) const
{ {
JsonValue& value = m_value[name]; JsonValue& value = m_value[name];
return JsonReaderArray(value, !value.IsArray()); m_hasReadError |= !value.IsArray();
return JsonReaderArray(value, m_hasReadError);
} }
bool JsonReaderObject::ReadBool(const char* name) bool JsonReaderObject::ReadBool(const char* name)
@ -450,6 +453,18 @@ namespace base
auto& document = m_document; auto& document = m_document;
document.ParseStream<flags>(m_fileStream); document.ParseStream<flags>(m_fileStream);
return JsonReaderObject(document, document.HasParseError()); m_hasParseError = document.HasParseError();
m_hasReadError = false;
return JsonReaderObject(document, m_hasReadError);
}
bool JsonReaderFile::HasParseError() const
{
return m_hasParseError;
}
bool JsonReaderFile::HasReadError() const
{
return m_hasReadError;
} }
} }

View File

@ -59,7 +59,7 @@ namespace base
using JsonValue = rapidjson::GenericValue<rapidjson::ASCII<>>; using JsonValue = rapidjson::GenericValue<rapidjson::ASCII<>>;
public: public:
explicit JsonReaderIterator(JsonValue* value); explicit JsonReaderIterator(JsonValue* value, bool& hasReadError);
JsonReaderObject operator*() const; JsonReaderObject operator*() const;
JsonReaderIterator& operator++(); JsonReaderIterator& operator++();
@ -68,6 +68,7 @@ namespace base
private: private:
JsonValue* m_value; JsonValue* m_value;
bool& m_hasReadError;
}; };
class JsonReaderArray class JsonReaderArray
@ -76,7 +77,7 @@ namespace base
using JsonValue = rapidjson::GenericValue<rapidjson::ASCII<>>; using JsonValue = rapidjson::GenericValue<rapidjson::ASCII<>>;
public: public:
explicit JsonReaderArray(JsonValue& value, bool parseError); explicit JsonReaderArray(JsonValue& value, bool& parseError);
bool HasReadError() const; bool HasReadError() const;
@ -89,7 +90,7 @@ namespace base
{ {
c.resize(m_value.Size()); c.resize(m_value.Size());
std::size_t index = 0; std::size_t index = 0;
for (base::JsonReaderObject& obj : *this) for (base::JsonReaderObject obj : *this)
{ {
fn(obj, c[index++]); fn(obj, c[index++]);
} }
@ -97,7 +98,7 @@ namespace base
private: private:
JsonValue& m_value; JsonValue& m_value;
bool m_hasReadError; bool& m_hasReadError;
}; };
class JsonReaderObject class JsonReaderObject
@ -106,7 +107,7 @@ namespace base
using JsonValue = rapidjson::GenericValue<rapidjson::ASCII<>>; using JsonValue = rapidjson::GenericValue<rapidjson::ASCII<>>;
public: public:
explicit JsonReaderObject(JsonValue& value, bool parseError); explicit JsonReaderObject(JsonValue& value, bool& parseError);
bool HasReadError() const; bool HasReadError() const;
@ -128,7 +129,7 @@ namespace base
private: private:
JsonValue& m_value; JsonValue& m_value;
bool m_hasReadError; bool& m_hasReadError;
}; };
class JsonReaderFile class JsonReaderFile
@ -138,8 +139,13 @@ namespace base
JsonReaderObject ParseObject(); JsonReaderObject ParseObject();
bool HasParseError() const;
bool HasReadError() const;
private: private:
rapidjson::FileReadStream m_fileStream; rapidjson::FileReadStream m_fileStream;
rapidjson::GenericDocument<rapidjson::ASCII<>> m_document; rapidjson::GenericDocument<rapidjson::ASCII<>> m_document;
bool m_hasParseError;
bool m_hasReadError;
}; };
} }