openFrameworks addon for converting config files type-by-type
README
ofxConfigBridge
ofxConfigBridge is an openFrameworks addon that provides a unified interface for reading, writing, and converting between multiple configuration file formats โ including YAML, JSON, and TOML โ with extensible support for future formats such as INI and XML.
---
โจ Features
- ๐งฉ Unified API for file I/O and format conversion
- ๐ Multiple Format Support:
- YAML (
yaml-cpp) - JSON (
nlohmann::json) - Ordered JSON (
nlohmann::ordered_json) - TOML (
toml11- ordered & unordered) - ๐ Seamless Conversion between any supported formats
- ๐ Auto-format Detection based on file extensions
- ๐งฑ Extensible Architecture with adapter pattern
- ๐ ๏ธ Rich API including file I/O, text parsing/dumping, and conversion
๐ ๏ธ Installation
cd openFrameworks/addons
git clone https://github.com/nariakiiwatani/ofxConfigBridge.git---
๐ API Reference
Basic File Operations
#include "ofxConfigBridge.h"
using namespace ofx::configbridge;
// Load configuration files
auto yaml = loadFile<YAML::Node>("config.yaml");
auto json = loadFile<nlohmann::ordered_json>("config.json");
auto toml = loadFile<toml::ordered_value>("config.toml");
// Save configuration files
saveFile("output.yaml", yaml);
saveFile("output.json", json);
saveFile("output.toml", toml);Format Conversion
// Convert between any supported formats
auto yaml = loadFile<YAML::Node>("config.yaml");
auto json = convert<nlohmann::ordered_json>(yaml);
auto toml = convert<toml::ordered_value>(json);
// Chain conversions
auto result = convert<YAML::Node>(
convert<nlohmann::json>(
loadFile<toml::ordered_value>("config.toml")
)
);Text Processing
// Parse from string
std::string yamlText = "key: value\nlist: [1, 2, 3]";
YAML::Node parsed;
parseText(yamlText, parsed);
// Dump to string
std::string output;
dumpText(parsed, output);Supported Types
| Format | Type | Description |
|---|---|---|
| JSON | nlohmann::json | Standard unordered JSON |
| JSON | nlohmann::ordered_json | Order-preserving JSON |
| YAML | YAML::Node | YAML documents |
| TOML | toml::ordered_value | Order-preserving TOML |
| TOML | toml::value | Standard TOML |
๐ง Configuration Options
// Options are used for conversion and export operations
Options opt;
opt.float_precision = 6; // Control floating-point output precision
// Convert with options
auto json = convert<nlohmann::json>(yaml, opt);
// Export to text with options
std::string output;
dumpText(data, output, opt);
// Save file with options
saveFile("output.json", data, opt);---
๐ฆ Dependencies
This addon includes the following libraries:
- yaml-cpp (MIT) - YAML parsing and emission
- toml11 (MIT) - TOML parsing and serialization
- nlohmann/json (included with openFrameworks) - JSON processing
- openFrameworks 0.12.0+
๐ฏ Example Usage
See the complete working example in
example/src/ofApp.cpp:void ofApp::setup() {
using namespace ofx::configbridge;
// Load YAML and convert to other formats
auto yaml = loadFile<YAML::Node>("config.yaml");
auto json = convert<nlohmann::ordered_json>(yaml);
auto toml = convert<toml::ordered_value>(yaml);
// Save converted files
saveFile("yaml_to_json.json", json);
saveFile("yaml_to_toml.toml", toml);
// Cross-format conversions work seamlessly
auto backToYaml = convert<YAML::Node>(toml);
saveFile("full_circle.yaml", backToYaml);
}---
โ๏ธ License
This project is licensed under the MIT License. See
LICENSE for full text.Included Libraries:
- yaml-cpp (MIT, ยฉ 2008 Jesse Beder)
- toml11 (MIT, ยฉ 2017 ToruNiina)
ofxAddons