<commit_before>// The libMesh Finite Element Library.
// Copyright (C) 2002-2017 <NAME>, <NAME>, <NAME>

// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.

// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA



#ifndef LIBMESH_PARAMETERS_H
#define LIBMESH_PARAMETERS_H

// C++ includes
#include <typeinfo>
#include <string>
#include <map>

// Local includes
#include "libmesh/libmesh_common.h"
#include "libmesh/reference_counted_object.h"
#include "libmesh/print_trace.h"

// C++ includes
#include <cstddef>
#include <map>
#include <string>
#include <typeinfo>
#include <sstream>

namespace libMesh
{
/**
 * Helper functions for printing scalar, vector and vector<vector> types.  Called from Parameters::Parameter<T>::print(...).
 */
template<typename P>
void print_helper(std::ostream & os, const P * param);

template<typename P>
void print_helper(std::ostream & os, const std::vector<P> * param);

template<typename P>
void print_helper(std::ostream & os, const std::vector<std::vector<P>> * param);

/**
 * This class provides the ability to map between
 * arbitrary, user-defined strings and several data
 * types.  This can be used to provide arbitrary
 * user-specified options.
 *
 * \author <NAME>
 * \date 2004
 */
class Parameters
{
public:

  /**
   * Default constructor.  Does nothing.
   */
  Parameters () {}

  /**
   * Copy constructor.
   */
  Parameters (const Parameters &);

  /**
   * Destructor.  Clears any allocated memory.
   */
  virtual ~Parameters ();

  /**
   * Assignment operator.  Removes all parameters in \p this
   * and inserts copies of all parameters from \p source
   */
  virtual Parameters & operator= (const Parameters & source);

  /**
   * Addition/Assignment operator.  Inserts copies of all parameters
   * from \p source.  Any parameters of the same name already in \p
   * this are replaced.
   */
  virtual Parameters & operator+= (const Parameters & source);

  /**
   * \returns \p true if a parameter of type \p T
   * with a specified name exists, \p false otherwise.
   *
   * If RTTI has been disabled then we return \p true
   * if a parameter of specified name exists regardless of its type.
   */
  template <typename T>
  bool have_parameter (const std::string &) const;

  /**
   * \returns A constant reference to the specified parameter
   * value.  Requires, of course, that the parameter exists.
   */
  template <typename T>
  const T & get (const std::string &) const;

  /**
   * Inserts a new Parameter into the object but does not return
   * a writable reference.  The value of the newly inserted
   * parameter may not be valid.
   */
  template <typename T>
  void insert (const std::string &);

  /**
   * \returns A writable reference to the specified parameter.
   * This method will create the parameter if it does not exist,
   * so it can be used to define parameters which will later be
   * accessed with the \p get() member.
   */
  template <typename T>
  T & set (const std::string &);

  /**
   * Overridable function to set any extended attributes for
   * classes inheriting from this class.
   */
  virtual void set_attributes(const std::string &, bool /*inserted_only*/) {}

  /**
   * Removes the specified parameter from the list, if it exists.
   */
  void remove (const std::string &);

  /**
   * \returns The total number of parameters.
   */
  std::size_t n_parameters () const { return _values.size(); }

#ifdef LIBMESH_HAVE_RTTI
  /**
   * \returns The number of parameters of the requested type.
   */
  template <typename T>
  unsigned int n_parameters () const;
#endif // LIBMESH_HAVE_RTTI

  /**
   * Clears internal data structures & frees any allocated memory.
   */
  virtual void clear ();

  /**
   * Prints the contents, by default to libMesh::out.
   */
  void print (std::ostream & os=libMesh::out) const;

private:

  /**
   * Abstract definition of a parameter value.
   */
  class Value : public ReferenceCountedObject<Value>
  {
  public:

    /**
     * Destructor.
     */
    virtual ~Value() {}

#ifdef LIBMESH_HAVE_RTTI
    /**
     * String identifying the type of parameter stored.
     * Must be reimplemented in derived classes.
     */
    virtual std::string type () const = 0;
#endif // LIBMESH_HAVE_RTTI

    /**
     * Prints the parameter value to the specified stream.
     * Must be reimplemented in derived classes.
     */
    virtual void print(std::ostream &) const = 0;

    /**
     * Clone this value.  Useful in copy-construction.
     * Must be reimplemented in derived classes.
     */
    virtual Value * clone () const = 0;
  };

public:

  /**
   * Concrete definition of a parameter value
   * for a specified type.
   */
  template <typename T>
  class Parameter : public Value
  {
  public:

