FBB::Config(3bobcat)
π FBB::Config(3bobcat) π β Configuration File Processing
okay so bestie, we're doing FBB::Config today, from the 3bobcat manual, and it's giving config file royalty. This is part 1 so buckle up, there's more coming π
β¨ NAME β¨
FBB::Config β the class that processes standard unix-like configuration files, no cap π
β¨ SYNOPSIS β¨
#include <bobcat/config>
Linking option: -lbobcat
so you include that header, you link with that flag, and boom you're in π¦
β¨ DESCRIPTION β¨
Config objects process standard unix-style configuration files. First thing it does: initial white-space (that's blanks and tabs, bestie) gets yeeted off every processed line. And if a line ends in a backslash (\)?? girlypop the backslash gets removed and the very next line β with its initial white-space ALSO removed β gets appended onto the current line. it's giving "I'm one line now" β¨
If the rmComment flag is set to true, blank lines and everything on a line starting from the first # get removed. BUT β plot twist β if a backslash comes right before the comment character (so, \#), that is not treated as a comment, it's replaced by a single # character instead. Similarly, if the rmComment flag is set, two backslash characters in a row get replaced by a single backslash character. periodt.
All the lines of the configuration file (possibly without the comment, depending) get stored inside the Config object. Their line numbers can be retrieved too π
At construction time you can specify two things: comment handling (keep comment / remove comment) and the type of searching (case sensitive / insensitive). main character energy fr fr.
In addition to one of the constructors, the load member can be used to process a configuration file β it replaces the object's current content with the content of another configuration file. Lowkey important caveat though: the load member cannot be used to alter the configuration file's processing parameters. But don't cry β overloaded assignment is supported, and comment- and letter-case handling can be modified by set-members π
Often lines in a config show this structure:
id: value trailing content
If id is a C++ identifier, this man-page calls it an ID. When looking for IDs, all non white-space characters immediately following the ID are ignored (in that example up there, the ID is id). A Key is defined as the first white-space delimited entry on a line. In the example, the key is id:. The first space-delimited entry following the key is the line's value, and all the line's content starting at value is the line's tail. slay, we have vocabulary πΈ
Config objects offer various members to process configuration file lines that are structured this way. BUT β and this is the iconic part β lines do not have to be structured this way. All the lines of a configuration file are made available by Config objects and can be processed in several other ways as well π«Ά
β¨ NAMESPACE β¨
FBB
All constructors, members, operators and manipulators mentioned in this man-page are defined in the namespace FBB. don't forget it π
β¨ INHERITS FROM β¨
-
(das it. it inherits from nothing. it's self-made, it's independent, it's that girl π )
β¨ ENUMERATIONS β¨
The following enumerations are defined by the class Config:
Comment: This enumeration has two values:Config::KeepCommentβ specifies that comment on lines must be kept β¨Config::NoCommentβ specifies that comment on lines must be removed π
Casing: This enumeration also has two values:Config::UseCaseβ specifies that specified targets must match case-sensitively πConfig::NoCaseβ specifies that specified targets are matched case-insensitively π
β¨ TYPES β¨
The following types are defined by the class Config:
const_iterator: a random access iterator referring to a line read from a configuration file.FBB::Config::const_iteratorobjects point toFBB::CF_Lineobjects (peep the next section for the whole description of the classCF_Line) πCIVect::const_iterator: an iterator type referring to lines matching regular expressions or IDs. It supports the standard random access iterator facilities. The dereference operators ofFBB::Config::CIVect::const_iteratorobjects returnFBB::Config::const_iteratorobjects. it's iterators all the way down bestie π¦
When two CIVect::const_iterator objects are subtracted, the number of lines matching their regular expressions (or IDs) is returned. Like, for example:
Config cf(...)
auto pair = cf.beginEndID("scenario");
cout << "There are " << (pair.second - pair.first) <<
" lines starting with the ID `scenarioβ\n";
Pattern(3bobcat) objects are used when looking for lines matching regular expressions π₯
β¨ CF_Line β¨
const_iterators point to objects of the class FBB::CF_Line. Objects of this class contain a line from the configuration file and its line number. The class offers the following facilities:
CF_Line(): the default constructor initialized its object with line number0, and an empty line;CF_Line(uint16_t lineNr, std::string const &line): this constructor initialized its object with line numberlineNr, and a copy of the contents ofline;std::string const &line() const: returns the object's line;std::string key() const: returns the line's key field;uint16_t lineNr() const: returns the line's line number;std::string tail() const: returns the line's tail field (i.e., the info beyond the key);std::string value() const: returns the line's value field (i.e., the first white-space delimited entry following the line's ID);CF_Lineobjects may be inserted intostd::ostreamobjects, inserting their lines into the streams π
Copy- and move-constructors and -assignment operators are available β¨
β¨ CONSTRUCTORS β¨
Config(Casing sType = UseCase, Comment cType = NoComment): creates an empty object. It is not associated with a configuration file; theloadmember can be used for that. The parameters specify specific handling of comment, and letter-casing;Config(std::string const &fname, Casing sType = UseCase, Comment cType = NoComment): creates aConfigobject, containing the information from the configuration filefname. The other parameters are used as described with the abovementioned constructor. If the file cannot be opened anFBB::Exceptionexception is thrown π;Config(std::istream &stream, Casing sType = UseCase, Comment cType = NoComment): same functionality as the previous constructor, but reading the configuration information from thestd::istreamstream;Config(std::istream &stream, uint16_t lineNr, Casing sType = UseCase, Comment cType = NoComment): same functionality as the previous constructor, but the line number of the first line read fromstreamis set tolineNr;Config(std::istream &&tmp, Casing sType = UseCase, Comment cType = NoComment): same functionality as the constructor expecting anistreamreference, but this time the configuration information is read from thestd::istreamrvalue referencetmp;Config(std::istream &&tmp, uint16_t lineNr, Casing sType = UseCase, Comment cType = NoComment): same functionality as the previous constructor, but the line number of the first line read fromstreamis set tolineNr. π₯
Copy- and move-constructors and -assignment operators are available β¨
β¨ OVERLOADED OPERATORS β¨
CF_Line const &operator[](size_t idx) const: returns the (0-based)idx-th line of the configuration file π
okay that's the whole first chunk bestie, and there's more coming so don't go anywhere π
β¨ MEMBER FUNCTIONS β¨
okay bestie, here's the whole member function menu. every signature is exactly as the manpage drops it, periodt. π
const_iterator begin() constβ returns aconst_iteratorreferring to the first line of the configuration file. it's giving start of the lore energy. β¨std::pair<CIVect::const_iterator, CIVect::const_iterator> beginEndID(std::string const &rid) constβ returns a pair ofCIVect::const_iterators. its first field is aCIVect::const_iteratorreferring to the first line containing IDid; its second field is aCIVect::const_iteratormarking the end of the series of lines containing IDid. the difference between the two iterators equals the number of lines containing IDid. a whole range of ID lines, slay. π«Άstd::pair<CIVect::const_iterator, CIVect::const_iterator> beginEndRE(std::string const ®ex) constβ same functionality as the previous member, but returning a pair of iterators to lines matchingregex. regex bestie, we love a pattern match. πΈconst_iterator end() constβ returns aconst_iteratorpointing beyond the last line of the configuration file. it's the no more lines, bye iterator. πvoid clear()β clears the current content of theConfigobject. this member is automatically called by theloadmembers. not me noticing thatloadhandles the cleanup for u. π§const_iterator find(std::string const &target) constβ returns an iterator to the first line containingtarget, starting the search atbegin(). note thattargetmay appear anywhere within a line. it returnsend()if no such line was found. no cap, anywhere in the line counts. π₯const_iterator find(std::string const &target, const_iterator from) constβ same functionality as the previous member, but searching starts atfrom. lowkey the same but with a glow-up starting point. β¨const_iterator findID(std::string const &id) constβ returns an iterator of the first line containing IDid. it returnsend()if no such line was found. ID main character energy. πconst_iterator findID(std::string const &id, const_iterator from) constβ same functionality as the previous member, but searching starts atfrom. periodt.const_iterator findKey(std::string const &key) constβ returns an iterator of the first line containing keykeyβ. it returnsend()if no such line was found. (yes bestie, the quote situation is exactly as the manpage gives it.) πconst_iterator findKey(std::string const &key, const_iterator from) constβ same functionality as the previous member, but searching starts atfrom. πconst_iterator findRE(std::string const ®ex) constβ an iterator is returned to the first line matching the regular expressionregex. it returnsend()if no such line was found. regex girlies rise. πvoid load(std::string const &fname)β the content of the file namedfnameis stored in theConfigobject, replacing any previously stored content. the file is read according to the latest setting of theCommentandCasingflags. if the file cannot be opened anFBB::Exceptionexception is thrown. so like, catch it or perish. πvoid load(std::istream &stream, uint16_t lineNr = 1)β same functionality as the previous member, but reading the configuration information from thestd::istreamreferencestream. thelineNrvalue specifies the line number of the first read line. default1, cute. πvoid load(std::istream &&tmp, uint16_t lineNr = 1)β same functionality as the previous member, but reading the configuration information from thestd::istreamrvalue referencetmp. rvalue reference representation. β¨void setComment(Comment type)β the objectβs comment-handling type is set totype(eitherKeepCommentorNoComment). it doesnβt affect the current content of theConfigobject, but when callingloadthe configuration file is processed according totypeβs value. so it's a future-vibe setting, not a now-vibe setting. πvoid setCasing(Casing type)β the objectβs letter case handling type is set totype(eitherUseCaseorNoCase). casing drama activated. π₯size_t size() constβ returns the number of lines stored in theConfigobject. count them, bestie. π
π EXAMPLE π
okay so imagine the configuration file is named config.rc, and it contains these exact 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 extends over multiple lines
and there may, of course, be more lines in this file
the next program may be compiled and run as a.out config.rc:
#include <iostream>
#include <algorithm>
#include <string>
#include <bobcat/config>
using namespace std;
using namespace FBB;
int main(int argc, char **argv)
{
Config cf(argv[1]);
cout << *cf.find("this one") << β\nβ; // find text within a line
// find all lines specifying ID βlineβ
auto [begin, end] = cv.beginEndID("line");
copy(begin, end, ostream_iterator<CF_Line>(cout, "\n"));
}
Producing the output:
line: this is found
line: this one is
line: what about this one? it extends over multiple lines
π FILES π
bobcat/configβ defines the class interface
π SEE ALSO π
argconfig(3bobcat), bobcat(7), exception(3bobcat), pattern(3bobcat)
π BUGS π
None reported. (iconic, no bugs bestie)
π¦ 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).
mwah π this page lives in libbobcat-dev_6.15.01, dated 2005-2026, and it's FBB::Config(3bobcat). periodt.
π¦ 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