本文整理汇总了C++中Configure::getConfigByName方法的典型用法代码示例。如果您正苦于以下问题:C++ Configure::getConfigByName方法的具体用法?C++ Configure::getConfigByName怎么用?C++ Configure::getConfigByName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Configure
的用法示例。
在下文中一共展示了Configure::getConfigByName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: synchronizeGlobalCacheWithDisk
/*
after some specific time ,
merge cache data with disk file and update every thread's cache
then every thread has the same cache
*/
void CacheManagerThread::synchronizeGlobalCacheWithDisk()
{
#ifndef NDEBUG
WRITE_STR(string(" start synchronize Global Cache With Disk ......."));
#endif
Configure *pconf = Configure::getInstance();
string cache_path = pconf->getConfigByName("cache_file_path");
string home_path = pconf->getConfigByName("home_path");
#ifndef NDEBUG
WRITE_STR(string(" 1st. merge the disk cache data to memory ......."));
#endif
// 1st. merge the disk cache data to memory;
ifstream ifs((home_path + cache_path).c_str());
if (!(ifs.is_open()))
{
throw runtime_error("open cache_path file");
}
string line, keyword, pairword;
int frequency;
while (getline(ifs, line))
{
istringstream istr(line);
istr >> keyword;
vector<pair<string, int> > vec;
while (istr >> pairword)
{
istr >> frequency;
vec.push_back(make_pair(pairword, frequency));
}
CacheData data(vec);
global_cache_map_.insert(make_pair(keyword, data));
}
ifs.close();
#ifndef NDEBUG
WRITE_STR(string(" 2nd. write the cache data back to disk...... "));
#endif
// 2nd. write the global cache data back to disk;
ofstream ofs((home_path + cache_path).c_str());
// file lock;
if (!(ofs.is_open()))
{
throw runtime_error("open cache_path file");
}
for (Cache::cache_map_type::iterator iter = global_cache_map_.begin() ; iter != global_cache_map_.end(); ++iter)
{
ofs << (*iter).first << "\t";
vector<pair<string, int> > vec = (*iter).second.getDataVec();
for (vector<pair<string, int> >::iterator it = vec.begin(); it != vec.end(); ++it)
{
ofs << (*it).first << " " << (*it).second<<" ";
}
ofs << "\n";
}
ofs.close();
}
示例2: run
void CacheManagerThread::run()
{
while (true)
{
#ifndef NDEBUG
WRITE_STR("start updateCache .......");
#endif
updateCache();
// 每隔一段时间就更新所有cache
Configure *pconf = Configure::getInstance();
string s_time = pconf->getConfigByName("cache_manager_sleep_seconds");
int sleep_time = atoi(s_time.c_str());
sleep(sleep_time);
}
}