diff --git a/src/Makefile.am b/src/Makefile.am index 42c6012a19d6a29665eee84418567c8a4c086a53..5908465c5bc107bb405cfca50494adf03d0c7be4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,6 +3,7 @@ bin_PROGRAMS = sand-wedge-2D sand-wedge-3D common_sources = \ assemblers.cc \ boundary_writer.cc \ + enumparser.cc \ friction_writer.cc \ solverfactory.cc \ state.cc \ diff --git a/src/enum_friction_model.cc b/src/enum_friction_model.cc deleted file mode 100644 index e8a7d066a44a61790ee2c798bd2eb2facb3c3149..0000000000000000000000000000000000000000 --- a/src/enum_friction_model.cc +++ /dev/null @@ -1,15 +0,0 @@ -#include <dune/common/exceptions.hh> - -#include "enums.hh" - -template <> struct StringToEnum<Config::FrictionModel> { - static Config::FrictionModel convert(std::string const &s) { - if (s == "Truncated") - return Config::Truncated; - - if (s == "Regularised") - return Config::Regularised; - - DUNE_THROW(Dune::Exception, "failed to parse enum"); - } -}; diff --git a/src/enum_parser.cc b/src/enum_parser.cc deleted file mode 100644 index 041983c900a2b2e2de20e98c40e84542f3a5a15a..0000000000000000000000000000000000000000 --- a/src/enum_parser.cc +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright Carsten Graeser 2012 - -#include <dune/common/exceptions.hh> -#include <dune/common/typetraits.hh> - -template <class Enum> struct StringToEnum : public Dune::NotImplemented {}; - -template <class Enum> -typename Dune::enable_if< - !Dune::IsBaseOf<Dune::NotImplemented, StringToEnum<Enum>>::value, - std::istream &>::type -operator>>(std::istream &lhs, Enum &e) { - std::string s; - lhs >> s; - - try { - e = StringToEnum<Enum>::convert(s); - } - catch (typename Dune::Exception) { - lhs.setstate(std::ios_base::failbit); - } - return lhs; -} diff --git a/src/enum_scheme.cc b/src/enum_scheme.cc deleted file mode 100644 index bcf550596f87f2434aa34e0ec8325b116eec76c3..0000000000000000000000000000000000000000 --- a/src/enum_scheme.cc +++ /dev/null @@ -1,15 +0,0 @@ -#include <dune/common/exceptions.hh> - -#include "enums.hh" - -template <> struct StringToEnum<Config::scheme> { - static Config::scheme convert(std::string const &s) { - if (s == "newmark") - return Config::Newmark; - - if (s == "backwardEuler") - return Config::BackwardEuler; - - DUNE_THROW(Dune::Exception, "failed to parse enum"); - } -}; diff --git a/src/enum_state_model.cc b/src/enum_state_model.cc deleted file mode 100644 index 37902aaca90854d20a57a7243584914144bc6ede..0000000000000000000000000000000000000000 --- a/src/enum_state_model.cc +++ /dev/null @@ -1,15 +0,0 @@ -#include <dune/common/exceptions.hh> - -#include "enums.hh" - -template <> struct StringToEnum<Config::stateModel> { - static Config::stateModel convert(std::string const &s) { - if (s == "AgeingLaw") - return Config::AgeingLaw; - - if (s == "SlipLaw") - return Config::SlipLaw; - - DUNE_THROW(Dune::Exception, "failed to parse enum"); - } -}; diff --git a/src/enum_verbosity.cc b/src/enum_verbosity.cc deleted file mode 100644 index eee21da1034c7d07f0716f31a155fb6951598d72..0000000000000000000000000000000000000000 --- a/src/enum_verbosity.cc +++ /dev/null @@ -1,17 +0,0 @@ -#include <dune/solvers/common/numproc.hh> // Solver::VerbosityMode -#include <dune/common/exceptions.hh> - -template <> struct StringToEnum<Solver::VerbosityMode> { - static Solver::VerbosityMode convert(std::string const &s) { - if (s == "full") - return Solver::FULL; - - if (s == "reduced") - return Solver::REDUCED; - - if (s == "quiet") - return Solver::QUIET; - - DUNE_THROW(Dune::Exception, "failed to parse enum"); - } -}; diff --git a/src/enumparser.cc b/src/enumparser.cc new file mode 100644 index 0000000000000000000000000000000000000000..c081ec490f6cdf2a3f2091c18e334a4995fc81ee --- /dev/null +++ b/src/enumparser.cc @@ -0,0 +1,77 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +// Copyright Carsten Graeser 2012 + +#include <dune/common/exceptions.hh> + +#include "enumparser.hh" + +template <class Enum> +typename Dune::enable_if< + !Dune::IsBaseOf<Dune::NotImplemented, StringToEnum<Enum>>::value, + std::istream &>::type +operator>>(std::istream &lhs, Enum &e) { + std::string s; + lhs >> s; + + try { + e = StringToEnum<Enum>::convert(s); + } + catch (typename Dune::Exception) { + lhs.setstate(std::ios_base::failbit); + } + return lhs; +} + +Config::FrictionModel StringToEnum<Config::FrictionModel>::convert( + std::string const &s) { + if (s == "Truncated") + return Config::Truncated; + + if (s == "Regularised") + return Config::Regularised; + + DUNE_THROW(Dune::Exception, "failed to parse enum"); +} + +Config::scheme StringToEnum<Config::scheme>::convert(std::string const &s) { + if (s == "newmark") + return Config::Newmark; + + if (s == "backwardEuler") + return Config::BackwardEuler; + + DUNE_THROW(Dune::Exception, "failed to parse enum"); +} + +Config::stateModel StringToEnum<Config::stateModel>::convert( + std::string const &s) { + if (s == "AgeingLaw") + return Config::AgeingLaw; + + if (s == "SlipLaw") + return Config::SlipLaw; + + DUNE_THROW(Dune::Exception, "failed to parse enum"); +} + +Solver::VerbosityMode StringToEnum<Solver::VerbosityMode>::convert( + std::string const &s) { + if (s == "full") + return Solver::FULL; + + if (s == "reduced") + return Solver::REDUCED; + + if (s == "quiet") + return Solver::QUIET; + + DUNE_THROW(Dune::Exception, "failed to parse enum"); +} + +template std::istream &operator>>(std::istream &lhs, Config::FrictionModel &); +template std::istream &operator>>(std::istream &lhs, Config::stateModel &); +template std::istream &operator>>(std::istream &lhs, Config::scheme &); +template std::istream &operator>>(std::istream &lhs, Solver::VerbosityMode &); diff --git a/src/enumparser.hh b/src/enumparser.hh new file mode 100644 index 0000000000000000000000000000000000000000..7eaa0fa6ed49e47034ad7b33b3dd6c0c62847f2e --- /dev/null +++ b/src/enumparser.hh @@ -0,0 +1,35 @@ +#ifndef SRC_ENUMPARSER_HH +#define SRC_ENUMPARSER_HH + +// Copyright Carsten Graeser 2012 + +#include <dune/common/typetraits.hh> + +#include <dune/solvers/solvers/solver.hh> + +#include "enums.hh" + +template <class Enum> struct StringToEnum : public Dune::NotImplemented {}; + +template <> struct StringToEnum<Config::FrictionModel> { + static Config::FrictionModel convert(std::string const &s); +}; + +template <> struct StringToEnum<Config::stateModel> { + static Config::stateModel convert(std::string const &s); +}; + +template <> struct StringToEnum<Config::scheme> { + static Config::scheme convert(std::string const &s); +}; + +template <> struct StringToEnum<Solver::VerbosityMode> { + static Solver::VerbosityMode convert(std::string const &s); +}; + +template <class Enum> +typename Dune::enable_if< + !Dune::IsBaseOf<Dune::NotImplemented, StringToEnum<Enum>>::value, + std::istream &>::type +operator>>(std::istream &lhs, Enum &e); +#endif diff --git a/src/sand-wedge.cc b/src/sand-wedge.cc index 04ed67907228a6af3f09de08a764da9892afd960..d94813e8e9b83bf5dbe5c77d587a8ed95905bf1f 100644 --- a/src/sand-wedge.cc +++ b/src/sand-wedge.cc @@ -68,11 +68,7 @@ #include "assemblers.hh" #include "tobool.hh" -#include "enum_parser.cc" -#include "enum_friction_model.cc" -#include "enum_scheme.cc" -#include "enum_state_model.cc" -#include "enum_verbosity.cc" +#include "enumparser.hh" #include "enums.hh" #include "friction_writer.hh" #include "sand-wedge-data/mybody.hh"