Code Monkey home page Code Monkey logo

simpleconfig's Introduction

SimpleConfig

SimpleConfig is a lightweight C++ library for easy configuration management. It provides a simple API for loading, parsing, and manipulating configuration files. Designed for efficiency and minimal dependencies, it's perfect for projects needing straightforward config handling.

Features

  • Path Management: Automatically determines and manages the configuration path within the user's AppData directory.
  • Config Listing: Lists all configuration files in the specified directory.
  • Load Configurations: Loads configuration data from a specified file.
  • Save Configurations: Saves current configuration data to a specified file.
  • Add Configurations: Adds a new configuration file by name.
  • Remove Configurations: Removes a specified configuration file.
  • Rename Configurations: Renames an existing configuration file.
  • Reset Configurations: Resets the configuration data to default values.

Usage

Including the Library

#include "config.h"

Usage

c_config configManager;

// Run the config manager and set the config directory name. A good place for this would be your processes main.
// Maybe in your dllmain or int main.
configManager.run("MyAppConfigs");

// Set a variable.
int test = configManager.feature.testInt;

ImGUI Example

ImGui::SetNextWindowPos(ImVec2(300, 300), ImGuiCond_FirstUseEver);
ImGui::Begin("Config", &configWindow);

constexpr auto& config_items = config.get_configs();
static auto current_config = -1;

if ((size_t)(current_config) >= config_items.size())
  current_config = -1;

static char buffer[32];

ImGui::Text("Configs");

if (ImGui::ListBox("config_list", &current_config, [](void* data, int idx, const char** out_text)
{
    auto& vector = *(std::vector<std::string> *)(data);
    *out_text = vector[idx].c_str();
    return true;
}, &config_items, (int)(config_items.size()), 5) && current_config != -1) strcpy_s(buffer, config_items[current_config].c_str());

if (ImGui::InputText("config_name", buffer, IM_ARRAYSIZE(buffer), ImGuiInputTextFlags_EnterReturnsTrue))
{
  if (current_config != -1)
    config.rename(current_config, buffer);
}

if (ImGui::Button("Create", ImVec2(60, 25)))
  config.add(buffer);

ImGui::SameLine();

if (ImGui::Button("Reset", ImVec2(60, 25)))
  config.reset();

ImGui::SameLine();

if (current_config > -1)
{
  if (ImGui::Button("Save", ImVec2(60, 25)))
    config.save(current_config);

  ImGui::SameLine();

  if (ImGui::Button("Load", ImVec2(60, 25)))
    config.load(current_config);

  ImGui::SameLine();

  if (ImGui::Button("Delete", ImVec2(60, 25)))
    config.remove(current_config);
}

License

SimpleConfig is released under the MIT License. See the LICENSE file for more details.

simpleconfig's People

Contributors

smellon69 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.