]> git.localhorst.tv Git - blank.git/blob - src/io/TokenStreamReader.hpp
impersonate command
[blank.git] / src / io / TokenStreamReader.hpp
1 #ifndef BLANK_IO_TOKENSTREAMREADER_HPP_
2 #define BLANK_IO_TOKENSTREAMREADER_HPP_
3
4 #include "Token.hpp"
5 #include "Tokenizer.hpp"
6 #include "../graphics/glm.hpp"
7
8 #include <iosfwd>
9 #include <string>
10
11
12 namespace blank {
13
14 class TokenStreamReader {
15
16 public:
17         explicit TokenStreamReader(std::istream &);
18
19         bool HasMore();
20         const Token &Next();
21         const Token &Peek();
22
23         void Skip(Token::Type);
24
25         void ReadBoolean(bool &);
26         void ReadIdentifier(std::string &);
27         void ReadNumber(float &);
28         void ReadNumber(int &);
29         void ReadNumber(unsigned long &);
30         void ReadString(std::string &);
31         // like ReadString, but does not require the value to be
32         // written as a string literal in source
33         void ReadRelaxedString(std::string &);
34
35         void ReadVec(glm::vec2 &);
36         void ReadVec(glm::vec3 &);
37         void ReadVec(glm::vec4 &);
38
39         void ReadVec(glm::ivec2 &);
40         void ReadVec(glm::ivec3 &);
41         void ReadVec(glm::ivec4 &);
42
43         void ReadQuat(glm::quat &);
44
45         // the Get* functions advance to the next token
46         // the As* functions try to cast the current token
47         // if the value could not be converted, a std::runtime_error is thrown
48         // conversion to string is always possible
49
50         bool GetBool();
51         bool AsBool() const;
52         float GetFloat();
53         float AsFloat() const;
54         int GetInt();
55         int AsInt() const;
56         unsigned long GetULong();
57         unsigned long AsULong() const;
58         const std::string &GetString();
59         const std::string &AsString() const;
60
61 private:
62         void SkipComments();
63
64         void Assert(Token::Type) const;
65         Token::Type GetType() const noexcept;
66         const std::string &GetValue() const noexcept;
67
68         Tokenizer in;
69         bool cached;
70
71 };
72
73 }
74
75 #endif