<commit_before>//----------------------------  parameter_handler.cc  ---------------------------
//    $Id$
//    Version: $Name$
//
//    Copyright (C) 1998, 1999, 2000, 2001, 2002 by the deal.II authors
//
//    This file is subject to QPL and may not be  distributed
//    without copyright and license information. Please refer
//    to the file deal.II/doc/license.html for the  text  and
//    further information on this license.
//
//----------------------------  parameter_handler.cc  ---------------------------


//TODO:[WB] (compiler) replace s.c_str() by s when that is possible

#include <base/parameter_handler.h>
#include <base/logstream.h>
#include <base/memory_consumption.h>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <list>

#ifdef HAVE_STD_STRINGSTREAM
#  include <sstream>
#else
#  include <strstream>
#endif

#ifdef HAVE_STD_NUMERIC_LIMITS
# include <limits>
#endif


namespace Patterns
{  

  PatternBase::~PatternBase ()
  {};


  unsigned int
  PatternBase::memory_consumption () const
  {
    if (dynamic_cast<const Integer*>(this) != 0)
      return sizeof(Integer);
    else if (dynamic_cast<const Double*>(this) != 0)
      return sizeof(Double);
    else if (dynamic_cast<const Bool*>(this) != 0)
      return sizeof(Bool);
    else if (dynamic_cast<const Anything*>(this) != 0)
      return sizeof(Anything);
    else
      return sizeof(*this) + 32;
  };
  


  const int Integer::min_int_value =
#ifdef HAVE_STD_NUMERIC_LIMITS
          std::numeric_limits<int>::min();
#else
          1;
#endif
  
  const int Integer::max_int_value =
#ifdef HAVE_STD_NUMERIC_LIMITS
          std::numeric_limits<int>::max();
#else
          0;
#endif
  

  Integer::Integer (const int lower_bound,
		    const int upper_bound) :
		  lower_bound (lower_bound),
		  upper_bound (upper_bound)
  {};



  bool Integer::match (const std::string &test_string) const
  {
#ifdef HAVE_STD_STRINGSTREAM
    std::istringstream str(test_string.c_str());
#else
    std::istrstream str(test_string.c_str());
#endif
    
    int i;
    if (str >> i)
      {
					 // check whether valid bounds
					 // were specified, and if so
					 // enforce their values
	if (lower_bound <= upper_bound)
	  return ((lower_bound <= i) &&
		  (upper_bound >= i));
	else
	  return true;
      };
  
    return false;
  };



  std::string Integer::description () const
  {
				     // check whether valid bounds
				     // were specified, and if so
				     // output their values
    if (lower_bound <= upper_bound)
      {
#ifdef HAVE_STD_STRINGSTREAM
	std::ostringstream description;	
#else
	std::ostrstream description;
#endif
	
	description << "[Integer range "
		    << lower_bound << "..." << upper_bound
		    << " (inclusive)]";
#ifndef HAVE_STD_STRINGSTREAM
	description << std::ends;
#endif
	return description.str();
      }
    else
				       // if no bounds were given, then
				       // return generic string
      return "[Integer]";
  };



  PatternBase *
  Integer::clone () const
  {
    return new Integer(lower_bound, upper_bound);
  };



  const double Double::min_double_value =
#ifdef HAVE_STD_NUMERIC_LIMITS
          -std::numeric_limits<double>::max();
#else
          1;
#endif
  
  const double Double::max_double_value =
#ifdef HAVE_STD_NUMERIC_LIMITS
          std::numeric_limits<double>::max();
#else
          0;
#endif
  
  Double::Double (const double lower_bound,
		  const double upper_bound) :
		  lower_bound (lower_bound),
		  upper_bound (upper_bound)
  {};



  bool Double::match (const std::string &test_string) const
  {
#ifdef HAVE_STD_STRINGSTREAM
    std::istringstream str(test_string.c_str());
#else
    std::istrstream str(test_string.c_str());
#endif

    double d;
    if (str >> d)
      {
					 // check whether valid bounds
					 // were specified, and if so
					 // enforce their values
	if (lower_bound <= upper_bound)
	  return ((lower_bound <= d) &&
		  (upper_bound >= d));
	else
	  return true;
      };
    return false;
  };



