zoukankan      html  css  js  c++  java
  • 根据命令参数读取

    int ACE_TMAIN(int argc, ACE_TCHAR* argv[])

    {
    int port=30000;
    int conPortNum=5000;
    std::string conf="server.conf";
    bool mode=true;
    bool display=true;
    ACE_Get_Opt cmdLine(argc,argv,"P:C:M:D:");
    int cnt=0;
    int opt;
    while((opt=cmdLine())!=-1){
    switch(opt){
    case 'P':
    port=atoi(cmdLine.opt_arg());
    cnt++;
    break;
    case 'C':
    conf=cmdLine.opt_arg();
    cnt++;
    break;
    case 'M':
    mode=strcmp(cmdLine.opt_arg(),"true")==0?true:false;
    cnt++;
    break;
    case 'D':
    display=strcmp(cmdLine.opt_arg(),"true")==0?true:false;
    cnt++;
    break;
    default:
    return 0;
    }
    }
    if(cnt<4){
    return 0;
    }

    ConfigurationManager configManager;
    if(!configManager.ReadFromFile(conf.c_str())){

    }

    ACE_Reactor Reactor;
    ACE_INET_Addr addr(port);

    SearchManager::Instance()->SetConfigManager(&configManager);
    //SearchManager::Instance()->PrePareSearchEngine(Configuration::PLACE_TYPE,1);

    HttpServer::CreateServer(&Reactor,addr);
    while(true)Reactor.handle_events();
    return 0;


    }

    读取文件

    bool ReadFromFile(const char* pFileName)
    {
    std::ifstream fin;
    fin.open(pFileName,std::ios_base::in);
    if(!fin)return false;
    Configuration* pConfig;
    while(pConfig=ReadConfiguration(fin)){
    m_ConfigVect.push_back(pConfig);
    }
    return true;
    }

    Configuration* ReadConfiguration(std::istream& fin)
    {
    std::string temp;
    const char* pIndex;

    std::string::size_type npos;
    do{
    if(fin.eof())return NULL;
    std::getline(fin,temp);
    npos=temp.find("$");
    }
    while(npos==std::string::npos||npos!=0);
    std::string type=temp.substr(1,temp.find_first_of(":")-1);
    temp=temp.substr(temp.find_first_of(":")+1);

    std::string name=temp.substr(0,temp.find_first_of(":"));

    std::string EngineType=temp.substr(temp.find_first_of(":")+1);

    Configuration* pConfig=new Configuration(type.c_str(),EngineType.c_str(),name.c_str());
    ParamBase* pParam;
    int nextChar;

    while(pParam=ReadParam(fin)){

    pConfig->AddParam(pParam);
    nextChar=fin.peek();

    if(nextChar=='$')break;
    else if(nextChar=='#')continue;
    }
    return pConfig;
    }

    时间

    const char* StrTime()
    {
    time_t clock;
    time(&clock);
    tm tmStruct;
    #ifdef WIN32
    localtime_s(&tmStruct,&clock);
    #else
    localtime_r(&clock,&tmStruct);
    #endif
    sprintf(m_timebuffer,"%04d/%02d/%02d %02d:%02d:%02d",tmStruct.tm_year+1900,tmStruct.tm_mon+1,tmStruct.tm_mday,
    tmStruct.tm_hour,tmStruct.tm_min,tmStruct.tm_sec);
    return m_timebuffer;
    }

  • 相关阅读:
    composer npm bower 版本依赖符号说明
    FastAdmin 速极后台框架从 v1.0 到 v1.2 的数据库升级
    FastAdmin 也可以出书了
    FastAdmin 开发时用到的 Git 命令 (2020-09-26)
    FastAdmin用什么弹窗组件
    笔记:Linux 文件权限
    笔记:使用源代码在 Centos 7 安装 Git 2
    php gd 生成表格 图片
    easyui datagrid 清空
    mysql 去重
  • 原文地址:https://www.cnblogs.com/rosesmall/p/2480209.html
Copyright © 2011-2022 走看看