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