]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Properly implement operator== for ParameterHandler.
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 8 Dec 2010 02:56:55 +0000 (02:56 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 8 Dec 2010 02:56:55 +0000 (02:56 +0000)
git-svn-id: https://svn.dealii.org/trunk@22941 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/include/deal.II/base/parameter_handler.h
deal.II/source/base/parameter_handler.cc

index eb723acb64d854fd8b1fcd989ca558ef417c5c53..72b14ce920aa9085c04bf380a070f421b0752203 100644 (file)
@@ -148,11 +148,11 @@ namespace Patterns
   };
 
                        /**
-                    * Returns pointer to the correct 
+                    * Returns pointer to the correct
                     * derived class based on description.
                     */
   PatternBase * pattern_factory (const std::string& description);
-  
+
                                   /**
                                     * Test for the string being an
                                     * integer. If bounds are given
@@ -259,14 +259,14 @@ namespace Patterns
                                        * function.
                                        */
       virtual PatternBase * clone () const;
-      
+
                        /**
                     * Creates new object if the start
                     * of description matches description_init.
-                    * Ownership of that object is 
+                    * Ownership of that object is
                     * transferred to the caller of this
                                        * function.
-                    */      
+                    */
       static Integer* create (const std::string& description);
 
     private:
@@ -407,14 +407,14 @@ namespace Patterns
                                        * function.
                                        */
       virtual PatternBase * clone () const;
-      
+
                        /**
                     * Creates new object if the start
                     * of description matches description_init.
-                    * Ownership of that object is 
+                    * Ownership of that object is
                     * transferred to the caller of this
                                        * function.
-                    */      
+                    */
       static Double* create (const std::string& description);
 
     private:
@@ -508,14 +508,14 @@ namespace Patterns
                                        * bytes) of this object.
                                        */
       unsigned int memory_consumption () const;
-      
+
                        /**
                     * Creates new object if the start
                     * of description matches description_init.
-                    * Ownership of that object is 
+                    * Ownership of that object is
                     * transferred to the caller of this
                                        * function.
-                    */      
+                    */
       static Selection* create (const std::string& description);
 
     private:
@@ -608,14 +608,14 @@ namespace Patterns
                                        * function.
                                        */
       virtual PatternBase * clone () const;
-      
+
                        /**
                     * Creates new object if the start
                     * of description matches description_init.
-                    * Ownership of that object is 
+                    * Ownership of that object is
                     * transferred to the caller of this
                                        * function.
-                    */      
+                    */
       static List* create (const std::string& description);
 
                                       /**
@@ -723,14 +723,14 @@ namespace Patterns
                                        * function.
                                        */
       virtual PatternBase * clone () const;
-      
+
                        /**
                     * Creates new object if the start
                     * of description matches description_init.
-                    * Ownership of that object is 
+                    * Ownership of that object is
                     * transferred to the caller of this
                                        * function.
-                    */      
+                    */
       static MultipleSelection* create (const std::string& description);
 
                                       /**
@@ -789,7 +789,7 @@ namespace Patterns
                                        * match.
                                        */
       virtual std::string description () const;
-      
+
                                       /**
                                        * Return a copy of the
                                        * present object, which is
@@ -800,16 +800,16 @@ namespace Patterns
                                        * function.
                                        */
       virtual PatternBase * clone () const;
-      
+
                              /**
                     * Creates new object if the start
                     * of description matches description_init.
-                    * Ownership of that object is 
+                    * Ownership of that object is
                     * transferred to the caller of this
                                        * function.
-                    */      
-      static Bool* create (const std::string& description);      
-      
+                    */
+      static Bool* create (const std::string& description);
+
     private:
                                       /**
                                        * Initial part of description
@@ -859,16 +859,16 @@ namespace Patterns
                                        * function.
                                        */
       virtual PatternBase * clone () const;
-      
+
                              /**
                     * Creates new object if the start
                     * of description matches description_init.
-                    * Ownership of that object is 
+                    * Ownership of that object is
                     * transferred to the caller of this
                                        * function.
-                    */      
+                    */
       static Anything* create (const std::string& description);
-      
+
     private:
                                       /**
                                        * Initial part of description
@@ -950,15 +950,15 @@ namespace Patterns
                                        * file type flag
                                        */
       FileType  file_type;
