mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-26 13:23:25 +03:00
TargetPhrase: can store arbitrary data
This commit is contained in:
parent
fd08880bde
commit
9f4ebd83e0
@ -33,6 +33,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#include "util/string_piece.hh"
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/unordered_map.hpp>
|
||||
|
||||
#ifdef HAVE_PROTOBUF
|
||||
#include "rule.pb.h"
|
||||
@ -65,6 +66,8 @@ private:
|
||||
|
||||
const PhraseDictionary *m_container;
|
||||
|
||||
mutable boost::unordered_map<const std::string, boost::shared_ptr<void> > m_data;
|
||||
|
||||
public:
|
||||
TargetPhrase(const PhraseDictionary *pt = NULL);
|
||||
TargetPhrase(std::string out_string, const PhraseDictionary *pt = NULL);
|
||||
@ -166,6 +169,23 @@ public:
|
||||
return m_container;
|
||||
}
|
||||
|
||||
bool SetData(const std::string& key, boost::shared_ptr<void> value) const {
|
||||
std::pair< boost::unordered_map<const std::string, boost::shared_ptr<void> >::iterator, bool > inserted =
|
||||
m_data.insert( std::pair<const std::string, boost::shared_ptr<void> >(key,value) );
|
||||
if (!inserted.second) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
boost::shared_ptr<void> GetData(const std::string& key) const {
|
||||
boost::unordered_map<const std::string, boost::shared_ptr<void> >::const_iterator found = m_data.find(key);
|
||||
if (found == m_data.end()) {
|
||||
return boost::shared_ptr<void>();
|
||||
}
|
||||
return found->second;
|
||||
}
|
||||
|
||||
// To be set by the FF that needs it, by default the rule source = NULL
|
||||
// make a copy of the source side of the rule
|
||||
void SetRuleSource(const Phrase &ruleSource) const;
|
||||
|
Loading…
Reference in New Issue
Block a user