diff options
author | Hieu Hoang <hieuhoang@gmail.com> | 2014-11-27 20:49:08 +0300 |
---|---|---|
committer | Hieu Hoang <hieuhoang@gmail.com> | 2014-11-27 20:49:08 +0300 |
commit | b70c34a083ab6a00fc071d40889e0cd9fb81a7b0 (patch) | |
tree | f110af5b3595dfce9d38d6eed14c8edce4f981d3 | |
parent | 604208964a6339c93e8c90614ad364ede535c83b (diff) |
make GetParam() a const method with no side effect
-rw-r--r-- | moses/Parameter.h | 15 | ||||
-rw-r--r-- | moses/Util.h | 18 |
2 files changed, 33 insertions, 0 deletions
diff --git a/moses/Parameter.h b/moses/Parameter.h index 2156949f4..3ebb96200 100644 --- a/moses/Parameter.h +++ b/moses/Parameter.h @@ -27,6 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include <map> #include <vector> #include "TypeDef.h" +#include "Util.h" namespace Moses { @@ -111,8 +112,22 @@ public: } void Save(const std::string path); + + template<typename T> + void SetParameter(T &var, const std::string &name, const T &defaultValue) + { + const PARAM_VEC *params = GetParam2(name); + if (params && params->size()) { + var = Scan<T>( params->at(0)); + } + else { + var = defaultValue; + } + } + }; + } #endif diff --git a/moses/Util.h b/moses/Util.h index acaa4b53c..0e3ead4e1 100644 --- a/moses/Util.h +++ b/moses/Util.h @@ -102,6 +102,24 @@ inline std::string Scan<std::string>(const std::string &input) return input; } +template<> +inline WordAlignmentSort Scan<WordAlignmentSort>(const std::string &input) +{ + return (WordAlignmentSort) Scan<size_t>(input); +} + +template<> +inline InputTypeEnum Scan<InputTypeEnum>(const std::string &input) +{ + return (InputTypeEnum) Scan<size_t>(input); +} + +template<> +inline SearchAlgorithm Scan<SearchAlgorithm>(const std::string &input) +{ + return (SearchAlgorithm) Scan<size_t>(input); +} + //! Specialisation to understand yes/no y/n true/false 0/1 template<> bool Scan<bool>(const std::string &input); |