Fixed assigning a temporary to a non const reference
This commit is contained in:
parent
4e4186d49e
commit
42955b7e01
@ -218,14 +218,15 @@ namespace base
|
||||
JsonWriterFile::WriteBits(name, data, numBytes * 8);
|
||||
}
|
||||
|
||||
JsonReaderIterator::JsonReaderIterator(JsonValue* value):
|
||||
m_value(value)
|
||||
JsonReaderIterator::JsonReaderIterator(JsonValue* value, bool& hasReadError):
|
||||
m_value(value),
|
||||
m_hasReadError(hasReadError)
|
||||
{
|
||||
}
|
||||
|
||||
JsonReaderObject JsonReaderIterator::operator*() const
|
||||
{
|
||||
return JsonReaderObject(*m_value, false);
|
||||
return JsonReaderObject(*m_value, m_hasReadError);
|
||||
}
|
||||
|
||||
JsonReaderIterator& JsonReaderIterator::operator++()
|
||||
@ -244,7 +245,7 @@ namespace base
|
||||
return m_value != other.m_value;
|
||||
}
|
||||
|
||||
JsonReaderArray::JsonReaderArray(JsonValue& value, bool parseError):
|
||||
JsonReaderArray::JsonReaderArray(JsonValue& value, bool& parseError):
|
||||
m_value(value),
|
||||
m_hasReadError(parseError)
|
||||
{
|
||||
@ -262,15 +263,15 @@ namespace base
|
||||
|
||||
JsonReaderIterator JsonReaderArray::begin()
|
||||
{
|
||||
return JsonReaderIterator(m_value.Begin());
|
||||
return JsonReaderIterator(m_value.Begin(), m_hasReadError);
|
||||
}
|
||||
|
||||
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_hasReadError(parseError)
|
||||
{
|
||||
@ -284,13 +285,15 @@ namespace base
|
||||
JsonReaderObject JsonReaderObject::ReadObject(const char* name) const
|
||||
{
|
||||
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
|
||||
{
|
||||
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)
|
||||
@ -450,6 +453,18 @@ namespace base
|
||||
|
||||
auto& document = m_document;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ namespace base
|
||||
using JsonValue = rapidjson::GenericValue<rapidjson::ASCII<>>;
|
||||
|
||||
public:
|
||||
explicit JsonReaderIterator(JsonValue* value);
|
||||
explicit JsonReaderIterator(JsonValue* value, bool& hasReadError);
|
||||
|
||||
JsonReaderObject operator*() const;
|
||||
JsonReaderIterator& operator++();
|
||||
@ -68,6 +68,7 @@ namespace base
|
||||
|
||||
private:
|
||||
JsonValue* m_value;
|
||||
bool& m_hasReadError;
|
||||
};
|
||||
|
||||
class JsonReaderArray
|
||||
@ -76,7 +77,7 @@ namespace base
|
||||
using JsonValue = rapidjson::GenericValue<rapidjson::ASCII<>>;
|
||||
|
||||
public:
|
||||
explicit JsonReaderArray(JsonValue& value, bool parseError);
|
||||
explicit JsonReaderArray(JsonValue& value, bool& parseError);
|
||||
|
||||
bool HasReadError() const;
|
||||
|
||||
@ -89,7 +90,7 @@ namespace base
|
||||
{
|
||||
c.resize(m_value.Size());
|
||||
std::size_t index = 0;
|
||||
for (base::JsonReaderObject& obj : *this)
|
||||
for (base::JsonReaderObject obj : *this)
|
||||
{
|
||||
fn(obj, c[index++]);
|
||||
}
|
||||
@ -97,7 +98,7 @@ namespace base
|
||||
|
||||
private:
|
||||
JsonValue& m_value;
|
||||
bool m_hasReadError;
|
||||
bool& m_hasReadError;
|
||||
};
|
||||
|
||||
class JsonReaderObject
|
||||
@ -106,7 +107,7 @@ namespace base
|
||||
using JsonValue = rapidjson::GenericValue<rapidjson::ASCII<>>;
|
||||
|
||||
public:
|
||||
explicit JsonReaderObject(JsonValue& value, bool parseError);
|
||||
explicit JsonReaderObject(JsonValue& value, bool& parseError);
|
||||
|
||||
bool HasReadError() const;
|
||||
|
||||
@ -128,7 +129,7 @@ namespace base
|
||||
|
||||
private:
|
||||
JsonValue& m_value;
|
||||
bool m_hasReadError;
|
||||
bool& m_hasReadError;
|
||||
};
|
||||
|
||||
class JsonReaderFile
|
||||
@ -138,8 +139,13 @@ namespace base
|
||||
|
||||
JsonReaderObject ParseObject();
|
||||
|
||||
bool HasParseError() const;
|
||||
bool HasReadError() const;
|
||||
|
||||
private:
|
||||
rapidjson::FileReadStream m_fileStream;
|
||||
rapidjson::GenericDocument<rapidjson::ASCII<>> m_document;
|
||||
bool m_hasParseError;
|
||||
bool m_hasReadError;
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user