-      
+
                              /**
                     * Creates new object if the start
                     * of description matches description_init.
-                    * Ownership of that object is 
+                    * Ownership of that object is
                     * transferred to the caller of this
                                        * function.
-                    */      
-      static FileName* create (const std::string& description);      
+                    */
+      static FileName* create (const std::string& description);
 
     private:
                                       /**
@@ -1020,15 +1020,15 @@ namespace Patterns
                                        * function.
                                        */
       virtual PatternBase * clone () const;
-      
+
                              /**
                     * Creates new object if the start
                     * of description matches description_init.
-                    * Ownership of that object is 
+                    * Ownership of that object is
                     * transferred to the caller of this
                                        * function.
-                    */      
-      static DirectoryName* create (const std::string& description);      
+                    */
+      static DirectoryName* create (const std::string& description);
 
     private:
                                       /**
@@ -2030,16 +2030,16 @@ class ParameterHandler : public Subscriptor
     unsigned int memory_consumption () const;
 
                          /**
-                      * Write the data of this object to 
+                      * Write the data of this object to
                       * a stream for the purpose of serialization.
-                      */ 
+                      */
    template <class Archive>
    void save (Archive & ar, const unsigned int version) const;
 
                          /**
                       * Read the data of this object
                       * from a stream for the purpose of serialization.
-                      */    
+                      */
    template <class Archive>
    void load (Archive & ar, const unsigned int version);
 
@@ -2049,7 +2049,7 @@ class ParameterHandler : public Subscriptor
                          * Test for equality.
                       */
    bool operator == (const ParameterHandler & prm2)  const;
-    
+
                                     /** @addtogroup Exceptions
                                      * @{ */
 
@@ -2602,7 +2602,7 @@ class MultipleParameterLoop : public ParameterHandler
 
 template <class Archive>
 inline
-void 
+void
 ParameterHandler::save (Archive & ar, const unsigned int) const
 {
                                        // Forward to serialization
@@ -2619,10 +2619,10 @@ ParameterHandler::save (Archive & ar, const unsigned int) const
   ar & descriptions;
 }
 
-   
+
 template <class Archive>
 inline
-void 
+void
 ParameterHandler::load (Archive & ar, const unsigned int)
 {
                                        // Forward to serialization
@@ -2639,21 +2639,6 @@ ParameterHandler::load (Archive & ar, const unsigned int)
     patterns.push_back (std_cxx1x::shared_ptr<Patterns::PatternBase>(Patterns::pattern_factory(descriptions[j])));
 }
 
-inline
-bool 
-ParameterHandler::operator == (const ParameterHandler & prm2)  const
-{
-  if(patterns.size() != prm2.patterns.size())
-    return false;
-    
-  for(unsigned int j=0; j<patterns.size(); ++j)
-    if (patterns[j]->description() != prm2.patterns[j]->description())
-      return false;
-      
-  // return !(*entries != *(prm2.entries));
-  return true;
-  // TODO: Fix
-}
 
 DEAL_II_NAMESPACE_CLOSE
 
index 0ed237c25f68645933916f8823bc8f671c351270..04d12d406250bb9d7d18a7edf89bea0198fc4938 100644 (file)
@@ -1958,6 +1958,32 @@ ParameterHandler::memory_consumption () const
 
 
 
+bool
+ParameterHandler::operator == (const ParameterHandler & prm2)  const
+{
+  if(patterns.size() != prm2.patterns.size())
+    return false;
+
+  for(unsigned int j=0; j<patterns.size(); ++j)
+    if (patterns[j]->description() != prm2.patterns[j]->description())
+      return false;
+
+                                  // instead of walking through all
+                                  // the nodes of the two trees
+                                  // entries and prm2.entries and
+                                  // comparing them for equality,
+                                  // simply dump the content of the
+                                  // entire structure into a string
+                                  // and compare those for equality
+  std::ostringstream o1, o2;
+  write_json (o1, *entries);
+  write_json (o2, *prm2.entries);
+  return (o1.str() == o2.str());
+}
+
+
+
+
 MultipleParameterLoop::UserClass::~UserClass ()
 {}
 

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.