l Libconfig is a simple library for processing structured configuration files.
l It is used for reading, manipulating, and writing structured configuration files
l It is more compact and more readable than XML. And unlike XML, it is type-aware, so it is not necessary to do string parsing in application code.
l The library includes bindings for both the C and C++ languages.
l The library features a fully reentrant parser and includes bindings for both the C and C++ programming languages.
l It works on POSIX-compliant UNIX and UNIX-like systems (GNU/Linux, Mac OS X, FreeBSD), Android, and Windows (2000, XP and later).
LICENSE-
Libconfig is distributed under the terms of the GNU Lesser General Public License. This license was chosen over the standard GNU license to allow libconfig to be used with non-free programs.
USING LIBRARY FOR C++ PROGRAM-
To use the library from C++, include the following preprocessor directive in your source files:
#include <libconfig.h++>
Or, alternatively:
#include <libconfig.hh>
The C++ API classes are defined in the namespace 'libconfig' , hence the following statement may optionally be used:
using namespace libconfig;
To link with the library, specify '-lconfig++' as an argument to the linker.
CONFIGURATION FILES-
Libconfig supports structured, hierarchical configurations. These configurations can be read from and written to files and manipulated in memory.
A configuration consists of a group of settings, which associate names with values. A value can be one of the following:
l A scalar value: integer, 64-bit integer, floating-point number, boolean, or string.
l An array, which is a sequence of scalar values, all of which must have the same type.
l A group, which is a collection of settings.
l A list, which is a sequence of values of any type, including other lists.
Consider the following configuration file for a hypothetical GUI application, which illustrates all of the elements of the configuration file grammar.
Settings can be uniquely identified within the configuration by a path. The path is a dot-separated sequence of names, beginning at a top-level group and ending at the setting itself. Each name in the path is the name of a setting; if the setting has no name because it is an element in a list or array, an integer index in square brackets can be used as the name.
For example, in our hypothetical configuration file, the path to the x setting is application.window.pos.x; the path to the version setting is simply version; and the path to the title setting of the second book in the books list is application.books.[1].title.
The datatype of a value is determined from the format of the value itself.
THE C++ API-
The class Config represents a configuration, and the class Setting represents a configuration setting. Note that by design, neither of these classes provides a public copy constructor or assignment operator. Therefore, instances of these classes may only be passed between functions via references or pointers.
The library defines a group of exceptions, all of which extend the common base exception ConfigException.
A SettingTypeException is thrown when the type of a setting's value does not match the type requested.
The following example presents a concise way to look up three values at once and perform error handling if any of them are not found or are of the wrong type:
DISADVANTAGES OF LIBCONFIG-
l The functions in the library do not make use of global variables and do not maintain state between successive calls.
l Libconfig is not thread-safe. The library is not aware of the presence of threads and knows nothing about the host system's threading model. Therefore, if an instance of a configuration is to be accessed from multiple threads, it must be suitably protected by synchronization mechanisms like read-write locks or mutexes; the standard rules for safe multithreaded access to shared data must be observed.
l Libconfig is not async-safe. Calls should not be made into the library from signal handlers.
l Libconfig is not guaranteed to be cancel-safe. Since it is not aware of the host system's threading model, the library does not contain any thread cancellation points.
l Libconfig does not natively support Unicode configuration files.
Name | Views | Likes |
---|---|---|
C++ string_wide_character_type | 343 | 3 |
C++ sum of the minimum elements of sub-array of array. | 272 | 1 |
C++ BFS | 426 | 1 |
C++ BANKERS ALGORITHM | 11105 | 2 |
C++ string_wide_char | 274 | 2 |
C++ TOWER OF HANOI | 878 | 2 |
C++ UTILITY LIBRARIES | 270 | 2 |
C++ COUNT CONVERSION | 411 | 1 |
C++ string::identify_alpha_numeric | 274 | 2 |
C++ TEMPLATES | 353 | 2 |
C++ QJSON | 404 | 3 |
C++ libconfig | 683 | 3 |
C++ COUNTING NUMBER OF SET BITS IN ARRAY | 415 | 1 |
C++ RULES AND AMBIGUITY IN FUNCTION OVERLOADING | 2662 | 2 |
C++ std::any | 224 | 2 |
C++ std::string_view | 378 | 2 |
LOOP INVARIANT SYNTAX - AN INTODUCTION | 285 | 1 |
C++ Localization Library | 672 | 2 |
C++ DINING PHILOSOPHERS PROBLEM | 3023 | 2 |
C++ QUICK SORT | 886 | 1 |
C++ CLOSET PAIR OF POINTS | 671 | 1 |
C++ SCAN DISK ALGORITHM | 1195 | 2 |
C++ MAXIMUM SUBSET WITH BITWISE OR | 512 | 1 |
C++ LOOK DISK ALGORITHM | 677 | 2 |
C++ C-SCAN DISK ALGORITHM | 607 | 2 |
Comments