← Back

ofxConfigBridge

github.com/nariakiiwatani/ofxConfigBridge · @nariakiiwatani
OF 0.12 Utilities

openFrameworks addon for converting config files type-by-type

1 0 Last commit 1y ago Created 1y ago

README

ofxConfigBridge



License: MIT openFrameworks C++

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



---

๐Ÿ› ๏ธ 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



FormatTypeDescription
JSONnlohmann::jsonStandard unordered JSON
JSONnlohmann::ordered_jsonOrder-preserving JSON
YAMLYAML::NodeYAML documents
TOMLtoml::ordered_valueOrder-preserving TOML
TOMLtoml::valueStandard 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:

---

๐ŸŽฏ 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:

Get this addon

HTTPS
SSH