Line data Source code
1 : /* 2 : * Copyright (c) 2017 Sebastian Weber, Henri Menke. All rights reserved. 3 : * 4 : * This file is part of the pairinteraction library. 5 : * 6 : * The pairinteraction library is free software: you can redistribute it and/or modify 7 : * it under the terms of the GNU Lesser General Public License as published by 8 : * the Free Software Foundation, either version 3 of the License, or 9 : * (at your option) any later version. 10 : * 11 : * The pairinteraction library is distributed in the hope that it will be useful, 12 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 : * GNU Lesser General Public License for more details. 15 : * 16 : * You should have received a copy of the GNU Lesser General Public License 17 : * along with the pairinteraction library. If not, see <http://www.gnu.org/licenses/>. 18 : */ 19 : 20 : #include "ConfParser.hpp" 21 : #include <boost/property_tree/json_parser.hpp> 22 : #include <boost/property_tree/ptree.hpp> 23 : #include <string> 24 : 25 3 : void Configuration::load_from_json(std::string const &filename) { 26 : using boost::property_tree::ptree; 27 : using boost::property_tree::json_parser::read_json; 28 : 29 6 : ptree pt; 30 3 : read_json(filename, pt); 31 : 32 153 : for (auto const &itr : pt) { 33 150 : params[itr.first] << itr.second.data(); 34 : } 35 3 : } 36 : 37 27 : void Configuration::save_to_json(std::string const &filename) const { 38 : using boost::property_tree::ptree; 39 : using boost::property_tree::json_parser::write_json; 40 : 41 54 : ptree pt; 42 : 43 960 : for (auto const &p : *this) { 44 933 : pt.put(p.first, p.second.str()); 45 : } 46 : 47 27 : write_json(filename, pt); 48 27 : }