]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Add Patterns::FileName and Patterns::DirectoryName.
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 25 Oct 2010 13:59:04 +0000 (13:59 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 25 Oct 2010 13:59:04 +0000 (13:59 +0000)
git-svn-id: https://svn.dealii.org/trunk@22473 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/parameter_handler.h
deal.II/base/source/parameter_handler.cc
deal.II/doc/news/changes.h

index cd7e389c3146b9bdda12d7407e85f2c69d2e4b8e..6866be775fc55aede97ae30499b418586b6c5ca3 100644 (file)
@@ -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
+                                   * <i>intent</i> 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 <tt>type</tt<.
+                                       */
+      enum FileType {input = 0, output = 1};
+
+                                      /**
+                                       * Constructor.  The type of the file
+                                       * can be specified by choosing the
+                                       * flag.
+                                       */
+      FileName (const FileType type = input);
+
+                                      /**
+                                       * Return <tt>true</tt> 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 <tt>"[Filename]"</tt>.
+                                       */
+      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
+                                   * <i>intent</i> 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 <tt>true</tt> 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 <tt>"[Filename]"</tt>.
+                                       */
+      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;
+  };
 }
 
 
index b5c817a4c9260b99d6a70ad2da7053a012d52b6e..5a87bb8bf0aac4f1f7aed19234e6d2ed4b82bd2a 100644 (file)
@@ -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 ()
index c0528d3bd089326af21000e2278bba26d0b9902e..e3be4e6935452fdd657647db63f5a1130931448c 100644 (file)
@@ -202,6 +202,13 @@ through DoFHandler::get_tria() and DoFHandler::get_fe(), respectively.
 
 
 <ol>
+  <li><p> 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.
+  <br>
+  (Martin Steigemann 2010/10/25)
+  </p>
+
   <li><p> New: The ParameterHandler class is now built on the
   <a href="http://www.boost.org" target="_top">boost</a>
   <code>property_tree</code> library which provides a much better
@@ -214,7 +221,7 @@ through DoFHandler::get_tria() and DoFHandler::get_fe(), respectively.
   (WB 2010/09/09)
   </p>
 
-  <li><p> Fixed: The ParameterHandler::set functions allowed to set values that
+  <li><p> 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.
   <br>

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.