Line data Source code
1 : /* Copyright (C) 2025 Robert Schiwon 2 : * 3 : * This file is part of libjdx. 4 : * 5 : * libjdx is free software: you can redistribute it and/or modify it under the 6 : * terms of the GNU Lesser General Public License as published by the Free 7 : * Software Foundation, either version 3 of the License, or (at your option) any 8 : * later version. 9 : * 10 : * libjdx is distributed in the hope that it will be useful, but WITHOUT ANY 11 : * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 12 : * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 13 : * details. 14 : * 15 : * You should have received a copy of the GNU Lesser General Public License 16 : * along with libjdx. If not, see <https://www.gnu.org/licenses/>. 17 : */ 18 : #include "jdx/DataLdr.hpp" 19 : #include "jdx/ParseException.hpp" 20 : #include "util/LdrUtils.hpp" 21 : #include "util/StringUtils.hpp" 22 : 23 218 : libjdx::jdx::DataLdr::DataLdr( 24 218 : std::string label, std::string variableList, io::TextReader& reader) 25 218 : : Ldr{std::move(label)} 26 218 : , m_variableList{std::move(variableList)} 27 : , m_reader{reader} 28 218 : , m_dataPos{reader.tellg()} 29 : { 30 218 : } 31 : 32 354 : const std::string& libjdx::jdx::DataLdr::getVariableList() const 33 : { 34 354 : return m_variableList; 35 : } 36 : 37 212 : libjdx::io::TextReader& libjdx::jdx::DataLdr::getReader() const 38 : { 39 212 : return m_reader; 40 : } 41 : 42 219 : void libjdx::jdx::DataLdr::validateInput(const std::string& label, 43 : const std::string& variableList, const std::string& expectedLabel, 44 : const std::vector<std::string>& expectedVariableLists) 45 : { 46 219 : if (label != expectedLabel) 47 : { 48 1 : throw ParseException("Illegal label at " + expectedLabel 49 2 : + " start encountered: " + label); 50 : } 51 218 : if (std::none_of(expectedVariableLists.begin(), expectedVariableLists.end(), 52 554 : [&variableList](const std::string& expectedVariableList) { 53 554 : return variableList == expectedVariableList; 54 : })) 55 : { 56 4 : throw ParseException("Illegal variable list for " + label 57 8 : + " encountered: " + variableList); 58 : } 59 214 : }