From: bangerth Date: Mon, 25 Oct 2010 13:59:04 +0000 (+0000) Subject: Add Patterns::FileName and Patterns::DirectoryName. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=35e306bdf465e1e72e779da4a9981ed577974c14;p=dealii-svn.git Add Patterns::FileName and Patterns::DirectoryName. git-svn-id: https://svn.dealii.org/trunk@22473 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/base/include/base/parameter_handler.h b/deal.II/base/include/base/parameter_handler.h index cd7e389c31..6866be775f 100644 --- a/deal.II/base/include/base/parameter_handler.h +++ b/deal.II/base/include/base/parameter_handler.h @@ -789,6 +789,149 @@ namespace Patterns */ static const char* description_init; }; + + + /** + * A pattern that can be used to indicate + * when a parameter is intended to be the + * name of a file. By itself, this class + * does not check whether the string that + * is given in a parameter file actually + * corresponds to an existing file (it + * could, for example, be the name of a + * file to which you want to write + * output). Functionally, the class is + * therefore equivalent to the Anything + * class. However, it allows to specify the + * intent of a parameter. The flag + * given to the constructor also allows to + * specify whether the file is supposed to + * be an input or output file. + * + * The reason for the existence of this + * class is to support graphical user + * interfaces for editing parameter + * files. These may open a file selection + * dialog if the filename is supposed to + * represent an input file. + */ + class FileName : public PatternBase + { + public: + /** + * Files can be used for input + * or output. This can be + * specified in the constructor + * by choosing the flag typetrue if the + * string matches its + * constraints, i.e. always. + */ + virtual bool match (const std::string &test_string) const; + + /** + * Return a description of + * the pattern that valid + * strings are expected to + * match. Here, this is the + * string "[Filename]". + */ + virtual std::string description () const; + + /** + * Return a copy of the + * present object, which is + * newly allocated on the + * heap. Ownership of that + * object is transferred to + * the caller of this + * function. + */ + virtual PatternBase * clone () const; + + /** + * file type flag + */ + FileType file_type; + + private: + /** + * Initial part of description + */ + static const char* description_init; + }; + + + /** + * A pattern that can be used to indicate + * when a parameter is intended to be the + * name of a directory. By itself, this + * class does not check whether the string + * that is given in a parameter file + * actually corresponds to an existing + * directory. Functionally, the class is + * therefore equivalent to the Anything + * class. However, it allows to specify the + * intent of a parameter. + * + * The reason for the existence of this + * class is to support graphical user + * interfaces for editing parameter + * files. These may open a file selection + * dialog to select or create a directory. + */ + class DirectoryName : public PatternBase + { + public: + /** + * Constructor. + */ + DirectoryName (); + + /** + * Return true if the + * string matches its + * constraints, i.e. always. + */ + virtual bool match (const std::string &test_string) const; + + /** + * Return a description of + * the pattern that valid + * strings are expected to + * match. Here, this is the + * string "[Filename]". + */ + virtual std::string description () const; + + /** + * Return a copy of the + * present object, which is + * newly allocated on the + * heap. Ownership of that + * object is transferred to + * the caller of this + * function. + */ + virtual PatternBase * clone () const; + + private: + /** + * Initial part of description + */ + static const char* description_init; + }; } diff --git a/deal.II/base/source/parameter_handler.cc b/deal.II/base/source/parameter_handler.cc index b5c817a4c9..5a87bb8bf0 100644 --- a/deal.II/base/source/parameter_handler.cc +++ b/deal.II/base/source/parameter_handler.cc @@ -587,9 +587,82 @@ namespace Patterns return new Anything(); } -} // end namespace Patterns + const char* FileName::description_init = "[FileName"; + + + FileName::FileName (const FileType type) + : file_type (type) + {} + + + + bool FileName::match (const std::string &) const + { + return true; + } + + + + std::string FileName::description () const + { + std::ostringstream description; + + description << description_init; + + if (file_type == input) + description << " (Type: input)]"; + else + description << " (Type: output)]"; + + return description.str(); + } + + + + PatternBase * + FileName::clone () const + { + return new FileName(file_type); + } + + + + const char* DirectoryName::description_init = "[DirectoryName"; + + + DirectoryName::DirectoryName () + {} + + + + bool DirectoryName::match (const std::string &) const + { + return true; + } + + + + std::string DirectoryName::description () const + { + std::ostringstream description; + + description << description_init << "]"; + + return description.str(); + } + + + + PatternBase * + DirectoryName::clone () const + { + return new DirectoryName(); + } + +} // end namespace Patterns + ParameterHandler::ParameterHandler () diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index c0528d3bd0..e3be4e6935 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -202,6 +202,13 @@ through DoFHandler::get_tria() and DoFHandler::get_fe(), respectively.
    +
  1. There are now Patterns::FileName and Patterns::DirectoryName classes + that can be used to indicate that a given parameter is supposed to be + a file or directory name. +
    + (Martin Steigemann 2010/10/25) +

    +
  2. New: The ParameterHandler class is now built on the boost property_tree library which provides a much better @@ -214,7 +221,7 @@ through DoFHandler::get_tria() and DoFHandler::get_fe(), respectively. (WB 2010/09/09)

    -
  3. Fixed: The ParameterHandler::set functions allowed to set values that +

  4. Fixed: The ParameterHandler::set() functions allowed to set values that did not satisfy the pattern given during declaration of the parameter. This is now fixed: the functions now throw an exception.