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);
+ void Assert(Token::Type) const;
Token::Type GetType() const noexcept;
const std::string &GetValue() const noexcept;
}
-void TokenStreamReader::Assert(Token::Type t) {
+void TokenStreamReader::Assert(Token::Type t) const {
if (GetType() != t) {
stringstream s;
s << "unexpected token in input stream: expected " << t << ", but got " << in.Current();
bool TokenStreamReader::GetBool() {
Next();
+ return AsBool();
+}
+
+bool TokenStreamReader::AsBool() const {
switch (GetType()) {
case Token::NUMBER:
- return GetInt() != 0;
+ return AsInt() != 0;
case Token::IDENTIFIER:
case Token::STRING:
if (GetValue() == "true" || GetValue() == "yes" || GetValue() == "on") {
float TokenStreamReader::GetFloat() {
Next();
+ return AsFloat();
+}
+
+float TokenStreamReader::AsFloat() const {
Assert(Token::NUMBER);
return stof(GetValue());
}
int TokenStreamReader::GetInt() {
Next();
+ return AsInt();
+}
+
+int TokenStreamReader::AsInt() const {
Assert(Token::NUMBER);
return stoi(GetValue());
}
unsigned long TokenStreamReader::GetULong() {
Next();
+ return AsULong();
+}
+
+unsigned long TokenStreamReader::AsULong() const {
Assert(Token::NUMBER);
return stoul(GetValue());
}