From 5ac7f8ffc7a7534a74c264c04180988d374a3e40 Mon Sep 17 00:00:00 2001 From: bangerth Date: Wed, 8 Dec 2010 02:56:55 +0000 Subject: [PATCH] Properly implement operator== for ParameterHandler. git-svn-id: https://svn.dealii.org/trunk@22941 0785d39b-7218-0410-832d-ea1e28bc413d --- .../include/deal.II/base/parameter_handler.h | 99 ++++++++----------- deal.II/source/base/parameter_handler.cc | 26 +++++ 2 files changed, 68 insertions(+), 57 deletions(-) diff --git a/deal.II/include/deal.II/base/parameter_handler.h b/deal.II/include/deal.II/base/parameter_handler.h index eb723acb64..72b14ce920 100644 --- a/deal.II/include/deal.II/base/parameter_handler.h +++ b/deal.II/include/deal.II/base/parameter_handler.h @@ -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 void save (Archive & ar, const unsigned int version) const; /** * Read the data of this object * from a stream for the purpose of serialization. - */ + */ template 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 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 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::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; jdescription() != prm2.patterns[j]->description()) - return false; - - // return !(*entries != *(prm2.entries)); - return true; - // TODO: Fix -} DEAL_II_NAMESPACE_CLOSE diff --git a/deal.II/source/base/parameter_handler.cc b/deal.II/source/base/parameter_handler.cc index 0ed237c25f..04d12d4062 100644 --- a/deal.II/source/base/parameter_handler.cc +++ b/deal.II/source/base/parameter_handler.cc @@ -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; jdescription() != 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 () {} -- 2.39.5