X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;ds=sidebyside;f=src%2Fio%2Ftoken.cpp;h=a2ad44c918f0a834a409aa94fc36f4c3877eaabe;hb=5bc84befaa51b81f8f4cfc7d447c553bb471953a;hp=588c125674b870d126e29147e16402994757a611;hpb=ac8bea15a3a4f04a0221adb922f183f83db5ae27;p=blank.git diff --git a/src/io/token.cpp b/src/io/token.cpp index 588c125..a2ad44c 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(); @@ -412,9 +412,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,18 +439,30 @@ 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()); }