]> git.localhorst.tv Git - blobs.git/blob - src/io/TokenStreamReader.hpp
c9043d181b52ee477741d5c385105b1efec92f0f
[blobs.git] / src / io / TokenStreamReader.hpp
1 #ifndef BLOBS_IO_TOKENSTREAMREADER_HPP_
2 #define BLOBS_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 blobs {
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(double &);
29         void ReadNumber(float &);
30         void ReadNumber(int &);
31         void ReadNumber(unsigned long &);
32         void ReadString(std::string &);
33
34         void ReadVec(glm::vec2 &);
35         void ReadVec(glm::vec3 &);
36         void ReadVec(glm::vec4 &);
37
38         void ReadVec(glm::dvec2 &);
39         void ReadVec(glm::dvec3 &);
40         void ReadVec(glm::dvec4 &);
41
42         void ReadVec(glm::ivec2 &);
43         void ReadVec(glm::ivec3 &);
44         void ReadVec(glm::ivec4 &);
45
46         void ReadQuat(glm::quat &);
47         void ReadQuat(glm::dquat &);
48
49         // the Get* functions advance to the next token
50         // the As* functions try to cast the current token
51         // if the value could not be converted, a std::runtime_error is thrown
52
53         bool GetBool();
54         bool AsBool() const;
55         double GetDouble();
56         double AsDouble() const;
57         float GetFloat();
58         float AsFloat() const;
59         int GetInt();
60         int AsInt() const;
61         unsigned long GetULong();
62         unsigned long AsULong() const;
63
64 private:
65         void SkipComments();
66
67         void Assert(Token::Type) const;
68         Token::Type GetType() const noexcept;
69         const std::string &GetValue() const noexcept;
70
71         Tokenizer in;
72         bool cached;
73
74 };
75
76 }
77 }
78
79 #endif