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:
authorUlrich Germann <Ulrich.Germann@gmail.com>2015-10-28 16:01:11 +0300
committerUlrich Germann <Ulrich.Germann@gmail.com>2015-10-28 16:01:11 +0300
commit07c8614877b3eaef17d9dd3f987b84099c2c8088 (patch)
tree76756279002e903fd1e02f47af65b7f3269a77dc /moses/ContextScope.h
parente3d5c477df3d498afe486ab378231dec65b3c3c8 (diff)
Once set, context weights are now always const on the ContextScope.
Diffstat (limited to 'moses/ContextScope.h')
-rw-r--r--moses/ContextScope.h16
1 files changed, 9 insertions, 7 deletions
diff --git a/moses/ContextScope.h b/moses/ContextScope.h
index 35f9f3166..7d2d6dc3b 100644
--- a/moses/ContextScope.h
+++ b/moses/ContextScope.h
@@ -38,7 +38,7 @@ protected:
#ifdef WITH_THREADS
mutable boost::shared_mutex m_lock;
#endif
- SPTR<std::map<std::string,float> > m_context_weights;
+ SPTR<std::map<std::string,float> const> m_context_weights;
public:
// class write_access
// {
@@ -110,16 +110,17 @@ public:
}
#ifdef HAVE_XMLRPC_C
- SPTR<std::map<std::string,float> >
+ SPTR<std::map<std::string,float> const>
GetContextWeights(xmlrpc_c::value const* spec = NULL) {
if (spec && m_context_weights == NULL) {
boost::unique_lock<boost::shared_mutex> lock(m_lock);
- m_context_weights.reset(new std::map<std::string, float>);
+ SPTR<std::map<std::string,float> > M(new std::map<std::string, float>);
typedef std::map<std::string,xmlrpc_c::value> tmap;
tmap const tmp = static_cast<tmap>(xmlrpc_c::value_struct(*spec));
for(tmap::const_iterator m = tmp.begin(); m != tmp.end(); ++m)
- (*m_context_weights)[m->first] = xmlrpc_c::value_double(m->second);
+ (*M)[m->first] = xmlrpc_c::value_double(m->second);
+ m_context_weights = M;
}
return m_context_weights;
}
@@ -129,7 +130,7 @@ public:
SetContextWeights(std::string const& spec) {
if (m_context_weights) return false;
boost::unique_lock<boost::shared_mutex> lock(m_lock);
- m_context_weights.reset(new std::map<std::string, float>);
+ SPTR<std::map<std::string,float> > M(new std::map<std::string, float>);
// TO DO; This needs to be done with StringPiece.find, not Tokenize
// PRIORITY: low
@@ -137,13 +138,14 @@ public:
for (std::vector<std::string>::iterator it = tokens.begin();
it != tokens.end(); it++) {
std::vector<std::string> key_and_value = Tokenize(*it, ",");
- (*m_context_weights)[key_and_value[0]] = atof(key_and_value[1].c_str());
+ (*M)[key_and_value[0]] = atof(key_and_value[1].c_str());
}
+ m_context_weights = M;
return true;
}
bool
- SetContextWeights(SPTR<std::map<std::string,float> > const& w) {
+ SetContextWeights(SPTR<std::map<std::string,float> const> const& w) {
if (m_context_weights) return false;
boost::unique_lock<boost::shared_mutex> lock(m_lock);
m_context_weights = w;