FBB::ConfigFile(3bobcat)
β¨ FBB::ConfigFile β¨
so bestie, welcome to FBB::ConfigFile(3bobcat) β the Configuration File Processing page π
π NAME π
FBB::ConfigFile β a whole class that processes standard unix-like configuration files π
πΈ SYNOPSIS πΈ
#include <bobcat/configfile>
Linking option: -lbobcat
π¦ DESCRIPTION π¦
okay first thing first, and I need you to hear me on this one: this class is deprecated π. like, it still works, but you should be using the class FBB::Config instead (check config(3bobcat)). periodt.
So. ConfigFile objects read standard unix-style configuration files β¨. The way it works: every line gets stored with its initial white-space (that's blanks and tabs) stripped off. And if a line ends in \? then the next line gets appended to the current one β also with its initial white-space removed. it's giving "continuation line" energy π«
Now, if the rmComment flag is set to true, blank lines get removed, and so does everything on a line from the first # onward. But β plot twist β if the comment character (#) is prefixed by a backslash (so, \#), it is not treated as a comment. Instead it gets replaced by a single # character. π«Ά
Similarly, if the rmComment flag was set, two consecutive backslash characters are replaced by a single backslash character. In the retrieved configuration information it appears as a single # character. So if your configuration file should actually contain \#, you write \\# β which results in replacing \# by #, leaving \#. yes queen, the escaping is escaping π
Every non-empty line of the configuration file is stored in the ConfigFile object (and when comment is ignored, comment is not considered to be line-content, ok bestie?). And when line indices should be stored, the (0-based) line indices of the lines are available as well π
At construction time you get to specify comment handling (keep comment / remove comment), case-sensitive searching (sensitive / insensitive) and index storage (store / don't store). it's giving β¨customizableβ¨
One thing though: it can't be modified using the open member. But overloaded assignment is supported, and comment and letter case handling can be modified by set-members π
β NAMESPACE β
FBB
All constructors, members, operators and manipulators mentioned in this man-page are defined in the namespace FBB.
π INHERITS FROM π
-
(yeah, nothing. it's giving independent main character energy π)
π ENUMERATIONS π
The following enumerations are defined by the class ConfigFile:
Commentβ this enumeration has two values:ConfigFile::KeepCommentβ used to indicate that comment on lines must be kept πConfigFile::RemoveCommentβ used to indicate that comment on lines must be removed π
SearchCasingβ this enumeration also has two values:ConfigFile::SearchCaseSensitiveβ used to do case sensitive searches for targets πConfigFile::SearchCaseInsensitiveβ used to do case insensitive searches for targets π
Indicesβ this enumeration also has two values:ConfigFile::IgnoreIndicesβ when used, the line numbers of the original configuration file are not available π«ConfigFile::StoreIndicesβ when used, the line numbers of the original configuration file are also available πΎ
π§ TYPES π§
The following types are defined by the class ConfigFile:
const_iteratorβ aconst_iteratoris an iterator pointing to a line (std::string) of the configuration file πΈconst_RE_iteratorβ aconst_RE_iteratoris an iterator pointing to lines matching a regular expression. It supports the following operations:const_RE_iterator &operator++()β the prefix increment operator increments the iterator to point to the next line in the configuration file matching the iterator's regular expression β¨std::string const &operator*()β the dereferencing operator returns the line of the configuration file the iterator refers to πstd::string const *operator->()β the pointer operator returns the address of the line of the configuration file the iterator refers to;const_RE_iterators can be compared for (in)equality, and they can be copy-constructed;const_RE_iteratorobjects are returned by theConfigFile::beginEndREmember and cannot otherwise be constructed π«
When two const_RE_iterator objects are subtracted, the number of lines matching their regular expression is returned. E.g. (see below for a description of the functions used in the next example):
ConfigFile cf(...)
auto iters = cf.beginEndRE("^hello");
cout << "There are " << (iters.second - iters.first) <<
" lines starting with hello\n";
The two const_RE_iterator objects should refer to the same regular expression. The provided example illustrates how this is realized using beginEndRE π«Ά
FBB::Pattern is used to perform the regular expression pattern matching. iykyk π
π CONSTRUCTORS π
ConfigFile(Comment cType = KeepComment, SearchCasing sType = SearchCaseSensitive, Indices iType = IgnoreIndices)β this constructor is used to create an emptyConfigFileobject. It is not associated with an input stream: theopenmember can be used for that. The parameters can be used to specify specific handling of comment, letter-casing and storage of line numbers in the original configuration file πΈConfigFile(std::string const &fname, Comment cType = KeepComment, SearchCasing sType = SearchCaseSensitive, Indices iType = IgnoreIndices)β this constructor is used to create aConfigFileobject which is filled with the information from a file whose name is provided as the constructor's first argument. The other parameters are used as described with the first constructor. It throws anFBB::Exceptionexception if the file could not be opened π
The copy and move constructors and assignment operators are available. π
π OVERLOADED OPERATORS π
std::string const &operator[](size_t idx) constβ this member returns the (0-based)idx-th line of the configuration file β¨
Copy and move constructors (and assignment operators) are available. π
π«Ά MEMBER FUNCTIONS π«Ά
ConfigFile::const_iterator begin() constβ bestie this just hands you aconst_iteratorpointing at the first line of the configuration file. The opening act. β¨ConfigFile::const_iterator end() constβ returns aconst_iteratorpointing beyond the last line of the configuration file. That's your lil' end sentinel, she's not a real line, she's the boundary. πstd::pair<ConfigFile::const_RE_iterator, ConfigFile::const_RE_iterator> beginEndRE(std::string const &target) constβ you get back a pair ofconst_RE_iterators, and here's the tea on what's inside:- The first field of the pair is a
constiterator to the first element (i.e., line) of theConfigFileobject in which the regular expressiontargetis found. π― - The second field is a
constiterator marking the end of the series of lines started at that first line matching the regular expression specified bytarget. - If the
RemoveCommentflag was specified, then comment-text is not searched. π - The iterator in the pair's first field can be incremented until the iterator returned in the pair's second field is reached; all iterators (that aren't equal to the iterator in second) point to lines matching the specified regular expression.
- The iterator's increment operator searches the next line matching the specified regular expression.
- Ngl, you can compute the difference between two
const_RE_iterators, but it's a relatively expensive operation β it's obtained by performing repeated regular expression matchings rather than the mere algebraic subtraction of pointer values. And if the difference can't be computed,std::numeric_limits<size_t>::max()is returned. π - This member also interprets the
SearchCasingflag.
- The first field of the pair is a
std::pair<ConfigFile::const_RE_iterator, ConfigFile::const_RE_iterator> beginEndRE() constβ returns a pair ofconst_RE_iterators, and both of them mark the end of a regular expression search. Two ends, zero content, it's giving "the party's over" πConfigFile::const_iterator find(std::string const &target) constβ this one returns an iterator to the first element (i.e., line) of theFBB::ConfigFileobject in whichtargetis found. Lore drop:targetmay appear anywhere within a line. If theRemoveCommentflag was specified, then comment-text is not searched. Use theendmember to determine the end-iterator. It is not guaranteed that all lines between the returned iterator andendcontaintargetβ so don't get cocky. This member also interprets theSearchCasingflag. πstd::string findKey(std::string const &keyPattern, size_t count = 1) constβ use this cutie to retrieve information from lines having the general patternkeyPattern value. Initial and trailing white space on lines are ignored.keyPatternitself should not contain initial or trailing white space. At least one white space character must appear betweenkeyPatternandvalue. If at leastcountlines were found matchingkeyPattern valuethen this member returns the first sequence of non white space characters followingkeyPatternafter matchingcountlines matchingkeyPattern value(i.e.,valueis returned). Ifvalueis empty or if fewer thancountlines matchkeyPatternan empty string is returned. And anFBB::Exceptionexception is thrown ifcountequals0. Zero. Nada. She said no. π«std::string findKeyTail(std::string const &keyPattern, size_t count = 1) constβ same energy, slightly different flavor: this one retrieves information from lines having the general patternkeyPattern value, merely followed by white space. Initial and trailing white space on lines are ignored.keyPatternitself should not contain initial or trailing white space. At least one white space character must appear betweenkeyPatternandvalue. If at leastcountlines were found matchingkeyPattern valuethen this member returns the information beyondkeyPatternafter matchingcountlines matchingkeyPattern(i.e.,valueis returned). The way this differs fromfindKeyis that all information trailingkeyPatternis returned invalue. Ifvalueis empty or if fewer thancountlines matchkeyPatternan empty string is returned. AnFBB::Exceptionexception is thrown ifcountequals0. Same rule, same refusal. βConfigFile::const_iterator findRE(std::string const &target) constβ returns an iterator to the first line of theConfigFileobject matching the regular expressiontarget. After calling this function,beginEndREreturns an iterator pair whose first field is an iterator to the same line and whose second field is the end-iterator for lines matchingtarget. If theRemoveCommentflag was specified, then comment-text is not searched. The inheritedendmember can be used to determine the end-iterator. It is not guaranteed that all lines between the returned iterator andendalso containtarget. πsize_t index(size_t idx) constβ only use this one when the parameterStoreIndiceswas specified at construction time. In that case it returns the original 0-based line index in the configuration file associated with theidx(0-based) index in the currentConfigurationobject. π’size_t index(const_iterator const &iter) constβ again, only for when the parameterStoreIndiceswas specified at construction time. Then it returns the original 0-based line index in the configuration file associated with the configuration line in the currentConfigurationobject pointed to byiter. And surprise: this may also be an (incremented version of the) iterator returned by the memberfindRE. π§void open(std::string const &fname)β this member reads the configuration file having namefname. Heads up: it redefines the current content of theConfigFileobject, destroying any information previously stored in it. (Gone. Poof. No undo. π) The configuration file is read according to the latest setting of the comment-flag. It throws anFBB::Exceptionexception if the file cannot be opened.
So basically: this member clears previously available information and reinitializes the object with information read from the new file. Fresh start, new me. π
void setCommentHandling(Comment type)β use this to change the comment-handling type originally set by the constructor, or set by earlier calls of this function. Important: when called it won't affect the current content of theConfigFileobject β but new calls of itsopenmember read the configuration file according to the last setting of the comment flag. So it's a "settings for next time" kinda girl. πvoid setSearchCasing(SearchCasing type)β same deal for letter-casing: changes the handling originally set by the constructor, or set by earlier calls of this function. When called it won't affect the current content of theConfigFileobject, but new calls of itsopenmember read the configuration file according to the last setting of the letter-casing flag. π€size_t size() constβ returns the number of lines in the configuration file. That's it. That's the whole function. Iconic. π
πΈ EXAMPLE πΈ
Okay so imagine the configuration file is called config.rc and it contains these lines:
# this is ignored
noline: this one too
line: this is found
this is not a line containing line: at the beginning of the line
line: this one is
line: what about this one? itβs extending over multiple lines
and there may, of course, be more lines in this file. β¨
The following program may be compiled and run as a.out config.rc:
#include <iostream>
#include <iterator>
#include <algorithm>
#include <string>
#include <bobcat/configfile>
using namespace std;
using namespace FBB;
int main(int argc, char **argv)
{
ConfigFile cf(argv[1]);
cout << *cf.find("this one") << β\nβ; // find text within a line
// find all lines matching
auto [begin, end] = cv.beginEndRE("^line:"); // `^line:β
copy(begin, end, ostream_iterator<string>(cout, "\n"));
}
Producing the output:
noline: this one too
line: this is found
line: this one is
line: what about this one? itβs extending over multiple lines
Ate, no cap. π«Ά
π FILES π
bobcat/configfileβ defines the class interface
π¦ SEE ALSO π¦
π BUGS π
None Reported.
π BOBCAT PROJECT FILES π
https://fbb-git.gitlab.io/bobcat/: gitlab project page;
Debian Bobcat project files:
libbobcat6: debian package containing the shared library, changelog and copyright note;libbobcat-dev: debian package containing the static library, headers, manual pages, and developer info;
π BOBCAT π
Bobcat is an acronym of `Brokkenβs Own Base Classes And Templatesβ.
β COPYRIGHT β
This is free software, distributed under the terms of the GNU General Public License (GPL).
π AUTHOR π
Frank B. Brokken (f.b.brokken@rug.nl).
And that's a wrap on the whole page, bestie!! π₯³ This one ships out of libbobcat-dev_6.15.01, dated 2005-2026, and it lives at FBB::ConfigFile(3bobcat) β go forth and configure your little heart out. Mwah. πππ¦
π¦ where this page comes from
- ubuntu stonking: libbobcat-dev 6.15.01-1 Β· GPL-3.0-or-later WITH OpenSSL exception
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms