{"id":13493413,"url":"https://github.com/cktan/tomlcpp","last_synced_at":"2025-12-24T10:48:15.219Z","repository":{"id":42022212,"uuid":"309016048","full_name":"cktan/tomlcpp","owner":"cktan","description":"No fanfare TOML C++ Library","archived":false,"fork":false,"pushed_at":"2023-04-20T00:58:33.000Z","size":73,"stargazers_count":52,"open_issues_count":2,"forks_count":11,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-10-31T07:34:19.327Z","etag":null,"topics":["c-plus-plus","c-plus-plus-14","c-plus-plus-17","toml","toml-parser"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cktan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-11-01T03:27:40.000Z","updated_at":"2024-09-26T14:01:00.000Z","dependencies_parsed_at":"2024-01-16T09:46:03.492Z","dependency_job_id":"82833026-ab02-4311-91c7-d2d03c7a7f3c","html_url":"https://github.com/cktan/tomlcpp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cktan%2Ftomlcpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cktan%2Ftomlcpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cktan%2Ftomlcpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cktan%2Ftomlcpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cktan","download_url":"https://codeload.github.com/cktan/tomlcpp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246021414,"owners_count":20710933,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-plus-plus","c-plus-plus-14","c-plus-plus-17","toml","toml-parser"],"created_at":"2024-07-31T19:01:14.972Z","updated_at":"2025-12-24T10:48:15.172Z","avatar_url":"https://github.com/cktan.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"# tomlcpp\nTOML in C++; v1.0 compliant.\n\nThis is a C++ wrapper around the C library available here: https://github.com/cktan/tomlc99.\n\n* Compatible with [TOML v1.0.0](https://toml.io/en/v1.0.0).\n* Tested with multiple test suites, including\n[BurntSushi/toml-test](https://github.com/BurntSushi/toml-test) and\n[iarna/toml-spec-tests](https://github.com/iarna/toml-spec-tests).\n* Does not throw C++ exceptions.\n* Provides very simple and intuitive interface.\n\n\n## Usage\n\nHere is a simple example that parses this config file:\n\n```\n[server]\n\thost = \"example.com\"\n\tport = [ 8080, 8181, 8282 ]\n```\n\nSteps for getting values:\n\n1. Call toml::parseFile on a toml file\n2. Get the top-level table\n3. Get values from the top-level table\n4. Examine the values\n\n```c++\n#include \u003cutility\u003e\n#include \u003cstring\u003e\n#include \u003cvector\u003e\n#include \u003cmemory\u003e\n#include \u003ciostream\u003e\n#include \"tomlcpp.hpp\"\n\nusing std::cerr;\nusing std::cout;\n\nvoid error(std::string msg)\n{\n    cerr \u003c\u003c \"ERROR: \" \u003c\u003c msg \u003c\u003c \"\\n\";\n    exit(1);\n}\n\nint main()\n{\n    // 1. parse file\n    auto res = toml::parseFile(\"sample.toml\");\n    if (!res.table) {\n        error(\"cannot parse file: \" + res.errmsg);\n    }\n\n    // 2. get top level table\n    auto server = res.table-\u003egetTable(\"server\");\n    if (!server) {\n        error(\"missing [server]\");\n    }\n\n    // 3. extract values from the top level table\n    auto [ ok, host ] = server-\u003egetString(\"host\");\n    if (!ok) {\n        fatal(\"missing or bad host entry\");\n    }\n\n    auto portArray = server-\u003egetArray(\"port\");\n    if (!portArray) {\n        fatal(\"missing 'port' array\");\n    }\n\n    // 4. examine the values\n    cout \u003c\u003c \"host: \" \u003c\u003c host \u003c\u003c \"\\n\";\n    cout \u003c\u003c \"port: \";\n    for (int i = 0; ; i++) {\n        auto p = portArray-\u003egetInt(i);\n        if (!p.first) break;\n\n        cout \u003c\u003c p.second \u003c\u003c \" \";\n    }\n    cout \u003c\u003c \"\\n\";\n\n    return 0;\n}\n```\n\n### Parsing\n\nTo parse a toml text or file, invoke `toml::parse(text)` or `toml::parseFile(path)`.\nThe return value is a `Result` struct. On success, the `Result.table` will have a non-NULL\npointer to the toml table content. Otherwise, the `Result.table` will be NULL, and `Result.errmsg`\nstores a string describing the error.\n\n### Traversing table\n\nToml tables are key-value maps.\n\n#### Keys\n\nThe method `Table::keys()` returns a vector of keys.\n\n#### Content\n\nTo extract values in a Table, call the `Table::getXXXX(key)` methods and supply the key:\n\n```\nTable::getString(key)\nTable::getBool(key)\nTable::getInt(key)\nTable::getDouble(key)\nTable::getTimestamp(key)\n```\n\nThese methods return a C++ `pair`, in which `pair.first` is a success indicator, and `pair.second` is the result value.\n\nTo access table or array in a Table, use these methods which return a `unique_ptr` to a Table or Array:\n\n```\nTable::getTable(key)\nTable::getArray(key)\n```\n\n### Traversing array\n\nSimilarly, to extract the primitive content of a toml::Array, call one of these methods:\n\n```\nArray::getString(idx)\nArray::getBool(idx)\nArray::getInt(idx)\nArray::getDouble(idx)\nArray::getTimestamp(idx)\nArray::getArray(idx)\nArray::getTable(idx)\n```\n\n\n## Building and installing\n\nA normal *make* suffices. You can also simply include the\n`toml.c`, `toml.h`, `tomlcpp.cpp`, `tomlcpp.hpp` files in your project.\n\nInvoking `make install` will install the header and library files into\n/usr/local/{include,lib}.\n\nAlternatively, specify `make install prefix=/a/file/path` to install into\n/a/file/path/{include,lib}.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcktan%2Ftomlcpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcktan%2Ftomlcpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcktan%2Ftomlcpp/lists"}