X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fio%2Ftoken.cpp;h=99b25b6690a168c727c63e623fcff426c62a59ca;hb=d6d568f97e755bf44f048975b375ed8cbcd6ac91;hp=588c125674b870d126e29147e16402994757a611;hpb=d507e4b06e32aff46caacf961b310ba1050b232f;p=blank.git diff --git a/src/io/token.cpp b/src/io/token.cpp index 588c125..99b25b6 100644 --- a/src/io/token.cpp +++ b/src/io/token.cpp @@ -286,7 +286,7 @@ const Token &TokenStreamReader::Peek() { } -void TokenStreamReader::Assert(Token::Type t) { +void TokenStreamReader::Assert(Token::Type t) const { if (GetType() != t) { stringstream s; s << "unexpected token in input stream: expected " << t << ", but got " << in.Current(); @@ -336,6 +336,10 @@ void TokenStreamReader::ReadString(string &out) { out = GetValue(); } +void TokenStreamReader::ReadRelaxedString(string &out) { + out = GetString(); +} + void TokenStreamReader::ReadVec(glm::vec2 &v) { Skip(Token::BRACKET_OPEN); @@ -412,9 +416,13 @@ void TokenStreamReader::ReadQuat(glm::quat &q) { bool TokenStreamReader::GetBool() { Next(); + return AsBool(); +} + +bool TokenStreamReader::AsBool() const { switch (GetType()) { case Token::NUMBER: - return GetInt() != 0; + return AsInt() != 0; case Token::IDENTIFIER: case Token::STRING: if (GetValue() == "true" || GetValue() == "yes" || GetValue() == "on") { @@ -435,20 +443,41 @@ bool TokenStreamReader::GetBool() { float TokenStreamReader::GetFloat() { Next(); + return AsFloat(); +} + +float TokenStreamReader::AsFloat() const { Assert(Token::NUMBER); return stof(GetValue()); } int TokenStreamReader::GetInt() { Next(); + return AsInt(); +} + +int TokenStreamReader::AsInt() const { Assert(Token::NUMBER); return stoi(GetValue()); } unsigned long TokenStreamReader::GetULong() { Next(); + return AsULong(); +} + +unsigned long TokenStreamReader::AsULong() const { Assert(Token::NUMBER); return stoul(GetValue()); } +const string &TokenStreamReader::GetString() { + Next(); + return AsString(); +} + +const string &TokenStreamReader::AsString() const { + return GetValue(); +} + }