X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fio%2FTokenStreamReader.hpp;fp=src%2Fio%2FTokenStreamReader.hpp;h=e2945c40cc2b60880261d7b525f8d852844ae753;hb=34e833025f0616ab4b86b808d0ce1cc49cecce5d;hp=0000000000000000000000000000000000000000;hpb=698d8120797383886d1386d3a8ac4b5fc1ca7f16;p=blobs.git diff --git a/src/io/TokenStreamReader.hpp b/src/io/TokenStreamReader.hpp new file mode 100644 index 0000000..e2945c4 --- /dev/null +++ b/src/io/TokenStreamReader.hpp @@ -0,0 +1,71 @@ +#ifndef BLOBS_IO_TOKENSTREAMREADER_HPP_ +#define BLOBS_IO_TOKENSTREAMREADER_HPP_ + +#include "Token.hpp" +#include "Tokenizer.hpp" +#include "../graphics/glm.hpp" + +#include +#include + + +namespace blobs { +namespace io { + +class TokenStreamReader { + +public: + explicit TokenStreamReader(std::istream &); + + bool HasMore(); + const Token &Next(); + const Token &Peek(); + + void Skip(Token::Type); + + void ReadBoolean(bool &); + void ReadIdentifier(std::string &); + void ReadNumber(float &); + void ReadNumber(int &); + void ReadNumber(unsigned long &); + void ReadString(std::string &); + + void ReadVec(glm::vec2 &); + void ReadVec(glm::vec3 &); + void ReadVec(glm::vec4 &); + + void ReadVec(glm::ivec2 &); + 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 + + bool GetBool(); + bool AsBool() const; + float GetFloat(); + float AsFloat() const; + int GetInt(); + int AsInt() const; + unsigned long GetULong(); + unsigned long AsULong() const; + +private: + void SkipComments(); + + void Assert(Token::Type) const; + Token::Type GetType() const noexcept; + const std::string &GetValue() const noexcept; + + Tokenizer in; + bool cached; + +}; + +} +} + +#endif