bool
MapModuleNoticeContainer::load( DataBuffer& dataBuf, uint32 mapSet )
{
   dataBuf.readNextLong(); // old totalLength
   dataBuf.readNextLong(); // nbrMaps

   mc2dbg << "[MMNC]: Using new kind of index.db" << endl;
   // Format on disk begins with two 32-bit words with zeroes.
   // They should already have been read by load.
   // We should really implement version 0 here as well so that
   // we can remove the MapModuleObjVector.
   // Then comes length and version

   uint32 totalLength = dataBuf.readNextLong(); // length
   uint32 version  = dataBuf.readNextLong();
   uint32 nbrItems = dataBuf.readNextLong();

   if (dataBuf.getNbrBytesLeft() == 0) {
      // we must have some bytes left
      // TODO: check if nbr bytes left is at least 
      // = length * something...
      return false;
   }

   // Reset the internal structs.
   deleteAllObjs();
   
   // Version should only be 1 now.
   for ( uint32 i = 0; i < nbrItems; ++i ) {
      MapModuleNotice* notice = 
         new MapModuleNotice( &dataBuf, version, mapSet );
      // Add the notice to the appropriate vectors and maps.
      addNotice( notice );
      mc2dbg << "[MMNC]: Added MapModuleNotice for "
             << notice->getMapName() << endl;
   }

   // Read the map hierarchy
   m_mapTree.load( &dataBuf, mapSet );

   // Read the regions
   int nbrRegions = dataBuf.readNextLong();
   m_regions.clear();

   mc2dbg << "[MMNC]: Number of top regions:" << nbrRegions << endl;

   for ( int i = 0; i < nbrRegions; ++i ) {

      MapTopRegion* region = new MapTopRegion();
      region->load( &dataBuf, mapSet );

      m_regions[ region->getID() ] = region;
      const char* name = region->getName( LangTypes::english );

      if ( name == NULL ) {
         name = "NULL";
      }

      mc2dbg << "[MMNC]: Added Top Region ID:" << region->getID()
             << " name: " << name << endl;
   }
   
   // Read the region hierarchy
   m_regionTree.load( &dataBuf );

   // Read map supplier coverage data.
   mc2dbg8 << "Curr offset: " << dataBuf.getCurrentOffset()
           << " total length " << totalLength << endl;
   if (dataBuf.getCurrentOffset() < totalLength+12 ){
      mc2dbg << "[MMNC]: Loading map supplier coverage." << endl;
      loadMapSupCoverage( &dataBuf );
      mc2dbg << "[MMNC]: Done loading map supplier coverage." << endl;
   }
   else {
      mc2dbg << "[MMNC]: Not loading map supplier coverage." << endl;
   }

#ifdef DEBUG_LEVEL_1
   //
   // debug
   //
   for(uint32 i = 0; i < m_allNotices.size(); ++i ) {
      mc2dbg << "Overview maps for " << m_allNotices[i]->getMapID()
             << endl;
      vector<uint32> overviewIDs;
      m_mapTree.getOverviewMapsFor(m_allNotices[i]->getMapID(),
                                   overviewIDs);
      for(uint32 j = 0; j < overviewIDs.size(); ++j ) {
         mc2dbg << "    " << j << "=" << overviewIDs[j] << endl;
      }
   }

   {
      // Print stuff
      mc2dbg << "MAP_HIERARCHY" << endl;
      set<uint32> mapIDs;
      m_mapTree.getTopLevelMapIDs(mapIDs);
      for(set<uint32>::const_iterator it = mapIDs.begin();
          it != mapIDs.end();
          ++it) {
         mc2dbg << "TopLevelMap :" << hex << *it << dec << " contains " 
                << endl;
         set<IDPair_t> items;
         m_mapTree.getContents(*it, items);
         for( set<IDPair_t>::iterator it = items.begin();
              it != items.end();
              ++it ) {
            mc2dbg << "      " << it->getMapID() << ":" << hex
                   << it->getItemID() << dec << endl;
         }
      }
   }

   // Print stuff
   mc2dbg << "REGION_HIERARCHY" << endl;
   set<uint32> mapIDs;
   m_regionTree.getTopLevelRegionIDs(mapIDs);
   for(set<uint32>::const_iterator it = mapIDs.begin();
       it != mapIDs.end();
       ++it) {
      mc2dbg << "TopLevelRegion : " 
             << getRegion( *it )->getNames()
                  ->getBestName( LangTypes::swedish )->getName()
             << " " << *it << endl;
      
      const ItemIDTree& idTree = getRegion( *it )->getItemIDTree();
      set<uint32> mapIDs;
      mc2dbg << " consists of the following items:" << endl;
      idTree.getTopLevelMapIDs( mapIDs );
      for ( set<uint32>::const_iterator jt = mapIDs.begin();
            jt != mapIDs.end(); ++jt ) {
         mc2dbg << " map id = " << *jt << endl;
         set<IDPair_t> items;
         idTree.getContents( *jt, items );
         for ( set<IDPair_t>::const_iterator kt = items.begin();
               kt != items.end(); ++kt ) {
            mc2dbg << "   [" << kt->first << ", " << kt->second << "]"
                   << endl;
         }
      }
      
      
      mc2dbg << " contains the following other regions: " << endl;
      set<uint32> items;
      m_regionTree.getContents(*it, items);
      for( set<uint32>::iterator jt = items.begin();
           jt != items.end();
           ++jt ) {
         mc2dbg << "      " << *jt << endl;
      }
   }

   //
   // end debug
   //   
#endif // DEBUG_LEVEL_1

   return true;
}
void
MapModuleNoticeContainer::
initUsingCC( const vector<MapModuleNotice*>& oldVector )
{
   // This method should only be used for the old index.db.
   // Go through all the notices
   for ( uint32 i = 0; i < oldVector.size(); i++ ) {      
      MapModuleNotice* notice = oldVector[i];
      addNotice( notice, true ); // True means that regions should be faked.
   }

   // Build the ItemIDTrees
   // We know that the top-regions only contain countries.
   // Save all the overview maps in a map sorted by cc.
   // WARNING: This will not work when there is more than
   //          one overview map per region,.
   map<StringTable::countryCode, uint32> overviewMaps;
   typedef  multimap<StringTable::countryCode, uint32> underviewMapMap_t;
   underviewMapMap_t underviewMaps;
   for( uint32 i = 0; i < oldVector.size(); ++i ) {
      MapModuleNotice* notice = m_allNotices[i];
      if ( MapBits::isCountryMap(notice->getMapID()) ) {
         overviewMaps[m_allNotices[i]->getCountryCode()] =
            MapBits::countryToOverview(notice->getMapID());
      } else if ( MapBits::isUnderviewMap( notice->getMapID() ) ) {
         underviewMaps.insert(make_pair(m_allNotices[i]->getCountryCode(),
                                        notice->getMapID()));
      }
   }

   // Loop over the found overview maps.
   for( map<StringTable::countryCode, uint32>::iterator
           it(overviewMaps.begin());
        it != overviewMaps.end();
        ++it ) {
      // Add the top level.
      ItemIDTree* idTree = findRegion( it->first )->getItemIDTreeForWriting();
      idTree->addMap( MAX_UINT32, it->second );
      // Add to or internal tree of all maps too.
      m_mapTree.addMap( MAX_UINT32, it->second );
      // Get the range of underview maps with the same county code
      pair<underviewMapMap_t::const_iterator,
           underviewMapMap_t::const_iterator> range =
         underviewMaps.equal_range( it->first );
      for ( underviewMapMap_t::const_iterator ut(range.first);
            ut != range.second;
            ++ut ) {
         // Add it to the tree of the region
         idTree->addMap( it->second, ut->second);
         // Also add it to our tree of maps.
         m_mapTree.addMap( it->second, ut->second );
      }
   }

#ifdef DEBUG_LEVEL_4
   for(uint32 i = 0; i < m_allNotices.size(); ++i ) {
      mc2dbg << "Overview maps for " << m_allNotices[i]->getMapID()
             << endl;
      vector<uint32> overviewIDs;
      m_mapTree.getOverviewMapsFor(m_allNotices[i]->getMapID(),
                                   overviewIDs);
      for(uint32 j = 0; j < overviewIDs.size(); ++j ) {
         mc2dbg << "    " << j << "=" << overviewIDs[j] << endl;
      }
   }
#endif
#ifdef DEBUG_LEVEL_4
   // Print stuff
   mc2dbg << "MAP_HIERARCHY" << endl;
   set<uint32> mapIDs;
   m_mapTree.getTopLevelMapIDs(mapIDs);
   for(set<uint32>::const_iterator it = mapIDs.begin();
       it != mapIDs.end();
       ++it) {
      mc2dbg << "TopLevelMap :" << hex << *it << dec << " contains " 
             << endl;
      set<IDPair_t> items;
      m_mapTree.getContents(*it, items);
      for( set<IDPair_t>::iterator it = items.begin();
           it != items.end();
           ++it ) {
         mc2dbg << "      " << it->getMapID() << ":" << hex
                << it->getItemID() << dec << endl;
      }
   }
#endif
}
void
WriteableMapModuleNoticeContainer::addLast(MapModuleNotice* notice)
{
   addNotice( notice );
}
Beispiel #4
0
	void NoticeWindow::addNotice(const QString & message ){
		addNotice( DEFAULT_PRIORITY, message);
	}
Beispiel #5
0
 void NoticeWindow::writeEvent(int priority, Grids::Event* evt) {
     if(priority >= current_priority)
         addNotice( priority, tr( evt->getStyledString().c_str() ) );
 }
Beispiel #6
0
 /* The process of translating a json into a styled string is
    processor intersive, so filter the low priority messages out first. */
 void NoticeWindow::writeValue(int priority, Grids::Value* val) {
     if(priority >= current_priority)
         addNotice( priority, tr( (*val).toStyledString().c_str() ) );
 }
Beispiel #7
0
	void NoticeWindow::write(int priority, const QString & message) {
		addNotice(priority, message);
	}
Beispiel #8
0
	void NoticeWindow::write(const QString & message) {
		addNotice(message);
	}