{"id":15551697,"url":"https://github.com/toruniina/tomlparser","last_synced_at":"2025-08-05T02:13:37.465Z","repository":{"id":94600322,"uuid":"65964225","full_name":"ToruNiina/TOMLParser","owner":"ToruNiina","description":"c++ header only TOML parser","archived":false,"fork":false,"pushed_at":"2018-06-01T04:04:41.000Z","size":118,"stargazers_count":10,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-23T19:25:39.816Z","etag":null,"topics":["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/ToruNiina.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,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-08-18T04:07:47.000Z","updated_at":"2025-02-22T15:22:17.000Z","dependencies_parsed_at":"2023-03-16T13:45:21.478Z","dependency_job_id":null,"html_url":"https://github.com/ToruNiina/TOMLParser","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ToruNiina%2FTOMLParser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ToruNiina%2FTOMLParser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ToruNiina%2FTOMLParser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ToruNiina%2FTOMLParser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ToruNiina","download_url":"https://codeload.github.com/ToruNiina/TOMLParser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250498407,"owners_count":21440461,"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":["toml","toml-parser"],"created_at":"2024-10-02T14:06:27.160Z","updated_at":"2025-04-23T19:25:41.065Z","avatar_url":"https://github.com/ToruNiina.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"TOMLParser\n====\n\n[![Build Status](https://travis-ci.org/ToruNiina/TOMLParser.svg?branch=travis)](https://travis-ci.org/ToruNiina/TOMLParser)\n[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE)\n\nC++ header-only TOML Parser.\n\n__NOTE__: New c++11 toml library named [toml11](https://github.com/ToruNiina/toml11) is ready. If you can use c++11, use it.\n__NOTE__: New c++(98|11|14|17) toml library with Boost named [Boost.toml](https://github.com/ToruNiina/Boost.toml) is ready. If you can use Boost C++ Library, use it.\n\n__TOMLParser__ supports [TOML v0.4.0](http://github.com/toml-lang/toml/blob/master/README.md).\n\nIf you can use c++11 features, this parser depends only on the STL.\nIf not so, it depends on the Boost C++ library.\n\nTo use this parser with c++98 \u0026 boost, it is better that download the boost library\nfrom the official site.\n\n[日本語版README](README_ja.md)\n\n## Usage\n\nBecause this is header-only library, you can use __TOMLParser__ without build.\n\nYou can easily see how to use it if you read the following sample codes.\n\nTo parse a TOML-file, use the `toml::Data toml::parse(std::basic_istream\u003ccharT\u003e\u0026)` function.\n\n```cpp\nstd::ifstream ifs(\"sample.toml\");\ntoml::Data data = toml::parse(ifs);\n```\n\nYou can get a TOML-value using the `T toml::get\u003cT\u003e` function.\n\n```toml\n# toml file\ntitle = \"title\"\n```\n\n```cpp\nstd::string title = toml::get\u003ctoml::String\u003e(data.at(\"title\")); // \"title\"\n```\n\nYou can also use the `T toml::get\u003cT\u003e` function for an array.\n\n```toml\n# toml file\narray = [3, 3.1, 3.14, 3.141, 3.1415]\n```\n\n```cpp\n// {3, 3.1, 3.14, 3.141, 3.1415}\nstd::vector\u003cdouble\u003e array = toml::get\u003ctoml::Array\u003ctoml::Float\u003e\u003e(data.at(\"array\"));\n```\n\nIf you have a TOML-file like the following,\n\n```toml\n# sample.toml\ntitle = \"this is sample\"\n\n[table]\nnumber = +100_000\nreals  = [-1.1e+2, 2.0, 3.0]\nnested_array = [[true, false], # this is a comment.\n                [true],\n                [false]]\ndate = 1979-05-27\ninline_table = {name = \"inline table\"}\narray_of_inline_table = [\n    {key = \"array\"},\n    {key = \"of\"},\n    {key = \"inline\"},\n    {key = \"table\"},\n    ]\n\n[[array_of_table]]\nfoobar = 1\n[[array_of_table]]\nfoobar = 2\n[[array_of_table]]\nfoobar = 3\n```\n\nyou can read and parse it using the c++11 code described below.\n\n```cpp\n#include \"toml.hpp\"\n#include \u003cfstream\u003e\n\nint main()\n{\n    std::ifstream file(\"sample.toml\");\n    if(not file.good()) return 1;\n\n    toml::Data data = toml::parse(file);\n    std::string title = toml::get\u003ctoml::String\u003e(data.at(\"title\"));\n    toml::Table table = toml::get\u003ctoml::Table\u003e(data.at(\"table\"));\n    std::int_least64_t number = toml::get\u003ctoml::Integer\u003e(table.at(\"number\");\n    std::vector\u003cdouble\u003e reals =\n        toml::get\u003ctoml::Array\u003ctoml::Float\u003e\u003e(table.at(\"reals\"));\n    std::vector\u003cstd::vector\u003cbool\u003e\u003e nested_array =\n        toml::get\u003ctoml::Array\u003ctoml::Array\u003ctoml::Boolean\u003e\u003e\u003e(table.at(\"nested_array\"));\n    std::chrono::system_clock::time_point date =\n        toml::get\u003ctoml::Datetime\u003e(table.at(\"date\"));\n    toml::Table inline_table = toml::get\u003ctoml::Table\u003e(table.at(\"inline_table\"));\n    std::string name = toml::get\u003ctoml::String\u003e(inline_table.at(\"name\"));\n\n    std::vector\u003ctoml::Table\u003e array_of_inline_table = \n        toml::get\u003ctoml::Array\u003ctoml::Table\u003e\u003e(table.at(\"array_of_inline_table\"));\n    std::string key0 = toml::get\u003ctoml::String\u003e(array_of_inline_table.at(0).at(\"key\"));\n    std::string key1 = toml::get\u003ctoml::String\u003e(array_of_inline_table.at(1).at(\"key\"));\n    std::string key2 = toml::get\u003ctoml::String\u003e(array_of_inline_table.at(2).at(\"key\"));\n    std::string key3 = toml::get\u003ctoml::String\u003e(array_of_inline_table.at(3).at(\"key\"));\n\n    std::vector\u003ctoml::Table\u003e array_of_table = \n        toml::get\u003ctoml::Array\u003ctoml::Table\u003e\u003e(table.at(\"array_of_table\"));\n    std::int_least64_t foobar0 = toml::get\u003ctoml::Integer\u003e(array_of_table.at(0).at(\"foobar\"));\n    std::int_least64_t foobar1 = toml::get\u003ctoml::Integer\u003e(array_of_table.at(1).at(\"foobar\"));\n    std::int_least64_t foobar2 = toml::get\u003ctoml::Integer\u003e(array_of_table.at(2).at(\"foobar\"));\n\n    return 0;\n}\n```\n\nEven though the function `toml::get\u003cT\u003e` is useful,\nyou cannot use it straightforwardly for a value like this.\n\n```toml\narray_of_array = [[1.0, 2.0, 3.0], [\"a\", \"b\", \"c\"]]\n```\n\nIn this case, `toml::ValueBase` will help you.\n\n```cpp\nstd::vector\u003ctoml::ValueBase\u003e array_of_array =\n    toml::get\u003ctoml::Array\u003ctoml::ValueBase\u003e\u003e(data.at(\"array_of_array\"));\nstd::vector\u003cdouble\u003e first_array =\n    toml::get\u003ctoml::Array\u003ctoml::Float\u003e\u003e(array_of_array.at(0));\nstd::vector\u003cstd::string\u003e second_array =\n    toml::get\u003ctoml::Array\u003ctoml::String\u003e\u003e(array_of_array.at(1));\n```\n\nIn C++98, some of the types and methods are different.\nFor more detail, see Documentation.\n\n## Documentation\n\nIn this parser, all the TOML types are the subclass of `toml::value_base`.\nActually, `toml::ValueBase` is just a `typedef` of `toml::shared_ptr\u003ctoml::value_base\u003e`.\n\nAll the supported TOML types are listed below.\n\n| TOML type | type names in this parser | actual type in c++11                   |\n|:----------|:--------------------------|:---------------------------------------|\n| Boolean   | `toml::Boolean`           | `bool`                                 |\n| Integer   | `toml::Integer`           | `std::int_least64_t`                   |\n| Float     | `toml::Float`             | `double`                               |\n| String    | `toml::String`            | `std::string`                          |\n| Datetime  | `toml::Datetime`          | `std::chrono::system_clock::time_point`|\n| Array     | `toml::Array\u003ctypename T\u003e` | `std::vector\u003cT\u003e`                       |\n| Table     | `toml::Table`             | `std::map\u003cstd::string, std::shared_ptr\u003ctoml::value_base\u003e\u003e` |\n\nAlso, `toml::Data` is just a typedef of `toml::Table`.\n\nIn C++98, `toml::Array\u003cT\u003e` become a struct that is a `type generator`\nbecause there are no `template using alias`.\nAnd there are no `at` method in `std::map`,\nso you should use `operator[]` to access the values.\n\nAdditionally, there are no `std::chrono`, `std::int_least64_t`\nand `std::shared_ptr`, so `boost::chrono`, `boost::int_least64_t`\nand `boost::shared_ptr` are used instead.\n\n| TOML type | type names in this parser | actual type in c++98                     |\n|:----------|:--------------------------|:-----------------------------------------|\n| Boolean   | `toml::Boolean`           | `bool`                                   |\n| Integer   | `toml::Integer`           | `boost::int_least64_t`                   |\n| Float     | `toml::Float`             | `double`                                 |\n| String    | `toml::String`            | `std::string`                            |\n| Datetime  | `toml::Datetime`          | `boost::chrono::system_clock::time_point`|\n| Array     | `toml::Array\u003ctypename T\u003e::type` | `std::vector\u003cT\u003e`                   |\n| Table     | `toml::Table`             | `std::map\u003cstd::string, boost::shared_ptr\u003ctoml::value_base\u003e\u003e` |\n\nSo, the different part of the sample code in C++98 is below.\n\n```cpp\n\nboost::int_least64_t number = toml::get\u003ctoml::Integer\u003e(table.at(\"number\");\nboost::chrono::system_clock::time_point date =\n    toml::get\u003ctoml::Datetime\u003e(table.at(\"date\"));\n\nstd::vector\u003cdouble\u003e reals =\n    toml::get\u003ctoml::Array\u003ctoml::Float\u003e::type\u003e(table.at(\"reals\"));\n\n//  If you do not want to write \"::type\", you can use std::vector instead of toml::Array.\n//  std::vector\u003cdouble\u003e reals =\n//      toml::get\u003cstd::vector\u003ctoml::Float\u003e\u003e(table.at(\"reals\"));\n```\n\n__Note__: When you install boost using apt or some other package manager\nthat provides binaries already built, some source files possibly does not exist.\nIf you fail to build your own project that includes this parser using boost and c++98\nwith an error message like \"boost/../libs/something not found\", please download\nboost library from the official site.\nThe reason of this problem is you and this parser are forcing to use\n```boost/chrono``` as header-only.\n\n### Excpetions\n\nIf the syntax is invalid or some sort of an internal error occurs,\nexception ```toml::syntax_error``` or ```toml::internal_error``` is thrown by\nthe function ```toml::parse```, respectively.\n\nIf an invalid type is set as a template parameter of the ```toml::get\u003cT\u003e``` function, \nexception ```toml::type_error``` is thrown.\n\nAll the exception classes are the subclass of ```toml::exception``` which is\nthe subclass of ```std::exception```.\n\n## Testing\n\nUsing Boost Unit Test Framework and CMake CTest.\n\n```\n$ mkdir build\n$ cd build\n$ cmake ..\n$ make \n$ make test\n```\n\n## Licensing terms\n\nThis project is licensed under the terms of the MIT License.\nSee LICENSE for the project license.\n\n- Copyright (c) 2016 Toru Niina\n\nAll rights reserved.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoruniina%2Ftomlparser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftoruniina%2Ftomlparser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoruniina%2Ftomlparser/lists"}