diff options
| author | Dylan <boss@tehbox.org> | 2026-06-14 22:24:52 +1200 |
|---|---|---|
| committer | Dylan <boss@tehbox.org> | 2026-06-14 22:24:52 +1200 |
| commit | 82a68f09ecf2440b22c2604fe207bbee1c5f4d3a (patch) | |
| tree | 73437353a456a41366cf5a48e52c70d480a925f7 /src/json.hpp | |
| parent | e742522e2f428a17cd389e030d167fadcd25c8ef (diff) | |
| download | tehjson-82a68f09ecf2440b22c2604fe207bbee1c5f4d3a.tar.gz tehjson-82a68f09ecf2440b22c2604fe207bbee1c5f4d3a.zip | |
feat: Added arrays for all literal types
Diffstat (limited to 'src/json.hpp')
| -rw-r--r-- | src/json.hpp | 19 |
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; + } } |
