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


C++ CmdLineParser::getOption方法代码示例

本文整理汇总了C++中CmdLineParser::getOption方法的典型用法代码示例。如果您正苦于以下问题:C++ CmdLineParser::getOption方法的具体用法?C++ CmdLineParser::getOption怎么用?C++ CmdLineParser::getOption使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CmdLineParser的用法示例。


在下文中一共展示了CmdLineParser::getOption方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main (int argc, char** argv)
{
    int ret = 0;
    CmdLineParser *cmdline = 0;
    Config *config = 0;

    if (!initNLS ("openspeak"))
    {
        std::cerr << "Initialising NLS failed!\n";
        return -1;
    }

    try
    {
    /* Parse the commandline */
        cmdline = new CmdLineParser (_("openSpeak Server"), "0.2-git");
        CmdLineParser::CmdLineOption options[] = {
            { "debug", 'd', CmdLineParser::OPTION_ARG_NONE, _("Display more informations"), "" },
            {0}
        };
        cmdline->addOption (options);
        cmdline->parseArguments (argc, argv);

    /* Check if the config path exists and if not create it */
        std::string confdir = FileUtils::getConfigPath ();
        if (!FileUtils::dirExists (confdir))
            FileUtils::mkdir (confdir);

    /* Also check for the log dir in the config dir */
        if (!FileUtils::dirExists (confdir + "log/"))
            FileUtils::mkdir (confdir + "log/");

    /* Create the log file */
        new LogMgr (confdir + "log/openspeakd.log",
                StringUtils::toBool (cmdline->getOption ("debug")) ?
                Log::LVL_DEBUG : Log::LVL_SILENT);
        LOG_SILENT (_("Started logging"));

    /* Open the config file and parse it */
        config = new Config ("openspeakd.conf");
        config->parse ();
        LOG_DEBUG (format (_("Parsed config file %1%openspeakd.conf")) % confdir);
    }
    catch (Exception ex)
    {
        if (LogMgr::getSingleton () && !ex.empty ())
            LOG_FATAL (format (_("Exception: %1%")) % ex.what ());
        else if (!ex.empty ())
            ex.print ();
        ret = -1;
    }
    catch (...)
    {
        if (LogMgr::getSingleton ())
            LOG_FATAL (_("Catched unknown exception"));
        else
            std::cout << _("Catched unknown exception");
        ret = -1;
    }

    delete cmdline;
    if (config)
        delete config;

    if (LogMgr::getSingleton ())
    {
        LOG_SILENT (_("Finished logging"));
        delete LogMgr::getSingleton ();
    }

    return ret;
}
开发者ID:rmbl,项目名称:openspeak,代码行数:72,代码来源:main.cpp


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