aboutsummaryrefslogtreecommitdiff
path: root/src/json.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/json.hpp')
-rw-r--r--src/json.hpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/json.hpp b/src/json.hpp
index 8ecd947..fb3a0b0 100644
--- a/src/json.hpp
+++ b/src/json.hpp
@@ -1,3 +1,5 @@
+#pragma once
+
#include "json.h"
#include <stdexcept>
@@ -53,4 +55,21 @@ namespace TehJSON
};
data = std::make_shared<T>(value);
}
+
+ template<typename T>
+ std::vector<T> JSON::readVector(TokenType type, T(*strToT)(const std::string))
+ {
+ std::vector<T> vec;
+ while(nextTokenType() != TokenType::RSquare)
+ {
+ if(nextTokenType() != type)
+ throw std::runtime_error("Array must be of all the same type");
+ vec.push_back(strToT(consume(type).content));
+ if(nextTokenType() == TokenType::Comma)
+ {
+ consume(TokenType::Comma);
+ }
+ }
+ return vec;
+ }
}