util/config.cc
/// Retrieve a pathname from section.param and deposit it in value,
/// returning true.  If the section.param cannot be found then value
/// remains unchanged and function returns false. Additionally, test
/// whether the FileCond constraint is satisfied.  May throw.
/// 
Retrieve a pathname from section.param and deposit it in value,
returning true.  If the section.param cannot be found then value
remains unchanged and function returns false. Additionally, test
whether the FileCond constraint is satisfied.  May throw.
Retrieve a pathname from section . param and deposit it in value returning true . If the section . param cannot be found then value remains unchanged and function returns false . Additionally test whether the FileCond constraint is satisfied . May throw .
bool Config::get_pathname( const char *section, const char *param,
                           FileCond cond, boost::filesystem::path &value)
{
    bool found=true;
    std::string pathstr {};
    const Json::Value &val=m_croot[section][param];
    if (val.isNull()) {
        found = false;
    } else {
        pathstr = val.asString();
        value = expand_home( pathstr );
    }
    if (cond == FileCond::MustExist) {
        if (not fs::exists(value)
            or not fs::is_regular_file(value)) {
            LOG_ERROR(Lgr) << "Config " << section << "." << param
                           << ", File not found: " << value;
            throw Config_path_error();
        }
    } else if (cond == FileCond::MustNotExist) {
        if (fs::exists(value)) {
            LOG_ERROR(Lgr) << "Config " << section << "." << param
                           << ", File already exists: " << value;
            throw Config_path_error();
        }
    } else if (cond == FileCond::MustExistDir) {
        if (not fs::exists(value)
            or not fs::is_directory(value)) {
            LOG_ERROR(Lgr) << "Config " << section << "." << param
                           << ", File not found: " << value;
            throw Config_path_error();
        }
    }
    LOG_INFO(Lgr) << "Config " << section << "." << param << "=" << value;
    return found;
}
bool Config :: get_pathname ( const char * section , const char * param , FileCond cond , boost :: filesystem :: path & value ) { bool found = true ; std :: string pathstr { } ; const Json :: Value & val = m_croot [ section ] [ param ] ; if ( val . isNull ( ) ) { found = false ; } else { pathstr = val . asString ( ) ; value = expand_home ( pathstr ) ; } if ( cond == FileCond :: MustExist ) { if ( not fs :: exists ( value ) or not fs :: is_regular_file ( value ) ) { LOG_ERROR ( Lgr ) << " " << section << " " << param << " " << value ; throw Config_path_error ( ) ; } } else if ( cond == FileCond :: MustNotExist ) { if ( fs :: exists ( value ) ) { LOG_ERROR ( Lgr ) << " " << section << " " << param << " " << value ; throw Config_path_error ( ) ; } } else if ( cond == FileCond :: MustExistDir ) { if ( not fs :: exists ( value ) or not fs :: is_directory ( value ) ) { LOG_ERROR ( Lgr ) << " " << section << " " << param << " " << value ; throw Config_path_error ( ) ; } } LOG_INFO ( Lgr ) << " " << section << " " << param << " " << value ; return found ; }
Retrieve a pathname from section.param and deposit it in value,
returning true.
Retrieve a pathname from section . param and deposit it in value returning true .
// maybe expand home on the default value????