advgetopt/conf_file.cpp
/** \brief Initialize the file setup object.
 *
 * This constructor initializes the setup object which can later be used
 * to search for an existing conf_file or creating a new conf_file.
 *
 * The setup holds the various parameters used to know how to load a
 * configuration file in memory. The parameters include
 *
 * \li \p filename -- the name of the file to read as a configuration file.
 * \li \p line_continuation -- how lines in the files are being read; in
 * most cases a line in a text file ends when a newline character (`\\n`)
 * is found; this parameter allows for lines that span (continue) on
 * multiple text lines. Only one type of continuation or no continue
 * (a.k.a. "single line") can be used per file.
 * \li \p assignment_operator -- the character(s) accepted between the
 * name of a variable and its value; by default this is the equal sign
 * (`=`). Multiple operators can be accepted.
 * \li \p comment -- how comments are introduced when supported. Multiple
 * introducers can be accepted within one file. By default we accept the
 * Unix Shell (`#`) and INI file (`;`) comment introducers.
 * \li \p section_operator -- the set of characters accepted as section
 * separator. By default we accept the INI file syntax (the `[section]`
 * syntax.)
 *
 * \note
 * If the filename represent an existing file, then the name is going to
 * get canonicalized before it gets saved in the structure. Otherwise it
 * gets saved as is.
 *
 * \param[in] filename  A valid filename.
 * \param[in] line_continue  One of the line_continuation_t values.
 * \param[in] assignment_operator  A set of assignment operator flags.
 * \param[in] comment  A set of comment flags.
 * \param[in] section_operator  A set of section operator flags.
 */
\brief Initialize the file setup object.
This constructor initializes the setup object which can later be used
to search for an existing conf_file or creating a new conf_file.

The setup holds the various parameters used to know how to load a
configuration file in memory. The parameters include

\li \p filename -- the name of the file to read as a configuration file.
\li \p line_continuation -- how lines in the files are being read; in
most cases a line in a text file ends when a newline character (`\\n`)
is found; this parameter allows for lines that span (continue) on
multiple text lines. Only one type of continuation or no continue
(a.k.a. "single line") can be used per file.
\li \p assignment_operator -- the character(s) accepted between the
name of a variable and its value; by default this is the equal sign
(`=`). Multiple operators can be accepted.
\li \p comment -- how comments are introduced when supported. Multiple
introducers can be accepted within one file. By default we accept the
Unix Shell (`#`) and INI file (`;`) comment introducers.
\li \p section_operator -- the set of characters accepted as section
separator. By default we accept the INI file syntax (the `[section]`
syntax.)

\note
If the filename represent an existing file, then the name is going to
get canonicalized before it gets saved in the structure. Otherwise it
gets saved as is.

\param[in] filename  A valid filename.
\param[in] line_continue  One of the line_continuation_t values.
\param[in] assignment_operator  A set of assignment operator flags.
\param[in] comment  A set of comment flags.
\param[in] section_operator  A set of section operator flags.
\ brief Initialize the file setup object . This constructor initializes the setup object which can later be used to search for an existing conf_file or creating a new conf_file . The setup holds the various parameters used to know how to load a configuration file in memory . The parameters include \ li \ p filename -- the name of the file to read as a configuration file . \ li \ p line_continuation -- how lines in the files are being read ; in most cases a line in a text file ends when a newline character ( ` \\ n ` ) is found ; this parameter allows for lines that span ( continue ) on multiple text lines . Only one type of continuation or no continue ( a . k . a . " single line " ) can be used per file . \ li \ p assignment_operator -- the character ( s ) accepted between the name of a variable and its value ; by default this is the equal sign ( ` = ` ) . Multiple operators can be accepted . \ li \ p comment -- how comments are introduced when supported . Multiple introducers can be accepted within one file . By default we accept the Unix Shell ( ` # ` ) and INI file ( ` ; ` ) comment introducers . \ li \ p section_operator -- the set of characters accepted as section separator . By default we accept the INI file syntax ( the ` [ section ] ` syntax . ) \ note If the filename represent an existing file then the name is going to get canonicalized before it gets saved in the structure . Otherwise it gets saved as is . \ param [ in ] filename A valid filename . \ param [ in ] line_continue One of the line_continuation_t values . \ param [ in ] assignment_operator A set of assignment operator flags . \ param [ in ] comment A set of comment flags . \ param [ in ] section_operator A set of section operator flags .
conf_file_setup::conf_file_setup(
          std::string const & filename
        , line_continuation_t line_continuation
        , assignment_operator_t assignment_operator
        , comment_t comment
        , section_operator_t section_operator)
    : f_original_filename(filename)
    , f_line_continuation(line_continuation)
    , f_assignment_operator(assignment_operator == 0
                ? ASSIGNMENT_OPERATOR_EQUAL
                : assignment_operator)
    , f_comment(comment)
    , f_section_operator(section_operator)
{
    if(filename.empty())
    {
        throw getopt_invalid("trying to load a configuration file using an empty filename.");
    }
    std::unique_ptr<char, decltype(&::free)> fn(realpath(filename.c_str(), nullptr), &::free);
    if(fn != nullptr)
    {
        f_filename = fn.get();
    }
    else
    {
        f_filename = filename;
    }
}
conf_file_setup :: conf_file_setup ( std :: string const & filename , line_continuation_t line_continuation , assignment_operator_t assignment_operator , comment_t comment , section_operator_t section_operator ) : f_original_filename ( filename ) , f_line_continuation ( line_continuation ) , f_assignment_operator ( assignment_operator == 0 ? ASSIGNMENT_OPERATOR_EQUAL : assignment_operator ) , f_comment ( comment ) , f_section_operator ( section_operator ) { if ( filename . empty ( ) ) { throw getopt_invalid ( " " ) ; } std :: unique_ptr < char , decltype ( & :: free ) > fn ( realpath ( filename . c_str ( ) , nullptr ) , & :: free ) ; if ( fn != nullptr ) { f_filename = fn . get ( ) ; } else { f_filename = filename ; } }
\brief Initialize the file setup object.
\ brief Initialize the file setup object .