Пример #1
0
// ##############################################################
void ModelManager::loadConfig(const string& fname)
{
    LINFO("Loading configuration from '%s'", fname.c_str());
    ParamMap pmap;
    pmap.load(fname.c_str());
    this->readParamsFrom(pmap);
}
Пример #2
0
// ##############################################################
bool ModelManager::parseCommandLine(const int argc,
                                    const char** argv,
                                    const char* usage,
                                    const int minarg,
                                    const int maxarg)
{
    ASSERT(rep != 0);

    // export options if that hasn't been done already
    if (this->hasBeenExported() == false)
        exportOptions(MC_RECURSE);

    // let's get our application name:
    if (argc <= 0)
        LFATAL("expected argc >= 1, got argc=%d", argc);
    string procname(argv[0]);
    uint ii = procname.rfind('/'); // skip the path; get just the filename:
    if (ii < procname.size()) procname = procname.substr(ii + 1);

    // if we wanted to automatically load a config from ~/.execname,
    // let's do that now:
    if (rep->autoLoadConfig && getenv("HOME"))
    {
        string fname = string(getenv("HOME")) + "/." + procname;
        FILE* tryit = fopen(fname.c_str(), "r");
        if (tryit) {   // config file exists; let's load it:
            fclose(tryit);
            LINFO("Autoloading configuration from '%s'", fname.c_str());
            ParamMap pmap;
            pmap.load(fname.c_str());
            readParamsFrom(pmap);
        }
    }

    return rep->com.parseCommandLine(argc, argv, usage, minarg, maxarg);
}