X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fio%2FTokenStreamReader.hpp;h=ea3a6ccbca1af7d5463d283e8b65329b5da6e889;hb=cdd865c1934eccbb1f1d0ffaf041e53f0fdd524b;hp=caa620705179c3e8ef51e10d04144d1c8043e2e0;hpb=ede25c0a2f59e21521d1cd962e6ea9d78169ca12;p=blank.git diff --git a/src/io/TokenStreamReader.hpp b/src/io/TokenStreamReader.hpp index caa6207..ea3a6cc 100644 --- a/src/io/TokenStreamReader.hpp +++ b/src/io/TokenStreamReader.hpp @@ -3,10 +3,10 @@ #include "Token.hpp" #include "Tokenizer.hpp" +#include "../graphics/glm.hpp" #include #include -#include namespace blank { @@ -14,7 +14,7 @@ namespace blank { class TokenStreamReader { public: - TokenStreamReader(std::istream &); + explicit TokenStreamReader(std::istream &); bool HasMore(); const Token &Next(); @@ -28,6 +28,9 @@ public: void ReadNumber(int &); void ReadNumber(unsigned long &); void ReadString(std::string &); + // like ReadString, but does not require the value to be + // written as a string literal in source + void ReadRelaxedString(std::string &); void ReadVec(glm::vec2 &); void ReadVec(glm::vec3 &); @@ -37,13 +40,28 @@ public: void ReadVec(glm::ivec3 &); void ReadVec(glm::ivec4 &); + void ReadQuat(glm::quat &); + + // the Get* functions advance to the next token + // the As* functions try to cast the current token + // if the value could not be converted, a std::runtime_error is thrown + // conversion to string is always possible + bool GetBool(); + bool AsBool() const; float GetFloat(); + float AsFloat() const; int GetInt(); + int AsInt() const; unsigned long GetULong(); + unsigned long AsULong() const; + const std::string &GetString(); + const std::string &AsString() const; private: - void Assert(Token::Type); + void SkipComments(); + + void Assert(Token::Type) const; Token::Type GetType() const noexcept; const std::string &GetValue() const noexcept;