  std::string Double::description () const
  {
				     // check whether valid bounds
				     // were specified, and if so
				     // output their values
    if (lower_bound <= upper_bound)
      {
#ifdef HAVE_STD_STRINGSTREAM
	std::ostringstream description;	<commit_msg>Do as much as the Standard of C++ allows.<commit_after>//----------------------------  parameter_handler.cc  ---------------------------
//    $Id$
//    Version: $Name$
//
//    Copyright (C) 1998, 1999, 2000, 2001, 2002 by the deal.II authors
//
//    This file is subject to QPL and may not be  distributed
//    without copyright and license information. Please refer
//    to the file deal.II/doc/license.html for the  text  and
//    further information on this license.
//
//----------------------------  parameter_handler.cc  ---------------------------

#include <base/parameter_handler.h>
#include <base/logstream.h>
#include <base/memory_consumption.h>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <list>

#ifdef HAVE_STD_STRINGSTREAM
#  include <sstream>
#else
#  include <strstream>
#endif

#ifdef HAVE_STD_NUMERIC_LIMITS
# include <limits>
#endif


namespace Patterns
{  

  PatternBase::~PatternBase ()
  {};


  unsigned int
  PatternBase::memory_consumption () const
  {
    if (dynamic_cast<const Integer*>(this) != 0)
      return sizeof(Integer);
    else if (dynamic_cast<const Double*>(this) != 0)
      return sizeof(Double);
    else if (dynamic_cast<const Bool*>(this) != 0)
      return sizeof(Bool);
    else if (dynamic_cast<const Anything*>(this) != 0)
      return sizeof(Anything);
    else
      return sizeof(*this) + 32;
  };
  


  const int Integer::min_int_value =
#ifdef HAVE_STD_NUMERIC_LIMITS
          std::numeric_limits<int>::min();
#else
          1;
#endif
  
  const int Integer::max_int_value =
#ifdef HAVE_STD_NUMERIC_LIMITS
          std::numeric_limits<int>::max();
#else
          0;
#endif
  

  Integer::Integer (const int lower_bound,
		    const int upper_bound) :
		  lower_bound (lower_bound),
		  upper_bound (upper_bound)
  {};



  bool Integer::match (const std::string &test_string) const
  {
#ifdef HAVE_STD_STRINGSTREAM
    std::istringstream str(test_string);
#else
    std::istrstream str(test_string.c_str());
#endif
    
    int i;
    if (str >> i)
      {
					 // check whether valid bounds
					 // were specified, and if so
					 // enforce their values
	if (lower_bound <= upper_bound)
	  return ((lower_bound <= i) &&
		  (upper_bound >= i));
	else
	  return true;
      };
  
    return false;
  };



  std::string Integer::description () const
  {
				     // check whether valid bounds
				     // were specified, and if so
				     // output their values
    if (lower_bound <= upper_bound)
      {
#ifdef HAVE_STD_STRINGSTREAM
	std::ostringstream description;	
#else
	std::ostrstream description;
#endif
	
	description << "[Integer range "
		    << lower_bound << "..." << upper_bound
		    << " (inclusive)]";
#ifndef HAVE_STD_STRINGSTREAM
	description << std::ends;
#endif
	return description.str();
      }
    else
				       // if no bounds were given, then
				       // return generic string
      return "[Integer]";
  };



  PatternBase *
  Integer::clone () const
  {
    return new Integer(lower_bound, upper_bound);
  };



  const double Double::min_double_value =
#ifdef HAVE_STD_NUMERIC_LIMITS
          -std::numeric_limits<double>::max();
#else
          1;
#endif
  
  const double Double::max_double_value =
#ifdef HAVE_STD_NUMERIC_LIMITS
          std::numeric_limits<double>::max();
#else
          0;
#endif
  
  Double::Double (const double lower_bound,
		  const double upper_bound) :
		  lower_bound (lower_bound),
		  upper_bound (upper_bound)
  {};



  bool Double::match (const std::string &test_string) const
  {
#ifdef HAVE_STD_STRINGSTREAM
    std::istringstream str(test_string);
#else
    std::istrstream str(test_string.c_str());
#endif

    double d;
    if (str >> d)
      {
					 // check whether valid bounds
					 // were specified, and if so
					 // enforce their values
	if (lower_bound <= upper_bound)
	  return ((lower_bound <= d) &&
		  (upper_bound >= d));
	else
	  return true;
      };
    return false;
  };



  std::string Double::description () const
  {
				     // check whether valid bounds
				     // were specified, and if so
				     // output their values
    if (lower_bound <= upper_bound)
      {
#ifdef HAVE_STD_STRINGSTREAM
	std::ostringstream description;	
{'fraction_non_alphanumeric': 0.14114498487316732, 'fraction_numerical': 0.006981615080288574, 'mean_word_length': 2.609827803443931, 'pattern_counts': {'":': 0, '<': 79, '<?xml version=': 0, '>': 55, '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': '5615651', 'n_tokens_mistral': 2901, 'n_tokens_neox': 2595, 'n_words': 704}