00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "AlignmentInfoCollection.h"
00021
00022 namespace Moses
00023 {
00024
00025 AlignmentInfoCollection AlignmentInfoCollection::s_instance;
00026
00027 AlignmentInfoCollection::AlignmentInfoCollection()
00028 {
00029 std::set<std::pair<size_t,size_t> > pairs;
00030 m_emptyAlignmentInfo = Add(pairs);
00031 }
00032
00033 AlignmentInfoCollection::~AlignmentInfoCollection()
00034 {}
00035
00036 const AlignmentInfo &AlignmentInfoCollection::GetEmptyAlignmentInfo() const
00037 {
00038 return *m_emptyAlignmentInfo;
00039 }
00040
00041 AlignmentInfo const *
00042 AlignmentInfoCollection::
00043 Add(AlignmentInfo const& ainfo)
00044 {
00045 #ifdef WITH_THREADS
00046 {
00047 boost::shared_lock<boost::shared_mutex> read_lock(m_accessLock);
00048 AlignmentInfoSet::const_iterator i = m_collection.find(ainfo);
00049 if (i != m_collection.end())
00050 return &*i;
00051 }
00052 boost::unique_lock<boost::shared_mutex> lock(m_accessLock);
00053 #endif
00054 std::pair<AlignmentInfoSet::iterator, bool> ret = m_collection.insert(ainfo);
00055 return &(*ret.first);
00056 }
00057
00058
00059
00060 }