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_iterator objects point to FBB::CF_Line objects (peep the next section for the whole description of the class CF_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 of FBB::Config::CIVect::const_iterator objects return FBB::Config::const_iterator objects. 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 number 0, and an empty line;
  • CF_Line(uint16_t lineNr, std::string const &line): this constructor initialized its object with line number lineNr, and a copy of the contents of line;
  • 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_Line objects may be inserted into std::ostream objects, 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; the load member 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 a Config object, containing the information from the configuration file fname. The other parameters are used as described with the abovementioned constructor. If the file cannot be opened an FBB::Exception exception is thrown 😭;
  • Config(std::istream &stream, Casing sType = UseCase, Comment cType = NoComment): same functionality as the previous constructor, but reading the configuration information from the std::istream stream;
  • 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 from stream is set to lineNr;
  • Config(std::istream &&tmp, Casing sType = UseCase, Comment cType = NoComment): same functionality as the constructor expecting an istream reference, but this time the configuration information is read from the std::istream rvalue reference tmp;
  • 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 from stream is set to lineNr. πŸ”₯

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 a const_iterator referring 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 of CIVect::const_iterators. its first field is a CIVect::const_iterator referring to the first line containing ID id; its second field is a CIVect::const_iterator marking the end of the series of lines containing ID id. the difference between the two iterators equals the number of lines containing ID id. a whole range of ID lines, slay. 🫢
  • std::pair<CIVect::const_iterator, CIVect::const_iterator> beginEndRE(std::string const &regex) const β€” same functionality as the previous member, but returning a pair of iterators to lines matching regex. regex bestie, we love a pattern match. 🌸
  • const_iterator end() const β€” returns a const_iterator pointing beyond the last line of the configuration file. it's the no more lines, bye iterator. πŸ‘‘
  • void clear() β€” clears the current content of the Config object. this member is automatically called by the load members. not me noticing that load handles the cleanup for u. 🧚
  • const_iterator find(std::string const &target) const β€” returns an iterator to the first line containing target, starting the search at begin(). note that target may appear anywhere within a line. it returns end() 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 at from. 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 ID id. it returns end() 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 at from. periodt.
  • const_iterator findKey(std::string const &key) const β€” returns an iterator of the first line containing key key’. it returns end() 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 at from. πŸ’–
  • const_iterator findRE(std::string const &regex) const β€” an iterator is returned to the first line matching the regular expression regex. it returns end() if no such line was found. regex girlies rise. 🌈
  • void load(std::string const &fname) β€” the content of the file named fname is stored in the Config object, replacing any previously stored content. the file is read according to the latest setting of the Comment and Casing flags. if the file cannot be opened an FBB::Exception exception 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 the std::istream reference stream. the lineNr value specifies the line number of the first read line. default 1, cute. πŸ“
  • void load(std::istream &&tmp, uint16_t lineNr = 1) β€” same functionality as the previous member, but reading the configuration information from the std::istream rvalue reference tmp. rvalue reference representation. ✨
  • void setComment(Comment type) β€” the object’s comment-handling type is set to type (either KeepComment or NoComment). it doesn’t affect the current content of the Config object, but when calling load the configuration file is processed according to type’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 to type (either UseCase or NoCase). casing drama activated. πŸ”₯
  • size_t size() const β€” returns the number of lines stored in the Config object. 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 πŸ¦‹

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’.


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