llregionnamecache.cpp

Go to the documentation of this file.
00001 
00030 #include "llviewerprecompiledheaders.h" // must be first include
00031 #include "llregionnamecache.h"
00032 #include "llxmltree.h"
00033 
00034 LLRegionNameCache *gRegionNameCache = NULL;
00035 
00036 void LLRegionNameCache::put(const LLUUID &region, const LLString &name)
00037 {
00038         if ( !name.empty() )
00039         {
00040                 llinfos << "Adding region to cache: " << name << " (" << region << ")" << llendl;
00041                 mCache[region] = LLRegionNameCacheEntry(name); 
00042         }
00043         else
00044         {
00045                 llinfos << "Not adding region to cache, name empty for " << region << llendl;
00046         }
00047 }
00048 
00049 LLString LLRegionNameCache::get(const LLUUID &region) 
00050 {
00051         if ( region.isNull() )                  return "?";
00052         if ( mCache.count( region ) > 0 )       return mCache[region].regionName;
00053         
00054         return "(" + region.asString() + ")";
00055 }
00056 
00057 void LLRegionNameCache::exportFile(const LLString &filename)
00058 {
00059 
00060         llinfos << "Writing region name cache to " << filename << llendl;
00061 
00062         llofstream file;
00063         file.open(filename.c_str());
00064 
00065         if (!file.is_open())
00066         {
00067                 llerrs << "Failed to open region name cache file " << filename << " for writing" << llendl;
00068                 return;
00069         }
00070 
00071 
00072         file << "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\n";
00073         file << "<cache>\n";
00074 
00075 
00076         std::map<LLUUID, LLRegionNameCacheEntry>::iterator iter;
00077         for(iter = mCache.begin(); iter != mCache.end(); iter++)
00078         {
00079                 LLUUID id = iter->first;
00080                 LLRegionNameCacheEntry *reg = &iter->second;
00081                 
00082                 if ( ! reg->isStatic )
00083                 {
00084                         file << "\t<entry id=\"" << id.asString().c_str() << "\">" << reg->regionName.c_str() << "</entry>\n";
00085                 }
00086         }
00087 
00088         file << "</cache>\n";
00089         file.close();
00090 }
00091 
00092 void LLRegionNameCache::importFile(const LLString &filename, bool is_static)
00093 {
00094         llinfos << "Loading cache from " << filename << llendl;
00095 
00096         LLXmlTree xml_tree;
00097         
00098         if ( !xml_tree.parseFile(filename) )
00099         {
00100                 llwarns << "Unable to parse region name cache file " << filename << llendl;
00101                 return;
00102         }
00103 
00104         
00105         LLXmlTreeNode *rootp = xml_tree.getRoot();
00106         if (!rootp)
00107         {
00108                 llwarns << "Region name cache file has no root element" << llendl;
00109                 return;
00110         }
00111 
00112         LLXmlTreeNode* child_nodep = rootp->getFirstChild();
00113         S32 count = 0;
00114 
00115         while( child_nodep )
00116         {
00117                 LLString name = child_nodep->getName();
00118                 if ( name != "entry" )
00119                 {
00120                         llwarns << "Ignoring unknown tag in region name cache: " << name << llendl;
00121                         child_nodep = rootp->getNextChild();
00122                         continue;
00123                 }
00124 
00125                 LLUUID region_id;
00126                 child_nodep->getAttributeUUID("id", region_id);
00127 
00128                 if ( region_id.isNull() )
00129                 {
00130                         llwarns << "Ignoring bad entry in region name cache, failed to parse region id" << llendl;
00131                         child_nodep = rootp->getNextChild();
00132                         return;
00133                 }
00134 
00135                 LLString region_name = child_nodep->getTextContents();
00136 
00137                 
00138                 mCache[region_id] = LLRegionNameCacheEntry(region_name, is_static);
00139                 child_nodep = rootp->getNextChild();
00140                 count++;
00141         }
00142 
00143         llinfos << "Loaded " << count << " entries from cache" << llendl;
00144 }
00145 
00146 
00147 
00148 

Generated on Thu Jul 1 06:09:04 2010 for Second Life Viewer by  doxygen 1.4.7