<commit_before>#include "ConfParser.hpp"
#include <string>
#include <fstream>
#include <iostream>
#include "json/json.h"

Configuration::value::value() : val() {
}
Configuration::value::value(std::stringstream v) {
    val.str(v.str());
}
std::string Configuration::value::str() const {
    return val.str();
}
void Configuration::value::str(std::string s) {
    val.str(s);
}
Configuration::value& Configuration::value::operator=(const Configuration::value& rhs) {
    val.str(std::string());
    val << rhs.str();
    return *this;
}
Configuration::iterator::entry::entry(const std::string key, Configuration::value& value) : key(key), value(value) {
}
Configuration::iterator::iterator(std::map<std::string, Configuration::value>::iterator itr) : itr(itr) {
}
bool Configuration::iterator::operator== (const iterator& other) const {
    return itr == other.itr;
}
bool Configuration::iterator::operator!= (const iterator& other) const {
    return itr != other.itr;
}
const Configuration::iterator& Configuration::iterator::operator++ () {
    ++itr;
    return *this;
}
Configuration::iterator::entry Configuration::iterator::operator* () {
    return iterator::entry(itr->first, itr->second);
}
Configuration::const_iterator::entry::entry(const std::string key, const Configuration::value& value) : key(key), value(value) {
}
Configuration::const_iterator::const_iterator(std::map<std::string, Configuration::value>::const_iterator itr) : itr(itr) {
}
bool Configuration::const_iterator::operator== (const const_iterator& other) const {
    return itr == other.itr;
}
bool Configuration::const_iterator::operator!= (const const_iterator& other) const {
    return itr != other.itr;
}
const Configuration::const_iterator& Configuration::const_iterator::operator++ () {
    ++itr;
    return *this;
}
Configuration::const_iterator::entry Configuration::const_iterator::operator* () {
    return const_iterator::entry(itr->first, itr->second);
}
int Configuration::load_from_json(std::string filename)
{
    Json::Value datadict;
    Json::Reader reader;
    std::ifstream conffile(filename);
    if ( !reader.parse(conffile, datadict) )
    {
        std::cerr << reader.getFormattedErrorMessages();
        conffile.close();
        return 1;
    }
    conffile.close();

    for(Json::Value::iterator itr = datadict.begin(); itr !=datadict.end(); ++itr) {
        params[itr.key().asString()] << itr->asString();
    }

    return 0;
}
int Configuration::save_to_json(std::string filename)
{
    Json::StyledWriter styledWriter;
    Json::Value datadict;
    std::ofstream conffile(filename);
    for (auto p: *this) {
        datadict[p.key] = p.value.str();
    }
    conffile << styledWriter.write(datadict);
    conffile.close();

    return 0;
}
Configuration::value& Configuration::operator [](const std::string& key) {
    return params[key];
}
const Configuration::value& Configuration::operator [](const std::string& key) const{<commit_msg>-> is not overloaded (at least not for me)<commit_after>#include "ConfParser.hpp"
#include <string>
#include <fstream>
#include <iostream>
#include "json/json.h"

Configuration::value::value() : val() {
}
Configuration::value::value(std::stringstream v) {
    val.str(v.str());
}
std::string Configuration::value::str() const {
    return val.str();
}
void Configuration::value::str(std::string s) {
    val.str(s);
}
Configuration::value& Configuration::value::operator=(const Configuration::value& rhs) {
    val.str(std::string());
    val << rhs.str();
    return *this;
}
Configuration::iterator::entry::entry(const std::string key, Configuration::value& value) : key(key), value(value) {
}
Configuration::iterator::iterator(std::map<std::string, Configuration::value>::iterator itr) : itr(itr) {
}
bool Configuration::iterator::operator== (const iterator& other) const {
    return itr == other.itr;
}
bool Configuration::iterator::operator!= (const iterator& other) const {
    return itr != other.itr;
}
const Configuration::iterator& Configuration::iterator::operator++ () {
    ++itr;
    return *this;
}
Configuration::iterator::entry Configuration::iterator::operator* () {
    return iterator::entry(itr->first, itr->second);
}
Configuration::const_iterator::entry::entry(const std::string key, const Configuration::value& value) : key(key), value(value) {
}
Configuration::const_iterator::const_iterator(std::map<std::string, Configuration::value>::const_iterator itr) : itr(itr) {
}
bool Configuration::const_iterator::operator== (const const_iterator& other) const {
    return itr == other.itr;
}
bool Configuration::const_iterator::operator!= (const const_iterator& other) const {
    return itr != other.itr;
}
const Configuration::const_iterator& Configuration::const_iterator::operator++ () {
    ++itr;
    return *this;
}
Configuration::const_iterator::entry Configuration::const_iterator::operator* () {
    return const_iterator::entry(itr->first, itr->second);
}
int Configuration::load_from_json(std::string filename)
{
    Json::Value datadict;
    Json::Reader reader;
    std::ifstream conffile(filename);
    if ( !reader.parse(conffile, datadict) )
    {
        std::cerr << reader.getFormattedErrorMessages();
        conffile.close();
        return 1;
    }
    conffile.close();

    for(Json::Value::iterator itr = datadict.begin(); itr !=datadict.end(); ++itr) {
      params[itr.key().asString()] << (*itr).asString();
    }

    return 0;
}
int Configuration::save_to_json(std::string filename)
{
    Json::StyledWriter styledWriter;
    Json::Value datadict;
    std::ofstream conffile(filename);
    for (auto p: *this) {
        datadict[p.key] = p.value.str();
    }
    conffile << styledWriter.write(datadict);
    conffile.close();

    return 0;
}
Configuration::value& Configuration::operator [](const std::string& key) {
    return params[key];
}
const Configuration::value& Configuration::operator [](const std::string& key) const{
{'fraction_non_alphanumeric': 0.16776149570490145, 'fraction_numerical': 0.001010611419909045, 'mean_word_length': 5.440347071583514, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4971161', 'n_tokens_mistral': 1792, 'n_tokens_neox': 1803, 'n_words': 359}