Branch data Line data Source code
1 : : /* 2 : : ** Copyright (C) 2021 CERN 3 : : ** 4 : : ** This software is provided 'as-is', without any express or implied 5 : : ** warranty. In no event will the authors be held liable for any damages 6 : : ** arising from the use of this software. 7 : : ** 8 : : ** Permission is granted to anyone to use this software for any purpose, 9 : : ** including commercial applications, and to alter it and redistribute it 10 : : ** freely, subject to the following restrictions: 11 : : ** 12 : : ** 1. The origin of this software must not be misrepresented; you must not 13 : : ** claim that you wrote the original software. If you use this software 14 : : ** in a product, an acknowledgment in the product documentation would be 15 : : ** appreciated but is not required. 16 : : ** 2. Altered source versions must be plainly marked as such, and must not be 17 : : ** misrepresented as being the original software. 18 : : ** 3. This notice may not be removed or altered from any source distribution. 19 : : ** 20 : : ** Created on: 2022-02-25T11:17:22+01:00 21 : : ** Author: Sylvain Fargier <sfargier> <sylvain.fargier@cern.ch> 22 : : ** 23 : : */ 24 : : 25 : : #define RYML_SINGLE_HDR_DEFINE_NOW 26 : : #include "yml.hpp" 27 : : 28 : : #include <logger/Logger.hpp> 29 : : 30 : : #include "Exception.hpp" 31 : : 32 : : namespace ccut { 33 : : namespace yml { 34 : : 35 : : struct Init 36 : : { 37 : 1 : Init() { init(); } 38 : : }; 39 : : 40 : : static Init i; 41 : : 42 : 2 : static void yamlError(const char *msg, 43 : : size_t msg_len, 44 : : Location, 45 : : void * /*user_data*/) 46 : : { 47 : 2 : std::string errMsg(msg, msg + msg_len); 48 : : 49 : 2 : logger::error("ccut:yml") << "yml error: " << errMsg; 50 : 2 : throw Exception(ErrorCode::InvalidArguments, errMsg); 51 : 2 : } 52 : : 53 : 1 : void init() 54 : : { 55 : 1 : set_callbacks(Callbacks(nullptr, nullptr, nullptr, yamlError)); 56 : 1 : logger::info("ccut:yml") << "initialized"; 57 : 1 : } 58 : : 59 : 0 : Exception make_error(const Parser &parser, 60 : : const NodeRef &ref, 61 : : const std::string &message) 62 : : { 63 : 0 : if (ref.valid()) 64 : : { 65 : 0 : Location loc = parser.location(ref); 66 : 0 : std::ostringstream oss; 67 : 0 : oss << parser.filename().str << ":" << loc.line << ":" << loc.col 68 : 0 : << ": " << message; 69 : 0 : return Exception(ErrorCode::InvalidArguments, oss.str()); 70 : 0 : } 71 : 0 : return Exception(ErrorCode::InvalidArguments, message); 72 : : } 73 : : 74 : : } // namespace yml 75 : : } // namespace ccut