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 <ugermann@inf.ed.ac.uk>2015-03-21 19:12:52 +0300
committerUlrich Germann <ugermann@inf.ed.ac.uk>2015-03-21 19:12:52 +0300
commit8ca11d941d99df42664b32c101020283cc83054e (patch)
treeeac36b128d9bfe22ff598458635ae66cdecbf57b /moses/IOWrapper.cpp
parent85d2567b57af592a3a902209c7b0f3675576aac7 (diff)
1. Lifetime of tasks in ThreadPool is now managed via shared pointers.
2. Code cleanup in IOWrapper and a bit elsewhere.
Diffstat (limited to 'moses/IOWrapper.cpp')
-rw-r--r--moses/IOWrapper.cpp61
1 files changed, 34 insertions, 27 deletions
diff --git a/moses/IOWrapper.cpp b/moses/IOWrapper.cpp
index 99897e289..92994e234 100644
--- a/moses/IOWrapper.cpp
+++ b/moses/IOWrapper.cpp
@@ -87,6 +87,9 @@ IOWrapper::IOWrapper()
{
const StaticData &staticData = StaticData::Instance();
+ m_inputType = staticData.GetInputType();
+ m_currentLine = staticData.GetStartTranslationId();
+
m_inputFactorOrder = &staticData.GetInputFactorOrder();
size_t nBestSize = staticData.GetNBestSize();
@@ -223,48 +226,52 @@ IOWrapper::~IOWrapper()
delete m_latticeSamplesStream;
}
-InputType*
-IOWrapper::
-GetInput(InputType* inputType)
-{
- if(inputType->Read(*m_inputStream, *m_inputFactorOrder)) {
- return inputType;
- } else {
- delete inputType;
- return NULL;
- }
-}
-
-bool
-IOWrapper
-::ReadInput(InputTypeEnum inputType,
- InputType*& source,
- TranslationTask const* ttask)
+// InputType*
+// IOWrapper::
+// GetInput(InputType* inputType)
+// {
+// if(inputType->Read(*m_inputStream, *m_inputFactorOrder)) {
+// return inputType;
+// } else {
+// delete inputType;
+// return NULL;
+// }
+// }
+
+boost::shared_ptr<InputType>
+IOWrapper::ReadInput()
{
- delete source;
- switch(inputType) {
+ boost::shared_ptr<InputType> source;
+ switch(m_inputType) {
case SentenceInput:
- source = GetInput(new Sentence(ttask));
+ source.reset(new Sentence);
break;
case ConfusionNetworkInput:
- source = GetInput(new ConfusionNet(ttask));
+ source.reset(new ConfusionNet);
break;
case WordLatticeInput:
- source = GetInput(new WordLattice(ttask));
+ source.reset(new WordLattice);
break;
case TreeInputType:
- source = GetInput(new TreeInput(ttask));
+ source.reset(new TreeInput);
break;
case TabbedSentenceInput:
- source = GetInput(new TabbedSentence(ttask));
+ source.reset(new TabbedSentence);
break;
case ForestInputType:
- source = GetInput(new ForestInput(ttask));
+ source.reset(new ForestInput);
break;
default:
- TRACE_ERR("Unknown input type: " << inputType << "\n");
+ TRACE_ERR("Unknown input type: " << m_inputType << "\n");
}
- return (source ? true : false);
+#ifdef WITH_THREADS
+ boost::lock_guard<boost::mutex> lock(m_lock);
+#endif
+ if (source->Read(*m_inputStream, *m_inputFactorOrder))
+ source->SetTranslationId(m_currentLine++);
+ else
+ source.reset();
+ return source;
}
} // namespace