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;
    }

  • 相关阅读:
    UPC2018组队训练赛第十二场
    ACM-ICPC 2018南京赛区网络预选赛
    UPC2018组队训练赛第十一场
    UPC2018组队训练赛第十场
    UPC2018组队训练赛第九场
    linux 用简单密码
    设置分辨率
    packstack
    rbenv
    elasticsearch
  • 原文地址:https://www.cnblogs.com/rosesmall/p/2480209.html
Copyright © 2011-2022 走看看