1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
|
includefile(include/header)
COMMENT(manpage, section, releasedate, archive, short name)
manpage(FBB::ConfigFile)(3bobcat)(_CurYrs_)
(libbobcat-dev__CurVers_)(Configuration File Processing)
manpagename(FBB::ConfigFile)
(A class processing standard unix-like configuration files)
manpagesynopsis()
bf(#include <bobcat/configfile>)nl()
Linking option: tt(-lbobcat)
manpagedescription()
This class is deprecated: the class bf(FBB::Config)
(cf. bf(config)(3bobcat)) should be used instead.
bf(ConfigFile) objects read standard tt(unix)-style configuration
files. Lines are stored with initial white-space (blanks and tabs) removed.
If a line ends in \, then the next line (initial white-space removed) is
appended to the current line.
If the tt(rmComment) flag is set to tt(true) blanks lines and
information on lines from the first tt(#) are removed. If the comment
character (tt(#)) is
prefixed by a backslash (i.e., tt(\#)) it is not considered comment, but
replaced by a single tt(#) character. Likewise, if the tt(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 tt(#) character. If the configuration file should contain
tt(\#) write tt(\\#), this results in replacing tt(\#) by tt(#), leaving
tt(\#).
All non-empty lines of the configuration file (when comment is ignored comment
is not considered to be line-content) are stored in the bf(ConfigFile) object.
When line indices should be stored the (0-based) line indices of lines are
available as well.
At construction time comment handling (keep comment / remove comment),
case-sensitive searching (sensitive / insensitive) and index storage (store /
don't store) can be specified.
It can't be modified using the tt(open) member, but overloaded assignment is
supported and comment and letter case handling can be modified by set-members.
includefile(include/namespace)
manpagesection(INHERITS FROM)
-
manpagesection(ENUMERATIONS)
The following enumerations are defined by the class bf(ConfigFile):
itemization(
itb(Comment)
This enumeration has two values: nl()
bf(ConfigFile::KeepComment) is used to indicate that comment on
lines must be kept; nl()
bf(ConfigFile::RemoveComment) is used to indicate that comment on
lines must be removed;
itb(SearchCasing)
This enumeration also has two values:nl()
bf(ConfigFile::SearchCaseSensitive) is used to do case sensitive
searches for targets;nl()
bf(ConfigFile::SearchCaseInsensitive) is used to do case
insensitive searches for targets.
itb(Indices)
This enumeration also has two values:nl()
bf(ConfigFile::IgnoreIndices) when used, the line numbers of the
original configuration file are not available;nl()
bf(ConfigFile::StoreIndices) when used, the line numbers of the
original configuration file are also available;nl()
)
manpagesection(TYPES)
The following types are defined by the class tt(ConfigFile):
itemization(
itb(const_iterator)
a tt(const_iterator) is an iterator pointing to a
line (tt(std::string)) of the configuration file;
itb(const_RE_iterator) a tt(const_RE_iterator) is an iterator pointing to
lines matching a regular expression. It supports the following operations:
itemization(
itt(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;
itt(std::string const &operator*()): the dereferencing operator
returns the line of the configuration file the iterator refers to;
itt(std::string const *operator->()): the pointer operator returns the
address of the line of the configuration file the iterator refers to;
)
tt(const_RE_iterator)s can be compared for (in)equality and they can be
copy-constructed; tt(const_RE_iterator) objects are returned by the
tt(ConfigFile::beginEndRE) member and cannot otherwise be constructed.
When two tt(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):
verb(
ConfigFile cf(...)
auto iters = cf.beginEndRE("^hello");
cout << "There are " << (iters.second - iters.first) <<
" lines starting with hello\n";
)
The two tt(const_RE_iterator) objects should refer to the same regular
expression. The provided example illustrates how this is realized using
tt(beginEndRE).
tt(FBB::Pattern) is used to perform the regular expression pattern
matching.
)
manpagesection(CONSTRUCTORS)
itemization(
itb(ConfigFile(Comment cType = KeepComment, SearchCasing sType =
SearchCaseSensitive, Indices iType = IgnoreIndices))
This constructor is used to create an empty bf(ConfigFile)
object. It is not associated with an input stream: the tt(open) member 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.
itb(ConfigFile(std::string const &fname, Comment cType = KeepComment,
SearchCasing sType = SearchCaseSensitive,
Indices iType = IgnoreIndices))
This constructor is used to create a bf(ConfigFile) object, 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 an tt(FBB::Exception) exception if the file
could not be opened.
)
manpagesection(OVERLOADED OPERATORS)
itemization(
itb(std::string const &operator[](size_t idx) const)
This member returns the (0-based) tt(idx)-th line of the configuration
file.
)
Copy and move constructors (and assignment operators) are available.
manpagesection(MEMBER FUNCTIONS)
itemization(
itb(ConfigFile::const_iterator begin() const)
This member returns a tt(const_iterator) to the first line of the
configuration file.
itb(ConfigFile::const_iterator end() const)
This member returns a tt(const_iterator) pointing beyond the last line
of the configuration file.
itb(std::pair<ConfigFile::const_RE_iterator, ConfigFile::const_RE_iterator>
beginEndRE(std::string const &target) const)
A pair of tt(const_RE_iterators) is returned. The tt(first)
field of the pair is a tt(const) iterator to the first element (i.e.,
line) of the bf(ConfigFile) object in which the regular expression tt(target)
is found.
The tt(second) field is a tt(const) iterator marking the end of the
series of lines started at the the first line matching the regular expression
specified by tt(target).
If the tt(RemoveComment) flag was specified, then comment-text is not
searched. The iterator returned in the pair's tt(first) field can be
incremented until the iteratr returned in the pair's tt(second) field is
reached; all iterators (unequal the iterator in tt(second)) point to lines
matching the specified regular expression.
The iterator's increment operator searches the next line matching the
specified regular expression.
Although the difference between two tt(const_RE_iterators) can be computed
it is a relatively expensive operation. The difference is obtained by
performing repeated regular expression matchings rather than the mere
algebraic subtraction of pointer values. If the difference cannot be computed
tt(std::numeric_limits<size_t>::max()) is returned.
This member also interprets the tt(SearchCasing) flag.
itb(std::pair<ConfigFile::const_RE_iterator, ConfigFile::const_RE_iterator>
beginEndRE() const)
A pair of tt(const_RE_iterators) is returned, both marking the end of
a regular expression search.
itb(ConfigFile::const_iterator find(std::string const &target) const)
This member returns an iterator to the first element (i.e., line) of
the tt(FBB::ConfigFile) object in which tt(target) is found. Note that
tt(target) may appear anywhere within a line. If the tt(RemoveComment) flag
was specified, then comment-text is not searched. Use the tt(end) member to
determine the end-iterator. It is not guaranteed that all lines between the
returned iterator and tt(end) contain tt(target). This member also
interprets the tt(SearchCasing) flag.
itb(std::string findKey(std::string const &keyPattern,
size_t count = 1) const)
This member can be used to retrieve information from lines having the
general pattern `tt(keyPattern value)'. Initial and trailing white space on
lines are ignored. tt(keyPattern) itself should not contain initial or
trailing white space. At least one white space character must appear between
tt(keyPattern) and tt(value). If at least tt(count) lines were found matching
tt(keyPattern value) then this member returns the first sequence of non white
space characters following tt(keyPattern) after matching tt(count) lines
matching tt(keyPattern value) (i.e., `tt(value)' is returned). If tt(value) is
empty or if fewer than tt(count) lines match tt(keyPattern) an empty string is
returned. An tt(FBB::Exception) exception is thrown if tt(count) equals 0.
itb(std::string findKeyTail(std::string const &keyPattern,
size_t count = 1) const)
This member can be used to retrieve information from lines having the
general pattern `tt(keyPattern value)', merely followed by white
space. Initial and trailing white space on lines are ignored. tt(keyPattern)
itself should not contain initial or trailing white space. At least one white
space character must appear between tt(keyPattern) and tt(value). If at least
tt(count) lines were found matching tt(keyPattern value) then this member
returns the information beyond tt(keyPattern) after matching tt(count) lines
matching tt(keyPattern) (i.e., `tt(value)' is returned). This function differs
from tt(findKey) in that all information trailing tt(keyPattern) is returned
in tt(value). If tt(value) is empty or if fewer than tt(count) lines match
tt(keyPattern) an empty string is returned. An tt(FBB::Exception) exception is
thrown if tt(count) equals 0.
itb(ConfigFile::const_iterator findRE(std::string const &target) const)
This member returns an iterator to the first line of the
bf(ConfigFile) object matching the regular expression tt(target). After
calling this function tt(beginEndRE) returns an iterator pair whose tt(first)
field is an iterator to the same line and whose tt(second) field is the
end-iterator for lines matching tt(target). If the tt(RemoveComment) flag was
specified, then comment-text is not searched. The inherited tt(end) member
can be used to determine the end-iterator. It is not guaranteed that all lines
between the returned iterator and tt(end) also contain tt(target).
itb(size_t index(size_t idx))
This function should only be used when the parameter tt(StoreIndices)
was specified at construction time. In that case it returns the original
0-based line index in the configuration file associated with the
tt(idx)sups(th) (0-based) index in the current tt(Configuration) object.
itb(size_t index(const_iterator const &iter))
This function should only be used when the parameter tt(StoreIndices)
was specified at construction time. In that case it returns the original
0-based line index in the configuration file associated with the configuration
line in the current tt(Configuration) object pointed to by tt(iter). This may
also be an (incremented version of the) iterator returned by the member
tt(findRE).
itb(void open(std::string const &fname))
This member reads the configuration file having name tt(fname).
It redefines the current content of the bf(ConfigFile) object,
destroying any information previously stored in it. The configuration file is
read according to the latest setting of the comment-flag. It throws an
tt(FBB::Exception) exception if the file cannot be opened.
This member clears previously available information and reinitializes the
object with information read from the new file.
itb(void setCommentHandling(Comment type))
This member can be used to change the comment-handling type originally
set by the constructor, or set by earlier calls of this function. When called
it won't affect the current content of the bf(ConfigFile) object, but
new calls of its tt(open) member reads the configuration file according
to the last setting of the comment flag.
itb(void setSearchCasing(SearchCasing type))
This member can be used to change the handling of the letter-casing
originally set by the constructor, or set by earlier calls of this
function. When called it won't affect the current content of the
bf(ConfigFile) object, but new calls of its tt(open) member reads the
configuration file according to the last setting of the letter-casing flag.
itb(size_t size() const)
This member returns the number of lines in the configuration file.
)
manpagesection(EXAMPLE)
Assume the configuration file is called tt(config.rc) and contains the
following lines:
COMMENT(Keep the blank following the backslashes below:)
verb(
# 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 tt(a.out config.rc):
verb(
#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:
verb(
noline: this one too
line: this is found
line: this one is
line: what about this one? it's extending over multiple lines
)
manpagefiles()
em(bobcat/configfile) - defines the class interface
manpageseealso()
bf(argconfig)(3bobcat), bf(bobcat)(7), bf(config)(3bobcat)
bf(exception)(3bobcat), bf(pattern)(3bobcat)
manpagebugs()
None Reported.
includefile(include/trailer)
|