当前位置: 首页>>代码示例>>C++>>正文


C++ Configure::getConfigByName方法代码示例

本文整理汇总了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();
}
开发者ID:Lgggg,项目名称:wangdaozuoye,代码行数:60,代码来源:CacheManagerThread.cpp

示例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);
    }
}
开发者ID:Lgggg,项目名称:wangdaozuoye,代码行数:15,代码来源:CacheManagerThread.cpp


注:本文中的Configure::getConfigByName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。