<commit_before>#ifndef __CONFIG_H__
#define __CONFIG_H__
// Copyright (c) 2009 - Mozy, Inc.

#include "predef.h"

#include <set>
#include <sstream>
#include <string>
#include <vector>

#include <boost/function.hpp>
#include <boost/shared_ptr.hpp>

#include "assert.h"
#include "json.h"

namespace Mordor {

class ConfigVarBase
{
public:
    typedef boost::shared_ptr<ConfigVarBase> ptr;

    struct Comparator
    {
        bool operator() (const ConfigVarBase::ptr &lhs, const ConfigVarBase::ptr &rhs) const;
    };

public:
    ConfigVarBase(const std::string &name, const std::string &description = "",
        bool dynamic = true, bool automatic = false)
        : m_name(name),
          m_description(description),
          m_dynamic(dynamic),
          m_automatic(automatic)
    {}
    virtual ~ConfigVarBase() {}

    std::string name() const { return m_name; }
    std::string description() const { return m_description; }
    bool dynamic() const { return m_dynamic; }
    bool automatic() const { return m_automatic; }

    void monitor(boost::function<void ()> dg) { m_dgs.push_back(dg); }

    virtual std::string toString() const { return ""; };
    virtual void fromString(const std::string &str) {};

private:
    std::string m_name, m_description;
    bool m_dynamic, m_automatic;

protected:
    std::vector<boost::function<void ()> > m_dgs;
};

template <class T>
class ConfigVar : public ConfigVarBase
{
public:
    typedef boost::shared_ptr<ConfigVar> ptr;

public:
    ConfigVar(const std::string &name, const T &defaultValue,
        const std::string &description = "", bool dynamic = true,
        bool automatic = false)
        : ConfigVarBase(name, description, dynamic, automatic),
          m_val(defaultValue)
    {}

    std::string toString() const
    {
        std::ostringstream os;
        os << m_val;
        return os.str();
    }

    void fromString(const std::string &str)
    {
        std::istringstream is(str);
        T v;
        is >> v;
        val(v);
    }

    // TODO: atomicCompareExchange and/or mutex<commit_msg>Fix for istringstream breaking up spaces in config vars<commit_after>#ifndef __CONFIG_H__
#define __CONFIG_H__
// Copyright (c) 2009 - Mozy, Inc.

#include "predef.h"

#include <set>
#include <sstream>
#include <string>
#include <vector>

#include <boost/function.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/shared_ptr.hpp>

#include "assert.h"
#include "json.h"

namespace Mordor {

class ConfigVarBase
{
public:
    typedef boost::shared_ptr<ConfigVarBase> ptr;

    struct Comparator
    {
        bool operator() (const ConfigVarBase::ptr &lhs, const ConfigVarBase::ptr &rhs) const;
    };

public:
    ConfigVarBase(const std::string &name, const std::string &description = "",
        bool dynamic = true, bool automatic = false)
        : m_name(name),
          m_description(description),
          m_dynamic(dynamic),
          m_automatic(automatic)
    {}
    virtual ~ConfigVarBase() {}

    std::string name() const { return m_name; }
    std::string description() const { return m_description; }
    bool dynamic() const { return m_dynamic; }
    bool automatic() const { return m_automatic; }

    void monitor(boost::function<void ()> dg) { m_dgs.push_back(dg); }

    virtual std::string toString() const { return ""; };
    virtual void fromString(const std::string &str) {};

private:
    std::string m_name, m_description;
    bool m_dynamic, m_automatic;

protected:
    std::vector<boost::function<void ()> > m_dgs;
};

template <class T>
class ConfigVar : public ConfigVarBase
{
public:
    typedef boost::shared_ptr<ConfigVar> ptr;

public:
    ConfigVar(const std::string &name, const T &defaultValue,
        const std::string &description = "", bool dynamic = true,
        bool automatic = false)
        : ConfigVarBase(name, description, dynamic, automatic),
          m_val(defaultValue)
    {}

    std::string toString() const
    {
        return boost::lexical_cast<std::string>(m_val);
    }

    void fromString(const std::string &str)
    {
        val(boost::lexical_cast<T>(str));
    }

    // TODO: atomicCompareExchange and/or mutex
{'fraction_non_alphanumeric': 0.12575138254388074, 'fraction_numerical': 0.0019235393123346958, 'mean_word_length': 3.369747899159664, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 32, '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': '2830178', 'n_tokens_mistral': 1307, 'n_tokens_neox': 1278, 'n_words': 329}