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