![]() |
advgetopt 2.0.47
Parse complex command line arguments and configuration files in C++.
|
#include <conf_file.h>
Public Types | |
typedef std::shared_ptr< conf_file_setup > | pointer_t |
Private Member Functions | |
void | initialize () |
Private Attributes | |
assignment_operator_t | f_assignment_operator = ASSIGNMENT_OPERATOR_EQUAL |
comment_t | f_comment = COMMENT_INI | COMMENT_SHELL |
std::string | f_filename = std::string() |
line_continuation_t | f_line_continuation = line_continuation_t::line_continuation_unix |
name_separator_t | f_name_separator = NAME_SEPARATOR_UNDERSCORES |
std::string | f_original_filename = std::string() |
section_operator_t | f_section_operator = SECTION_OPERATOR_INI_FILE |
std::string | f_section_to_ignore = std::string() |
std::string | f_url = std::string() |
Definition at line 110 of file conf_file.h.
typedef std::shared_ptr<conf_file_setup> advgetopt::conf_file_setup::pointer_t |
Definition at line 113 of file conf_file.h.
advgetopt::conf_file_setup::conf_file_setup | ( | std::string const & | filename, |
line_continuation_t | line_continuation = line_continuation_t::line_continuation_unix , |
||
assignment_operator_t | assignment_operator = ASSIGNMENT_OPERATOR_EQUAL , |
||
comment_t | comment = COMMENT_INI | COMMENT_SHELL , |
||
section_operator_t | section_operator = SECTION_OPERATOR_INI_FILE , |
||
name_separator_t | name_separator = NAME_SEPARATOR_UNDERSCORES |
||
) |
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
filename
– the name of the file to read as a configuration file. 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. 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. 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. section_operator
– the set of characters accepted as section separator. By default we accept the INI file syntax (the [section]
syntax.)[in] | filename | A valid filename. |
[in] | line_continue | One of the line_continuation_t values. |
[in] | assignment_operator | A set of assignment operator flags. |
[in] | comment | A set of comment flags. |
[in] | section_operator | A set of section operator flags. |
Definition at line 177 of file conf_file.cpp.
References initialize().
advgetopt::conf_file_setup::conf_file_setup | ( | std::string const & | filename, |
conf_file_setup const & | original | ||
) |
Definition at line 197 of file conf_file.cpp.
References initialize().
assignment_operator_t advgetopt::conf_file_setup::get_assignment_operator | ( | ) | const |
This function returns the set of flags describing the list of accepted operators one can use to do assignments.
Right now we support the follow:
=
) character, like in most Unix configuration files and shell scripts. :
) character, like in email and HTTP headers. +=
(append) and ?=
(optional) operators; this is used to add to an existing parameter and to set a parameter only if not already set.Definition at line 345 of file conf_file.cpp.
References f_assignment_operator.
Referenced by advgetopt::conf_file::is_assignment_operator(), advgetopt::conf_file::read_configuration(), and advgetopt::conf_file::save_configuration().
comment_t advgetopt::conf_file_setup::get_comment | ( | ) | const |
Get the comment flags.
This function returns the comment flags. These describe which type of comments are supported in this configuration file.
Currently we support:
;
) and end with a newline. #
) and end with a newline. //
) and end with a newline.Right now we only support line comments. Configuration entries cannot include comments. A comment character can be preceeded by spaces and tabs.
Line continuation is taken in account with comments. So the following when the line continuation is set to Unix is one long comment:
Definition at line 384 of file conf_file.cpp.
References f_comment.
Referenced by advgetopt::conf_file::is_comment(), and advgetopt::conf_file::read_configuration().
std::string advgetopt::conf_file_setup::get_config_url | ( | ) | const |
This function transforms the configuration file setup in a unique URL. This URL allows us to verify that two setup are the same so when attempting to reload the same configuration file, we can make sure you are attempting to do so with the same URL.
This is because trying to read the same file with, for example, line continuation set to Unix the first time and then set to MS-DOS the second time would not load the same thing is either line continuation was used.
Definition at line 452 of file conf_file.cpp.
References advgetopt::ASSIGNMENT_OPERATOR_COLON, advgetopt::ASSIGNMENT_OPERATOR_EQUAL, advgetopt::ASSIGNMENT_OPERATOR_EXTENDED, advgetopt::ASSIGNMENT_OPERATOR_SPACE, advgetopt::COMMENT_CPP, advgetopt::COMMENT_INI, advgetopt::COMMENT_SAVE, advgetopt::COMMENT_SHELL, f_assignment_operator, f_comment, f_filename, f_line_continuation, f_section_operator, f_url, advgetopt::line_continuation_fortran, advgetopt::line_continuation_msdos, advgetopt::line_continuation_rfc_822, advgetopt::line_continuation_semicolon, advgetopt::line_continuation_single_line, advgetopt::line_continuation_unix, advgetopt::SECTION_OPERATOR_BLOCK, advgetopt::SECTION_OPERATOR_C, advgetopt::SECTION_OPERATOR_CPP, and advgetopt::SECTION_OPERATOR_INI_FILE.
Referenced by advgetopt::conf_file::get_conf_file().
std::string const & advgetopt::conf_file_setup::get_filename | ( | ) | const |
When creating a new conf_file_setup, you have to specify a filename. This function returns that filename after it was canonicalized by the constructor.
The canonicalization process computes the full path to the real file. If such does not exist then no filename is defined, so this function may return an empty string.
Definition at line 286 of file conf_file.cpp.
References f_filename.
Referenced by advgetopt::conf_file::get_conf_file(), advgetopt::conf_file::read_configuration(), advgetopt::conf_file::save_configuration(), and advgetopt::conf_file::set_parameter().
line_continuation_t advgetopt::conf_file_setup::get_line_continuation | ( | ) | const |
This function returns the line continuation for this setup.
This parameter is not a set of flags. We only support one type of line continuation per file. Many continuations could be contradictory if used simultaneously.
The continuation setting is one of the following:
&
at end of the line. \
at end of the line. &
at the start of the next line; there cannot be any spaces, the &
has to be the very first character. ;
ends the line; when reading a line with this continuation mode, the reader stops only when it finds the ;
or EOF (also if a comment is found.)Definition at line 318 of file conf_file.cpp.
References f_line_continuation.
Referenced by advgetopt::conf_file::get_line().
name_separator_t advgetopt::conf_file_setup::get_name_separator | ( | ) | const |
A parameter name can include dashes or underscores. The advgetopt supports either one and internally, it saves the names with dashes. Most other tools, though will only expect one or the other, most likely underscores, which is the default here.
You can specify either one when building the conf_file_setup. At the moment, there is no option to keep the dashes and underscores as found in the input.
Definition at line 608 of file conf_file.cpp.
References f_name_separator.
Referenced by advgetopt::conf_file::save_configuration().
std::string const & advgetopt::conf_file_setup::get_original_filename | ( | ) | const |
When creating a new conf_file_setup, you have to specify a filename. This function returns that string exactly, without canonicalization.
Definition at line 265 of file conf_file.cpp.
References f_original_filename.
section_operator_t advgetopt::conf_file_setup::get_section_operator | ( | ) | const |
This function returns the flags representing which of the section operators are accepted.
We currently support the following types of sections:
.
) is viewed as a section/name separator as when you access a variable member in a structure. ::
) is viewed as a section/name separator; if used at the very beginning, it is viewed as "global scope" and whatever other section is currently active is ignored. {
) and closing (}
) curvly brackets to group parameters together; a name must preceed the opening bracket, it represents the section name. var
ends up in section a
, sub-section b
, and sub-sub-section c
(or section a::b::c
.) Before saving the results in the parameters, all section operators get transformed to the C++ scope (::
) operator, which is why that operator used in any name ends up looking like a section separator. Definition at line 428 of file conf_file.cpp.
References f_section_operator.
Referenced by advgetopt::conf_file::read_configuration(), and advgetopt::conf_file::set_parameter().
std::string const & advgetopt::conf_file_setup::get_section_to_ignore | ( | ) | const |
This function returns a reference to the name of the section to ignore.
For additional information, see the set_section_to_ignore() function.
Definition at line 638 of file conf_file.cpp.
References f_section_to_ignore.
Referenced by advgetopt::conf_file::set_parameter().
|
private |
Definition at line 213 of file conf_file.cpp.
References f_filename, and f_original_filename.
Referenced by conf_file_setup(), and conf_file_setup().
bool advgetopt::conf_file_setup::is_valid | ( | ) | const |
This function is used to check whether the conf_file_setup is valid or not. It is valid when everything is in order, which at this point means the filename is not empty.
All the other parameters are always viewed as being valid.
Definition at line 250 of file conf_file.cpp.
References f_filename.
Referenced by advgetopt::getopt::parse_options_from_file().
If the number of sections is exactly 2 when only 1 should be used, then the first name is checked against this name. If equal, it gets removed.
This is done so fluid-settings files can be loaded and we do not have to duplicate the data (since that's bad practice).
[in] | section_name | The name of the section to ignore. |
Definition at line 624 of file conf_file.cpp.
References f_section_to_ignore.
Referenced by advgetopt::getopt::parse_options_from_file().
|
private |
Definition at line 145 of file conf_file.h.
Referenced by get_assignment_operator(), and get_config_url().
|
private |
Definition at line 146 of file conf_file.h.
Referenced by get_comment(), and get_config_url().
|
private |
Definition at line 142 of file conf_file.h.
Referenced by get_config_url(), get_filename(), initialize(), and is_valid().
|
private |
Definition at line 144 of file conf_file.h.
Referenced by get_config_url(), and get_line_continuation().
|
private |
Definition at line 149 of file conf_file.h.
Referenced by get_name_separator().
|
private |
Definition at line 141 of file conf_file.h.
Referenced by get_original_filename(), and initialize().
|
private |
Definition at line 147 of file conf_file.h.
Referenced by get_config_url(), and get_section_operator().
|
private |
Definition at line 143 of file conf_file.h.
Referenced by get_section_to_ignore(), and set_section_to_ignore().
|
mutableprivate |
Definition at line 148 of file conf_file.h.
Referenced by get_config_url().
This document is part of the Snap! Websites Project.
Copyright by Made to Order Software Corp.