StormByte C++ Library: Config module 1.0.1.9999
StormByte-Config is the configuration module of the StormByte C++ suite.
Loading...
Searching...
No Matches
StormByte-Config

Platform C++26 CMake License: LGPL v3 CI Sponsor

This repository is StormByte Config: human-readable text and versioned binary documents for the StormByte C++ suite.

It depends on StormByte Base. Public headers live under StormByte/config/ and cover the document, items (values, comments, groups, lists), Save / Load, and collision / hook policy.

The suite is split on purpose. Base, Buffer, Crypto, Database, Logger, Multimedia, Network and System are other repositories. This one does not implement them.

What this module does

  • Text and binary I/OSave / Load with Mode::Text or Mode::Binary on any std::ostream / std::istream. Stream operators stay text-only.
  • Versioned binary — magic STBTCF + format version. Older layouts load; newer ones are rejected; save always writes the current version.
  • Values — string, integer, double, boolean, binary (std::vector<std::byte>: Base64 b"..." in text, raw bytes on the wire).
  • Comments#, //, /* */.
  • Containers — lists [] and groups {}.
  • HooksAddHookBeforeRead / AddHookAfterRead.
  • On existingKeep, Overwrite, or ThrowException (default).

The rest of the suite

Module Role API
Base Exceptions, Expected, serialization, strings, UUID, concepts /StormByte
Buffer FIFO, SharedFIFO, Ring, Producer/Consumer and multi-stage pipelines /StormByte-Buffer
Config This repository /StormByte-Config
Crypto Hash, compress, encrypt, sign and key agreement — Crypto++ never leaves the private tree /StormByte-Crypto
Database One API over SQLite, PostgreSQL and MariaDB /StormByte-Database
Logger Stream logger with levels, headers, human-readable sizes and redaction (ThreadedLog) /StormByte-Logger
Multimedia Decode, encode and containers without raw FFmpeg types; codecs enabled only if present /StormByte-Multimedia
Network Framed packets, Client/Server, IPv4/IPv6 TCP and Buffer pipelines (compress/encrypt) /StormByte-Network
System Processes, pipes and environment variables across Linux, Windows and macOS /StormByte-System

Table of Contents

  • What this module does
  • The rest of the suite
  • Installation
  • Usage
    • Load from a stream
    • Binary Save / Load
    • Values and containers
  • Contributing
  • License

Installation

Needs a C++26 compiler, CMake 3.28 or newer, and StormByte Base ≥ 1.0.0.

git clone --recursive https://github.com/StormBytePP/StormByte-Config.git
cd StormByte-Config
cmake -S . -B build
cmake --build build

Usage

Headers are #include <StormByte/config/….hxx>. Namespace root is StormByte::Config.

Load from a stream

#include <StormByte/config/config.hxx>
#include <fstream>
using namespace StormByte::Config;
int main() {
Config config;
std::ifstream file("config.cfg");
file >> config;
}
Configuration document (text or versioned binary).
Definition config.hxx:54
Config module of the StormByte suite.
Definition alias.hxx:29

Hooks: AddHookBeforeRead / AddHookAfterRead. Existing keys: OnExistingAction (Keep, Overwrite, ThrowException; default is throw).

Binary Save / Load

#include <StormByte/config/config.hxx>
#include <fstream>
#include <iostream>
using namespace StormByte::Config;
int main() {
Config config;
config.Add(Item::Value<std::string>("username", "example_user"));
config.Add(Item::Value<int>("timeout", 30));
{
std::ofstream out("config.bin", std::ios::binary);
config.Save(out, Mode::Binary);
}
std::ifstream in("config.bin", std::ios::binary);
auto loaded = Config::Load(in, Mode::Binary);
if (!loaded) {
std::cerr << loaded.error()->what() << std::endl;
return 1;
}
std::cout << loaded.value()["username"].Value<std::string>() << std::endl;
}
Item::Base & Add(const Item::Base &item)
Adds an item to the configuration.
Definition config.hxx:273
void Save(std::ostream &stream, Mode mode=Mode::Text) const
Write this document to an output stream.
Named or unnamed typed value.
Definition value.hxx:37

Values and containers

username = "example_user"
timeout = 30
feature_timeout = 60.5
enabled = true
payload = b"SGVsbG8gV29ybGQ="
favorite_numbers = [3 14 42 "pi constant"]
settings = {
username = "example_user"
timeout = 30
}
# bash comment
// C++ comment
/* multiline */

Binary values are std::vector<std::byte>. Text form is Base64 with b"..."; the binary document stores raw bytes.

Contributing

Issues only on this repository. Fork and open a pull request against master.

License

GNU Lesser General Public License version 3 or later. See [LICENSE](LICENSE) and https://www.gnu.org/licenses/lgpl-3.0.html.