00001 #include <boost/foreach.hpp>
00002 #include "Bitmaps.h"
00003 #include "Util.h"
00004
00005 using namespace std;
00006
00007 namespace Moses
00008 {
00009 Bitmaps::Bitmaps(size_t inputSize, const std::vector<bool> &initSourceCompleted)
00010 {
00011 m_initBitmap = new Bitmap(inputSize, initSourceCompleted);
00012 m_coll[m_initBitmap];
00013 }
00014
00015 Bitmaps::~Bitmaps()
00016 {
00017 BOOST_FOREACH (const Coll::value_type& myPair, m_coll) {
00018 const Bitmap *bm = myPair.first;
00019 delete bm;
00020 }
00021 }
00022
00023 const Bitmap &Bitmaps::GetNextBitmap(const Bitmap &bm, const Range &range)
00024 {
00025 Bitmap *newBM = new Bitmap(bm, range);
00026
00027 Coll::const_iterator iter = m_coll.find(newBM);
00028 if (iter == m_coll.end()) {
00029 m_coll[newBM] = NextBitmaps();
00030 return *newBM;
00031 } else {
00032 delete newBM;
00033 return *iter->first;
00034 }
00035 }
00036
00037 const Bitmap &Bitmaps::GetBitmap(const Bitmap &bm, const Range &range)
00038 {
00039 Coll::iterator iter = m_coll.find(&bm);
00040 assert(iter != m_coll.end());
00041
00042 const Bitmap *newBM;
00043 NextBitmaps &next = iter->second;
00044 NextBitmaps::const_iterator iterNext = next.find(range);
00045 if (iterNext == next.end()) {
00046
00047 newBM = &GetNextBitmap(bm, range);
00048 next[range] = newBM;
00049 } else {
00050
00051
00052 newBM = iterNext->second;
00053 }
00054 return *newBM;
00055 }
00056
00057 }
00058