bool CXmlTree::CreateCache(unsigned cacheId, const char *path, const char *attribute /*= NULL*/, CacheFlags flags /*= cacheDefault*/) { CXmlNodePtr node = GetRoot(); if(!node->Lookup(path)) { CServerIo::trace(3,"CreateCache node lookup failed"); return false; } cache_t& cache = m_Cache[cacheId]; cache.flags = flags; if(flags&cacheFilename) { if(cache.filenameMap) delete cache.filenameMap; cache.filenameMap = new std::map<cvs::filename, xmlNodePtr>; } else if(flags&cacheUsername) { if(cache.usernameMap) delete cache.usernameMap; cache.usernameMap = new std::map<cvs::username, xmlNodePtr>; } else { if(cache.standardMap) delete cache.standardMap; cache.standardMap = new std::map<cvs::string, xmlNodePtr>; } while(node->XPathResultNext()) { const char *value; if(attribute) { if(attribute[0]=='@') value = node->GetAttrValue(attribute+1); else value = node->GetNodeValue(attribute); } else value = node->GetValue(); if(value) { if(flags&cacheFilename) (*cache.filenameMap)[value]=node->Object(); else if(flags&cacheUsername) (*cache.usernameMap)[value]=node->Object(); else (*cache.standardMap)[value]=node->Object(); } } return true; }
bool CXmlTree::AddToCache(unsigned cacheId, const char *key, CXmlNodePtr node) { cacheMap_t::const_iterator i = m_Cache.find(cacheId); if(!node || !key || i==m_Cache.end()) return false; const cache_t& cache = i->second; assert(node->m_tree == this); if(cache.flags&cacheFilename) (*cache.filenameMap)[key]=node->Object(); else if(cache.flags&cacheUsername) (*cache.usernameMap)[key]=node->Object(); else (*cache.standardMap)[key]=node->Object(); return true; }