Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHieu Hoang <hieuhoang@gmail.com>2014-11-27 20:49:08 +0300
committerHieu Hoang <hieuhoang@gmail.com>2014-11-27 20:49:08 +0300
commitb70c34a083ab6a00fc071d40889e0cd9fb81a7b0 (patch)
treef110af5b3595dfce9d38d6eed14c8edce4f981d3
parent604208964a6339c93e8c90614ad364ede535c83b (diff)
make GetParam() a const method with no side effect
-rw-r--r--moses/Parameter.h15
-rw-r--r--moses/Util.h18
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);