    /**
     * \returns A read-only reference to the parameter value.<commit_msg>Make Parameters::Value public to allow iterators to use the Value type<commit_after>// The libMesh Finite Element Library.
// Copyright (C) 2002-2017 <NAME>, <NAME>, <NAME>

// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.

// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA



#ifndef LIBMESH_PARAMETERS_H
#define LIBMESH_PARAMETERS_H

// C++ includes
#include <typeinfo>
#include <string>
#include <map>

// Local includes
#include "libmesh/libmesh_common.h"
#include "libmesh/reference_counted_object.h"
#include "libmesh/print_trace.h"

// C++ includes
#include <cstddef>
#include <map>
#include <string>
#include <typeinfo>
#include <sstream>

namespace libMesh
{
/**
 * Helper functions for printing scalar, vector and vector<vector> types.  Called from Parameters::Parameter<T>::print(...).
 */
template<typename P>
void print_helper(std::ostream & os, const P * param);

template<typename P>
void print_helper(std::ostream & os, const std::vector<P> * param);

template<typename P>
void print_helper(std::ostream & os, const std::vector<std::vector<P>> * param);

/**
 * This class provides the ability to map between
 * arbitrary, user-defined strings and several data
 * types.  This can be used to provide arbitrary
 * user-specified options.
 *
 * \author <NAME>
 * \date 2004
 */
class Parameters
{
public:

  /**
   * Default constructor.  Does nothing.
   */
  Parameters () {}

  /**
   * Copy constructor.
   */
  Parameters (const Parameters &);

  /**
   * Destructor.  Clears any allocated memory.
   */
  virtual ~Parameters ();

  /**
   * Assignment operator.  Removes all parameters in \p this
   * and inserts copies of all parameters from \p source
   */
  virtual Parameters & operator= (const Parameters & source);

  /**
   * Addition/Assignment operator.  Inserts copies of all parameters
   * from \p source.  Any parameters of the same name already in \p
   * this are replaced.
   */
  virtual Parameters & operator+= (const Parameters & source);

  /**
   * \returns \p true if a parameter of type \p T
   * with a specified name exists, \p false otherwise.
   *
   * If RTTI has been disabled then we return \p true
   * if a parameter of specified name exists regardless of its type.
   */
  template <typename T>
  bool have_parameter (const std::string &) const;

  /**
   * \returns A constant reference to the specified parameter
   * value.  Requires, of course, that the parameter exists.
   */
  template <typename T>
  const T & get (const std::string &) const;

  /**
   * Inserts a new Parameter into the object but does not return
   * a writable reference.  The value of the newly inserted
   * parameter may not be valid.
   */
  template <typename T>
  void insert (const std::string &);

  /**
   * \returns A writable reference to the specified parameter.
   * This method will create the parameter if it does not exist,
   * so it can be used to define parameters which will later be
   * accessed with the \p get() member.
   */
  template <typename T>
  T & set (const std::string &);

  /**
   * Overridable function to set any extended attributes for
   * classes inheriting from this class.
   */
  virtual void set_attributes(const std::string &, bool /*inserted_only*/) {}

  /**
   * Removes the specified parameter from the list, if it exists.
   */
  void remove (const std::string &);

  /**
   * \returns The total number of parameters.
   */
  std::size_t n_parameters () const { return _values.size(); }

#ifdef LIBMESH_HAVE_RTTI
  /**
   * \returns The number of parameters of the requested type.
   */
  template <typename T>
  unsigned int n_parameters () const;
#endif // LIBMESH_HAVE_RTTI

  /**
   * Clears internal data structures & frees any allocated memory.
   */
  virtual void clear ();

  /**
   * Prints the contents, by default to libMesh::out.
   */
  void print (std::ostream & os=libMesh::out) const;

  /**
   * Abstract definition of a parameter value.
   */
  class Value : public ReferenceCountedObject<Value>
  {
  public:

    /**
     * Destructor.
     */
    virtual ~Value() {}

#ifdef LIBMESH_HAVE_RTTI
    /**
     * String identifying the type of parameter stored.
     * Must be reimplemented in derived classes.
     */
    virtual std::string type () const = 0;
#endif // LIBMESH_HAVE_RTTI

    /**
     * Prints the parameter value to the specified stream.
     * Must be reimplemented in derived classes.
     */
    virtual void print(std::ostream &) const = 0;

    /**
     * Clone this value.  Useful in copy-construction.
     * Must be reimplemented in derived classes.
     */
    virtual Value * clone () const = 0;
  };

  /**
   * Concrete definition of a parameter value
   * for a specified type.
   */
  template <typename T>
  class Parameter : public Value
  {
  public:

    /**
     * \returns A read-only reference to the parameter value.
{'fraction_non_alphanumeric': 0.10254066898190459, 'fraction_numerical': 0.0056662401754706635, 'mean_word_length': 3.057471264367816, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 57, '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': '4642371', 'n_tokens_mistral': 3199, 'n_tokens_neox': 3094, 'n_words': 1271}