00001 /*********************************************************************** 00002 Moses - statistical machine translation system 00003 Copyright (C) 2006-2011 University of Edinburgh 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public 00007 License as published by the Free Software Foundation; either 00008 version 2.1 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with this library; if not, write to the Free Software 00017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00018 ***********************************************************************/ 00019 00020 #pragma once 00021 00022 #include "AlignmentInfo.h" 00023 00024 #include <set> 00025 00026 #ifdef WITH_THREADS 00027 #include <boost/thread/shared_mutex.hpp> 00028 #include <boost/thread/locks.hpp> 00029 #endif 00030 00031 namespace Moses 00032 { 00033 00037 class AlignmentInfoCollection 00038 { 00039 public: 00040 static AlignmentInfoCollection &Instance() { 00041 return s_instance; 00042 } 00043 00049 private: 00050 const AlignmentInfo* Add(AlignmentInfo const& ainfo); 00051 00052 public: 00053 template<typename ALNREP> 00054 AlignmentInfo const * 00055 Add(ALNREP const & aln) { 00056 return this->Add(AlignmentInfo(aln)); 00057 } 00058 00060 const AlignmentInfo &GetEmptyAlignmentInfo() const; 00061 00062 private: 00063 typedef std::set<AlignmentInfo, AlignmentInfoOrderer> AlignmentInfoSet; 00064 00065 00067 AlignmentInfoCollection(); 00068 ~AlignmentInfoCollection(); 00069 00070 static AlignmentInfoCollection s_instance; 00071 00072 #ifdef WITH_THREADS 00073 //reader-writer lock 00074 mutable boost::shared_mutex m_accessLock; 00075 #endif 00076 00077 AlignmentInfoSet m_collection; 00078 const AlignmentInfo *m_emptyAlignmentInfo; 00079 }; 00080 00081 }