<commit_before>/*ckwg +5
 * Copyright 2011 by Kitware, Inc. All Rights Reserved. Please refer to
 * KITWARE_LICENSE.TXT for licensing information, or contact General Counsel,
 * Kitware, Inc., 28 Corporate Drive, Clifton Park, NY 12065.
 */

#include "config.h"

#include <boost/algorithm/string/predicate.hpp>
#include <boost/bind.hpp>
#include <boost/foreach.hpp>
#include <boost/none.hpp>

#include <algorithm>
#include <sstream>

/**
 * \file config.cxx
 *
 * \brief Implementation of \link config configuration\endlink in the pipeline.
 */

namespace vistk
{

config::key_t const config::block_sep = key_t(":");
config::key_t const config::global_value = key_t("_global");

static bool does_not_begin_with(config::key_t const& key, config::key_t const& name);
static config::key_t strip_block_name(config::key_t const& key);

config_t
config
::empty_config(key_t const& name)
{
  return config_t(new config(name));
}

config
::~config()
{
}

config_t
config
::subblock(key_t const& key) const
{
  config_t config = empty_config(key);
  key_t const block_start = key + block_sep;
  key_t const global_start = global_value + block_sep;

  store_t::const_iterator i = m_store.begin();
  store_t::const_iterator i_end = m_store.end();

  for (; i != i_end; ++i)
  {
    if (boost::starts_with(i->first, block_start))
    {
      config->set_value(i->first.substr(block_start.size()), i->second);
    }
    else if (boost::starts_with(i->first, global_start))
    {
      config->set_value(i->first.substr(global_start.size()), i->second);
    }
  }

  return config;
}

config_t
config
::subblock_view(key_t const& key)
{
  return config_t(new config(key, this));
}

void
config
::set_value(key_t const& key, value_t const& value)
{
  if (m_parent)
  {
    m_parent->set_value(m_name + block_sep + key, value);
  }
  else
  {
    if (is_read_only(key))
    {<commit_msg>Simplify the subblock method implementation<commit_after>/*ckwg +5
 * Copyright 2011 by Kitware, Inc. All Rights Reserved. Please refer to
 * KITWARE_LICENSE.TXT for licensing information, or contact General Counsel,
 * Kitware, Inc., 28 Corporate Drive, Clifton Park, NY 12065.
 */

#include "config.h"

#include <boost/algorithm/string/predicate.hpp>
#include <boost/bind.hpp>
#include <boost/foreach.hpp>
#include <boost/none.hpp>

#include <algorithm>
#include <sstream>

/**
 * \file config.cxx
 *
 * \brief Implementation of \link config configuration\endlink in the pipeline.
 */

namespace vistk
{

config::key_t const config::block_sep = key_t(":");
config::key_t const config::global_value = key_t("_global");

static bool does_not_begin_with(config::key_t const& key, config::key_t const& name);
static config::key_t strip_block_name(config::key_t const& key);

config_t
config
::empty_config(key_t const& name)
{
  return config_t(new config(name));
}

config
::~config()
{
}

config_t
config
::subblock(key_t const& key) const
{
  config_t config = empty_config(key);

  BOOST_FOREACH (key_t const& key_name, available_values())
  {
    if (does_not_begin_with(key_name, key))
    {
      continue;
    }

    key_t const stripped_key_name = strip_block_name(key_name);

    config->set_value(stripped_key_name, get_value(key_name));
  }

  return config;
}

config_t
config
::subblock_view(key_t const& key)
{
  return config_t(new config(key, this));
}

void
config
::set_value(key_t const& key, value_t const& value)
{
  if (m_parent)
  {
    m_parent->set_value(m_name + block_sep + key, value);
  }
  else
  {
    if (is_read_only(key))
    {
{'fraction_non_alphanumeric': 0.13310676862078732, 'fraction_numerical': 0.006796941376380629, 'mean_word_length': 4.5886075949367084, 'pattern_counts': {'":': 2, '<': 15, '<?xml version=': 0, '>': 26, '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': '4126144', 'n_tokens_mistral': 1302, 'n_tokens_neox': 1262, 'n_words': 300}