mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-12-16 03:08:52 +08:00
feat: change some unreleased features as ext
some features introduced in toml-lang v1.1.0 have been postponed.
so those features are renamed as library extensions (`v_1_1_0` -> `ext_`).
those will not be removed because they may be introduced in the future
release of toml-lang. bd1bae2b51
This commit is contained in:
295
docs/changelog/index.html
Normal file
295
docs/changelog/index.html
Normal file
@@ -0,0 +1,295 @@
|
||||
<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
|
||||
Change Log
|
||||
#
|
||||
|
||||
|
||||
v4.4.0
|
||||
#
|
||||
|
||||
|
||||
Added
|
||||
#
|
||||
|
||||
|
||||
Add toml::find_or_default() (#280) (by Ken Matsui @ken-matsui)
|
||||
Add erase to ordered_map (#282) (#283) (by Sunlight @SunPodder)
|
||||
Add bool basic_value::accessed() const to detect whether the value has been accessed
|
||||
|
||||
enabled only if TOML11_ENABLE_ACCESS_CHECK is defined
|
||||
|
||||
|
||||
Add compare operators to toml::spec
|
||||
|
||||
|
||||
Fixed
|
||||
#
|
||||
|
||||
|
||||
Use is_void<T> instead of is_same<T, void> (#281) (by Ken Matsui @ken-matsui)
|
||||
|
||||
|
||||
Changed
|
||||
#
|
||||
|
||||
|
||||
Improve toml::parse performance by 2x
|
||||
Stop using deprecated Ubuntu 20 image on GitHub Actions
|
||||
|
||||
|
||||
v4.3.0
|
||||
#
|
||||
|
||||
|
||||
Added
|
||||
#
|
||||
|
||||
|
||||
Support std::optional as a template argument of toml::find
|
||||
Support multiple arguments toml::visit(visitor, args...)
|
||||
|
||||
|
||||
Fixed
|
||||
#
|
||||
|
||||
|
||||
toml::detail::region::last_ may be used uninitialized (#267) (#268) (by amatej @kontura)
|
||||
Fix use with CMake 3.21 and older (#271) (by Severin Leonhardt @SeverinLeonhardt)
|
||||
fix: prevent size_t-max length string allocation (#275) (#276) (by @hayt)
|
||||
update README.md (#277) (by somebody @oldoldtea) (by lz)
|
||||
Make parsing faster for very long line (#278)
|
||||
Avoid known problem in MSVC (#279)
|
||||
Check if source_location::file_name() is null before formatting
|
||||
|
||||
|
||||
Changed
|
||||
#
|
||||
|
||||
|
||||
Update hugo-book theme
|
||||
Add MSVC 2017 to appveyor build
|
||||
|
||||
|
||||
v4.2.0
|
||||
#
|
||||
|
||||
|
||||
Added
|
||||
#
|
||||
|
||||
|
||||
Support std::optional members for TOML11_DEFINE_CONVERSION_NON_INTRUSIVE (by Ken Matsui)
|
||||
Make thread_local for color_mode optional (by Ken Matsui)
|
||||
add usage with CPM to README
|
||||
add explanation about ordered_map to README and update doc
|
||||
|
||||
|
||||
Fixed
|
||||
#
|
||||
|
||||
|
||||
Manually cast file size to std::streamsize (by Pino Toscano)
|
||||
Typographical error in table_format output
|
||||
Format an empty array specified as array-of-table in one line
|
||||
Added a missing include file
|
||||
Fix typos in documentation template syntax (by Jack W)
|
||||
Fix toml::find_or for deeply nested tables
|
||||
|
||||
|
||||
v4.1.0
|
||||
#
|
||||
|
||||
|
||||
Added
|
||||
#
|
||||
|
||||
|
||||
support std::get<std::u8string>
|
||||
support toml::value(std::u8string)
|
||||
support string_type = std::u8string
|
||||
support operator<<(std::ostream&, toml::value)
|
||||
add bool uppercase to toml::integer_format
|
||||
support template into_toml() (by 萧迩珀)
|
||||
|
||||
|
||||
Fixed
|
||||
#
|
||||
|
||||
|
||||
Fix not checking for \r\n when parsing line comments (by Andreas Keller)
|
||||
|
||||
|
||||
Changed
|
||||
#
|
||||
|
||||
|
||||
speedup CI tests by multicore build
|
||||
|
||||
|
||||
v4.0.3
|
||||
#
|
||||
|
||||
|
||||
Fixed
|
||||
#
|
||||
|
||||
|
||||
remove default template argument from forward declaration in toml_fwd.hpp
|
||||
enable to call toml::make_error_info with multiple toml::values
|
||||
enable to copy/move toml::result having std::reference_wrapper
|
||||
fix document generation error with the latest version of hugo
|
||||
fix several tiny errors that causes warning
|
||||
fix CMake compatibility warning
|
||||
|
||||
|
||||
Changed
|
||||
#
|
||||
|
||||
add -Werror / /WX to build script
|
||||
set MSVC warning level to /W4
|
||||
add explanation of features to README"><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/changelog/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="changelog"><meta property="og:description" content="Change Log # v4.4.0 # Added # Add toml::find_or_default() (#280) (by Ken Matsui @ken-matsui) Add erase to ordered_map (#282) (#283) (by Sunlight @SunPodder) Add bool basic_value::accessed() const to detect whether the value has been accessed enabled only if TOML11_ENABLE_ACCESS_CHECK is defined Add compare operators to toml::spec Fixed # Use is_void<T> instead of is_same<T, void> (#281) (by Ken Matsui @ken-matsui) Changed # Improve toml::parse performance by 2x Stop using deprecated Ubuntu 20 image on GitHub Actions v4.3.0 # Added # Support std::optional as a template argument of toml::find Support multiple arguments toml::visit(visitor, args...) Fixed # toml::detail::region::last_ may be used uninitialized (#267) (#268) (by amatej @kontura) Fix use with CMake 3.21 and older (#271) (by Severin Leonhardt @SeverinLeonhardt) fix: prevent size_t-max length string allocation (#275) (#276) (by @hayt) update README.md (#277) (by somebody @oldoldtea) (by lz) Make parsing faster for very long line (#278) Avoid known problem in MSVC (#279) Check if source_location::file_name() is null before formatting Changed # Update hugo-book theme Add MSVC 2017 to appveyor build v4.2.0 # Added # Support std::optional members for TOML11_DEFINE_CONVERSION_NON_INTRUSIVE (by Ken Matsui) Make thread_local for color_mode optional (by Ken Matsui) add usage with CPM to README add explanation about ordered_map to README and update doc Fixed # Manually cast file size to std::streamsize (by Pino Toscano) Typographical error in table_format output Format an empty array specified as array-of-table in one line Added a missing include file Fix typos in documentation template syntax (by Jack W) Fix toml::find_or for deeply nested tables v4.1.0 # Added # support std::get<std::u8string> support toml::value(std::u8string) support string_type = std::u8string support operator<<(std::ostream&, toml::value) add bool uppercase to toml::integer_format support template into_toml() (by 萧迩珀) Fixed # Fix not checking for \r\n when parsing line comments (by Andreas Keller) Changed # speedup CI tests by multicore build v4.0.3 # Fixed # remove default template argument from forward declaration in toml_fwd.hpp enable to call toml::make_error_info with multiple toml::values enable to copy/move toml::result having std::reference_wrapper fix document generation error with the latest version of hugo fix several tiny errors that causes warning fix CMake compatibility warning Changed # add -Werror / /WX to build script set MSVC warning level to /W4 add explanation of features to README"><meta property="og:locale" content="en"><meta property="og:type" content="website"><title>changelog | toml11</title><link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/changelog/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/changelog/ title=changelog><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" crossorigin=anonymous></script><link rel=alternate type=application/rss+xml href=https://toruniina.github.io/toml11/docs/changelog/index.xml title=toml11></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
|
||||
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
|
||||
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
|
||||
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/changelog/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle>
|
||||
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle>
|
||||
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/ class=active>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
|
||||
</label><strong>changelog</strong>
|
||||
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#change-log>Change Log</a></li><li><a href=#v440>v4.4.0</a><ul><li><a href=#added>Added</a></li><li><a href=#fixed>Fixed</a></li><li><a href=#changed>Changed</a></li></ul></li><li><a href=#v430>v4.3.0</a><ul><li><a href=#added-1>Added</a></li><li><a href=#fixed-1>Fixed</a></li><li><a href=#changed-1>Changed</a></li></ul></li><li><a href=#v420>v4.2.0</a><ul><li><a href=#added-2>Added</a></li><li><a href=#fixed-2>Fixed</a></li></ul></li><li><a href=#v410>v4.1.0</a><ul><li><a href=#added-3>Added</a></li><li><a href=#fixed-3>Fixed</a></li><li><a href=#changed-2>Changed</a></li></ul></li><li><a href=#v403>v4.0.3</a><ul><li><a href=#fixed-4>Fixed</a></li><li><a href=#changed-3>Changed</a></li></ul></li><li><a href=#v402>v4.0.2</a><ul><li><a href=#fixed-5>Fixed</a></li><li><a href=#changed-4>Changed</a></li></ul></li><li><a href=#v401>v4.0.1</a><ul><li><a href=#fixed-6>Fixed</a></li><li><a href=#added-4>Added</a></li></ul></li><li><a href=#changes-from-v3-to-v4>Changes from v3 to v4</a><ul><li><a href=#breaking-changes>Breaking Changes</a><ul><li><a href=#changed-template-parameters-of-tomlbasic_value>Changed <code>template</code> Parameters of <code>toml::basic_value</code></a></li><li><a href=#removed-stdinitializer_list-support-for-tomlbasic_value>Removed <code>std::initializer_list</code> Support for <code>toml::basic_value</code></a></li><li><a href=#renamed-tomlbasic_valueis_uninitialized-to-is_empty>Renamed <code>toml::basic_value::is_uninitialized()</code> to <code>is_empty()</code></a></li><li><a href=#added-format-information-and-removed-tomlstring>Added Format Information and Removed <code>toml::string</code></a></li><li><a href=#changed-arguments-of-tomlformat>Changed Arguments of <code>toml::format</code></a></li><li><a href=#changed-member-functions-of-tomlsource_location>Changed Member Functions of <code>toml::source_location</code></a></li><li><a href=#renamed-tomlformat_underline-to-tomlformat_location>Renamed <code>toml::format_underline</code> to <code>toml::format_location</code></a></li></ul></li><li><a href=#changed-arguments-of-tomlformat_error>Changed Arguments of <code>toml::format_error</code></a><ul><li><a href=#changed-control-of-tomlcolor>Changed Control of <code>toml::color</code></a></li></ul></li><li><a href=#non-breaking-changes>Non-Breaking Changes</a><ul><li><a href=#added-parse_str>Added <code>parse_str</code></a></li><li><a href=#added-try_parse>Added <code>try_parse</code></a></li><li><a href=#support-for-parsing-byte-sequences>Support for Parsing Byte Sequences</a></li><li><a href=#added-tomlspec>Added <code>toml::spec</code></a></li><li><a href=#added-format-information>Added Format Information</a></li><li><a href=#changed-to-preserve_comments-by-default>Changed to <code>preserve_comments</code> by Default</a></li><li><a href=#changed-to-preserve-comments-by-default>Changed to Preserve Comments by Default</a></li><li><a href=#added-single_includetomlhpp>Added <code>single_include/toml.hpp</code></a></li><li><a href=#option-to-use-precompiled-library>Option to Use Precompiled Library</a></li><li><a href=#reference-documentation>Reference Documentation</a></li></ul></li></ul></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=change-log>Change Log
|
||||
<a class=anchor href=#change-log>#</a></h1><h1 id=v440>v4.4.0
|
||||
<a class=anchor href=#v440>#</a></h1><h2 id=added>Added
|
||||
<a class=anchor href=#added>#</a></h2><ul><li>Add <code>toml::find_or_default()</code> (#280) (by Ken Matsui @ken-matsui)</li><li>Add <code>erase</code> to <code>ordered_map</code> (#282) (#283) (by Sunlight @SunPodder)</li><li>Add <code>bool basic_value::accessed() const</code> to detect whether the value has been accessed<ul><li>enabled only if <code>TOML11_ENABLE_ACCESS_CHECK</code> is defined</li></ul></li><li>Add compare operators to <code>toml::spec</code></li></ul><h2 id=fixed>Fixed
|
||||
<a class=anchor href=#fixed>#</a></h2><ul><li>Use <code>is_void<T></code> instead of <code>is_same<T, void></code> (#281) (by Ken Matsui @ken-matsui)</li></ul><h2 id=changed>Changed
|
||||
<a class=anchor href=#changed>#</a></h2><ul><li>Improve <code>toml::parse</code> performance by 2x</li><li>Stop using deprecated Ubuntu 20 image on GitHub Actions</li></ul><h1 id=v430>v4.3.0
|
||||
<a class=anchor href=#v430>#</a></h1><h2 id=added-1>Added
|
||||
<a class=anchor href=#added-1>#</a></h2><ul><li>Support <code>std::optional</code> as a template argument of <code>toml::find</code></li><li>Support multiple arguments <code>toml::visit(visitor, args...)</code></li></ul><h2 id=fixed-1>Fixed
|
||||
<a class=anchor href=#fixed-1>#</a></h2><ul><li><code>toml::detail::region::last_</code> may be used uninitialized (#267) (#268) (by amatej @kontura)</li><li>Fix use with CMake 3.21 and older (#271) (by Severin Leonhardt @SeverinLeonhardt)</li><li>fix: prevent size_t-max length string allocation (#275) (#276) (by @hayt)</li><li>update README.md (#277) (by somebody @oldoldtea) (by lz)</li><li>Make parsing faster for very long line (#278)</li><li>Avoid known problem in MSVC (#279)</li><li>Check if <code>source_location::file_name()</code> is null before formatting</li></ul><h2 id=changed-1>Changed
|
||||
<a class=anchor href=#changed-1>#</a></h2><ul><li>Update hugo-book theme</li><li>Add MSVC 2017 to appveyor build</li></ul><h1 id=v420>v4.2.0
|
||||
<a class=anchor href=#v420>#</a></h1><h2 id=added-2>Added
|
||||
<a class=anchor href=#added-2>#</a></h2><ul><li>Support <code>std::optional</code> members for <code>TOML11_DEFINE_CONVERSION_NON_INTRUSIVE</code> (by Ken Matsui)</li><li>Make <code>thread_local</code> for <code>color_mode</code> optional (by Ken Matsui)</li><li>add usage with CPM to README</li><li>add explanation about <code>ordered_map</code> to README and update doc</li></ul><h2 id=fixed-2>Fixed
|
||||
<a class=anchor href=#fixed-2>#</a></h2><ul><li>Manually cast file size to <code>std::streamsize</code> (by Pino Toscano)</li><li>Typographical error in <code>table_format</code> output</li><li>Format an empty array specified as array-of-table in one line</li><li>Added a missing include file</li><li>Fix typos in documentation template syntax (by Jack W)</li><li>Fix <code>toml::find_or</code> for deeply nested tables</li></ul><h1 id=v410>v4.1.0
|
||||
<a class=anchor href=#v410>#</a></h1><h2 id=added-3>Added
|
||||
<a class=anchor href=#added-3>#</a></h2><ul><li>support <code>std::get<std::u8string></code></li><li>support <code>toml::value(std::u8string)</code></li><li>support <code>string_type = std::u8string</code></li><li>support <code>operator<<(std::ostream&, toml::value)</code></li><li>add <code>bool uppercase</code> to <code>toml::integer_format</code></li><li>support <code>template into_toml()</code> (by 萧迩珀)</li></ul><h2 id=fixed-3>Fixed
|
||||
<a class=anchor href=#fixed-3>#</a></h2><ul><li>Fix not checking for <code>\r\n</code> when parsing line comments (by Andreas Keller)</li></ul><h2 id=changed-2>Changed
|
||||
<a class=anchor href=#changed-2>#</a></h2><ul><li>speedup CI tests by multicore build</li></ul><h1 id=v403>v4.0.3
|
||||
<a class=anchor href=#v403>#</a></h1><h2 id=fixed-4>Fixed
|
||||
<a class=anchor href=#fixed-4>#</a></h2><ul><li>remove default template argument from forward declaration in <code>toml_fwd.hpp</code></li><li>enable to call <code>toml::make_error_info</code> with multiple <code>toml::value</code>s</li><li>enable to copy/move <code>toml::result</code> having <code>std::reference_wrapper</code></li><li>fix document generation error with the latest version of hugo</li><li>fix several tiny errors that causes warning</li><li>fix CMake compatibility warning</li></ul><h2 id=changed-3>Changed
|
||||
<a class=anchor href=#changed-3>#</a></h2><p>add <code>-Werror</code> / <code>/WX</code> to build script
|
||||
set MSVC warning level to <code>/W4</code>
|
||||
add explanation of features to README</p><h1 id=v402>v4.0.2
|
||||
<a class=anchor href=#v402>#</a></h1><h2 id=fixed-5>Fixed
|
||||
<a class=anchor href=#fixed-5>#</a></h2><ul><li>check return value of fread in <code>parse(FILE*)</code></li><li>version macro defined in <code>toml11/version.hpp</code></li><li>update docs about compilation</li><li>update docs about file open mode</li></ul><h2 id=changed-4>Changed
|
||||
<a class=anchor href=#changed-4>#</a></h2><ul><li>use version macros defined in <code>toml11/version.hpp</code> as the project version in <code>CMakeLists.txt</code></li></ul><h1 id=v401>v4.0.1
|
||||
<a class=anchor href=#v401>#</a></h1><h2 id=fixed-6>Fixed
|
||||
<a class=anchor href=#fixed-6>#</a></h2><ul><li>Resolved naming conflict of <code>sematic_version::{major, minor}</code> with macros defined in <code><sys/sysmacro.h></code></li><li>Fixed the definition of <code>operator<<</code> in <code>discard_comments</code> (by Egor Pugin)</li><li>Fixed the issue where the first blank line was not output in <code>format_location</code></li><li>Fixed the issue where error messages pointing to <code>source_location</code> referring to lines containing only newline characters were displayed in two lines</li><li>Corrected links in the README</li><li>Corrected the title of the README in <code>example/unicode</code></li></ul><h2 id=added-4>Added
|
||||
<a class=anchor href=#added-4>#</a></h2><ul><li>Configured CI to automatically update <code>single_include/toml.hpp</code> when changes are made to <code>main</code></li></ul><h1 id=changes-from-v3-to-v4>Changes from v3 to v4
|
||||
<a class=anchor href=#changes-from-v3-to-v4>#</a></h1><h2 id=breaking-changes>Breaking Changes
|
||||
<a class=anchor href=#breaking-changes>#</a></h2><h3 id=changed-template-parameters-of-tomlbasic_value>Changed <code>template</code> Parameters of <code>toml::basic_value</code>
|
||||
<a class=anchor href=#changed-template-parameters-of-tomlbasic_value>#</a></h3><p>In toml11 v3, <code>toml::basic_value</code> took separate template arguments for the comment container, table-type container, and array-type container.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> Comment,
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> ...<span style=color:#f92672>></span> <span style=color:#66d9ef>class</span> <span style=color:#a6e22e>Table</span> <span style=color:#f92672>=</span> std<span style=color:#f92672>::</span>unordered_map,
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> ...<span style=color:#f92672>></span> <span style=color:#66d9ef>class</span> <span style=color:#a6e22e>Array</span> <span style=color:#f92672>=</span> std<span style=color:#f92672>::</span>vector<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>class</span> <span style=color:#a6e22e>basic_value</span>;
|
||||
</span></span></code></pre></div><p>However, this approach does not accommodate changes to types such as <code>integer_type</code>.</p><p>In toml11 v4, <code>toml::basic_value</code> now accepts a single <code>TypeConfig</code>, allowing for more types to be customized.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TypeConfig<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>class</span> <span style=color:#a6e22e>basic_value</span>;
|
||||
</span></span></code></pre></div><p>By default, the types stored in <code>toml::value</code> remain unchanged.</p><p>For more information on changing types, please refer to the
|
||||
<a href=https://toruniina.github.io/toml11/docs/reference/types/><code>type_config</code></a> documentation.</p><h3 id=removed-stdinitializer_list-support-for-tomlbasic_value>Removed <code>std::initializer_list</code> Support for <code>toml::basic_value</code>
|
||||
<a class=anchor href=#removed-stdinitializer_list-support-for-tomlbasic_value>#</a></h3><p>In toml11 v3, there was an overload for <code>toml::value</code> that accepted <code>std::initializer_list</code>. This allowed for more intuitive initialization of <code>toml::value</code> with arrays and tables.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>// toml11 v3
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>toml<span style=color:#f92672>::</span>value v{<span style=color:#ae81ff>1</span>,<span style=color:#ae81ff>2</span>,<span style=color:#ae81ff>3</span>,<span style=color:#ae81ff>4</span>,<span style=color:#ae81ff>5</span>};
|
||||
</span></span><span style=display:flex><span>toml<span style=color:#f92672>::</span>value v{ {<span style=color:#e6db74>"a"</span>, <span style=color:#ae81ff>42</span>}, {<span style=color:#e6db74>"b"</span>, <span style=color:#e6db74>"foo"</span>} };
|
||||
</span></span></code></pre></div><p>However, this caused the following issues:</p><p>First, it was impossible to distinguish between a single-element array and a regular value, as it always became an array.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>// toml11 v3
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>toml<span style=color:#f92672>::</span>value v{<span style=color:#ae81ff>1</span>}; <span style=color:#75715e>// Becomes [1,] instead of 1
|
||||
</span></span></span></code></pre></div><p>With the widespread use of uniform initialization, this became very inconvenient.</p><p>Second, it was unclear whether the value represented a table with all string values or a nested array.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>// toml11 v3
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>toml<span style=color:#f92672>::</span>value v{ {<span style=color:#e6db74>"a"</span>, <span style=color:#e6db74>"foo"</span>}, {<span style=color:#e6db74>"b"</span>, <span style=color:#e6db74>"bar"</span>} };
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e>// Could be either:
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e>// {a = "foo", b = "bar"}
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e>// [["a", "foo"], ["b", "bar"]]
|
||||
</span></span></span></code></pre></div><p>These issues were difficult to resolve due to language specifications.</p><p>To avoid confusion, toml11 v4 has removed <code>std::initializer_list</code> support.</p><p>When initializing <code>toml::value</code> with an array, you must explicitly specify <code>toml::array</code>, and when initializing with a table, you must explicitly specify <code>toml::table</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>// toml11 v4
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>toml<span style=color:#f92672>::</span>value v(toml<span style=color:#f92672>::</span>array{<span style=color:#ae81ff>1</span>,<span style=color:#ae81ff>2</span>,<span style=color:#ae81ff>3</span>,<span style=color:#ae81ff>4</span>,<span style=color:#ae81ff>5</span>});
|
||||
</span></span><span style=display:flex><span>toml<span style=color:#f92672>::</span>value v(toml<span style=color:#f92672>::</span>table{ {<span style=color:#e6db74>"a"</span>, <span style=color:#ae81ff>42</span>}, {<span style=color:#e6db74>"b"</span>, <span style=color:#e6db74>"foo"</span>} });
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span>toml<span style=color:#f92672>::</span>value v{toml<span style=color:#f92672>::</span>array{<span style=color:#ae81ff>1</span>}}; <span style=color:#75715e>// [1,]
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>toml<span style=color:#f92672>::</span>value v{<span style=color:#ae81ff>1</span>} <span style=color:#75715e>// 1
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span>toml<span style=color:#f92672>::</span>value v{toml<span style=color:#f92672>::</span>table{{<span style=color:#e6db74>"a"</span>, <span style=color:#e6db74>"foo"</span>}, {<span style=color:#e6db74>"b"</span>, <span style=color:#e6db74>"bar"</span>}}};
|
||||
</span></span><span style=display:flex><span>toml<span style=color:#f92672>::</span>value v{toml<span style=color:#f92672>::</span>array{toml<span style=color:#f92672>::</span>array{<span style=color:#e6db74>"a"</span>, <span style=color:#e6db74>"foo"</span>}, toml<span style=color:#f92672>::</span>array{<span style=color:#e6db74>"b"</span>, <span style=color:#e6db74>"bar"</span>}}};
|
||||
</span></span></code></pre></div><p>While this makes initializing <code>toml::value</code> with tables or arrays slightly less convenient, it ensures that the values will not become unpredictable by requiring explicit type information.</p><h3 id=renamed-tomlbasic_valueis_uninitialized-to-is_empty>Renamed <code>toml::basic_value::is_uninitialized()</code> to <code>is_empty()</code>
|
||||
<a class=anchor href=#renamed-tomlbasic_valueis_uninitialized-to-is_empty>#</a></h3><p>In toml11 v3, the function to check whether a <code>basic_value</code> was uninitialized was called <code>is_uninitialized</code>.</p><p>However, in toml11 v4, the library supports <code>null</code> values as an extension, allowing for the intentional construction of empty values.
|
||||
Therefore, the function has been renamed to <code>is_empty</code> to reflect this change.</p><h3 id=added-format-information-and-removed-tomlstring>Added Format Information and Removed <code>toml::string</code>
|
||||
<a class=anchor href=#added-format-information-and-removed-tomlstring>#</a></h3><p>In toml11 v3, to retain information on whether a string was <code>basic</code> or <code>literal</code>, the library used a thin wrapper around <code>std::string</code> called <code>toml::string</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>// toml11 v3
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>enum</span> <span style=color:#66d9ef>class</span> <span style=color:#a6e22e>string_t</span> <span style=color:#f92672>:</span> std<span style=color:#f92672>::</span><span style=color:#66d9ef>uint8_t</span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> basic <span style=color:#f92672>=</span> <span style=color:#ae81ff>0</span>,
|
||||
</span></span><span style=display:flex><span> literal <span style=color:#f92672>=</span> <span style=color:#ae81ff>1</span>,
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>string</span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> string_t kind;
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string str;
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span><span style=display:flex><span>} <span style=color:#75715e>// namespace toml
|
||||
</span></span></span></code></pre></div><p>In toml11 v4, to accommodate more format information such as the numeric base or whether arrays should be multiline, every type now has an associated <code>xxx_format</code> type, which is stored alongside the value.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>// toml11 v4
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span><span style=color:#66d9ef>enum</span> <span style=color:#66d9ef>class</span> <span style=color:#a6e22e>string_format</span> <span style=color:#f92672>:</span> std<span style=color:#f92672>::</span><span style=color:#66d9ef>uint8_t</span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> basic <span style=color:#f92672>=</span> <span style=color:#ae81ff>0</span>,
|
||||
</span></span><span style=display:flex><span> literal <span style=color:#f92672>=</span> <span style=color:#ae81ff>1</span>,
|
||||
</span></span><span style=display:flex><span> multiline_basic <span style=color:#f92672>=</span> <span style=color:#ae81ff>2</span>,
|
||||
</span></span><span style=display:flex><span> multiline_literal <span style=color:#f92672>=</span> <span style=color:#ae81ff>3</span>
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>string_format_info</span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> string_format fmt <span style=color:#f92672>=</span> string_format<span style=color:#f92672>::</span>basic;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>bool</span> start_with_newline <span style=color:#f92672>=</span> false;
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span></code></pre></div><p>This change allows for more detailed format information to be preserved, ensuring that format specifics for numeric types, arrays, and tables are maintained even after parsing.</p><h3 id=changed-arguments-of-tomlformat>Changed Arguments of <code>toml::format</code>
|
||||
<a class=anchor href=#changed-arguments-of-tomlformat>#</a></h3><p>In toml11 v3, <code>toml::format</code> accepted values such as the precision and width of numeric types.</p><p>However, this approach did not allow for detailed formatting specifications, resulting in serialized files that did not match expectations.</p><p>In toml11 v4, each <code>toml::value</code> now carries its own format information, enabling more detailed formatting options to be preserved within the <code>toml::value</code> itself.</p><p>As a result, <code>toml::format</code> no longer accepts specific formatting values. Instead, it now only takes a <code>toml::spec</code>, which includes language feature flags used during formatting.</p><h3 id=changed-member-functions-of-tomlsource_location>Changed Member Functions of <code>toml::source_location</code>
|
||||
<a class=anchor href=#changed-member-functions-of-tomlsource_location>#</a></h3><p>In toml11 v3, the member types of <code>toml::source_location</code> were designed to handle only single lines.</p><p>In toml11 v4, the member types of <code>toml::source_location</code> are designed to handle multiple lines.</p><h3 id=renamed-tomlformat_underline-to-tomlformat_location>Renamed <code>toml::format_underline</code> to <code>toml::format_location</code>
|
||||
<a class=anchor href=#renamed-tomlformat_underline-to-tomlformat_location>#</a></h3><p>In toml11 v3, the function used to format location information from <code>toml::source_location</code> was called <code>toml::format_underline</code>.</p><p>To make the name clearer, it has been renamed to <code>toml::format_location</code>.</p><h2 id=changed-arguments-of-tomlformat_error>Changed Arguments of <code>toml::format_error</code>
|
||||
<a class=anchor href=#changed-arguments-of-tomlformat_error>#</a></h2><p>In toml11 v3, there was no class to represent error information, resulting in complex arguments for <code>toml::format_error</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> C, <span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> ...<span style=color:#f92672>></span> <span style=color:#66d9ef>class</span> <span style=color:#a6e22e>T</span>, <span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> ...<span style=color:#f92672>></span> <span style=color:#66d9ef>class</span> <span style=color:#a6e22e>A</span><span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>string format_error(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> err_msg,
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>C, T, A<span style=color:#f92672>>&</span> v, <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> comment,
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> hints <span style=color:#f92672>=</span> {},
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>bool</span> colorize <span style=color:#f92672>=</span> TOML11_ERROR_MESSAGE_COLORIZED);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> C, <span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> ...<span style=color:#f92672>></span> <span style=color:#66d9ef>class</span> <span style=color:#a6e22e>T</span>, <span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> ...<span style=color:#f92672>></span> <span style=color:#66d9ef>class</span> <span style=color:#a6e22e>A</span><span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>inline</span> std<span style=color:#f92672>::</span>string format_error(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> err_msg,
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>basic_value<span style=color:#f92672><</span>C, T, A<span style=color:#f92672>>&</span> v1, <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> comment1,
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>basic_value<span style=color:#f92672><</span>C, T, A<span style=color:#f92672>>&</span> v2, <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> comment2,
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> hints <span style=color:#f92672>=</span> {},
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>bool</span> colorize <span style=color:#f92672>=</span> TOML11_ERROR_MESSAGE_COLORIZED);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> C, <span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> ...<span style=color:#f92672>></span> <span style=color:#66d9ef>class</span> <span style=color:#a6e22e>T</span>, <span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> ...<span style=color:#f92672>></span> <span style=color:#66d9ef>class</span> <span style=color:#a6e22e>A</span><span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>inline</span> std<span style=color:#f92672>::</span>string format_error(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> err_msg,
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>basic_value<span style=color:#f92672><</span>C, T, A<span style=color:#f92672>>&</span> v1, <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> comment1,
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>basic_value<span style=color:#f92672><</span>C, T, A<span style=color:#f92672>>&</span> v2, <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> comment2,
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>basic_value<span style=color:#f92672><</span>C, T, A<span style=color:#f92672>>&</span> v3, <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> comment3,
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> hints <span style=color:#f92672>=</span> {},
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>bool</span> colorize <span style=color:#f92672>=</span> TOML11_ERROR_MESSAGE_COLORIZED);
|
||||
</span></span></code></pre></div><p>In toml11 v4, we have introduced <code>class error_info</code> and <code>make_error_info</code>, simplifying the arguments for <code>format_error</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>std<span style=color:#f92672>::</span>string format_error(<span style=color:#66d9ef>const</span> error_info<span style=color:#f92672>&</span> err);
|
||||
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>string format_error(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> errkind, <span style=color:#66d9ef>const</span> error_info<span style=color:#f92672>&</span> err);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> ... Ts<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>string format_error(std<span style=color:#f92672>::</span>string title,
|
||||
</span></span><span style=display:flex><span> source_location loc, std<span style=color:#f92672>::</span>string msg, Ts<span style=color:#f92672>&&</span> ... tail);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC, <span style=color:#66d9ef>typename</span> ... Ts<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>string format_error(std<span style=color:#f92672>::</span>string title,
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v, std<span style=color:#f92672>::</span>string msg, Ts<span style=color:#f92672>&&</span> ... tail);
|
||||
</span></span></code></pre></div><h3 id=changed-control-of-tomlcolor>Changed Control of <code>toml::color</code>
|
||||
<a class=anchor href=#changed-control-of-tomlcolor>#</a></h3><p>In toml11 v3, to control whether to colorize the output, we used the manipulator <code>toml::colorize</code> in conjunction with <code>toml::color::enable/disable</code>.</p><p>The manipulator allowed us to decide whether to apply color to each stream,
|
||||
but in v4, the frequency of using streams has decreased,
|
||||
and issues such as the fact that <code>std::ios_base::xalloc</code> used internally is not thread-safe in C++11 have arisen.
|
||||
Therefore, we have decided to use only <code>toml::color::enable/disable</code> and have removed <code>toml::colorize</code>.</p><h2 id=non-breaking-changes>Non-Breaking Changes
|
||||
<a class=anchor href=#non-breaking-changes>#</a></h2><h3 id=added-parse_str>Added <code>parse_str</code>
|
||||
<a class=anchor href=#added-parse_str>#</a></h3><p>In toml11 v3, there was no function to directly parse a string itself.
|
||||
Therefore, when parsing a string, it was necessary to use <code>std::istringstream</code>.</p><p>To address this inconvenience, we have added <code>toml::parse_str</code>, allowing for direct parsing of strings.</p><h3 id=added-try_parse>Added <code>try_parse</code>
|
||||
<a class=anchor href=#added-try_parse>#</a></h3><p>In toml11 v3, when a parser encountered an error, it threw <code>toml::syntax_error</code>.</p><p>However, there are cases where you do not want to throw exceptions due to environments where exceptions cannot be thrown, or for reasons of performance.</p><p>In toml11 v4, we have implemented <code>toml::try_parse</code> using <code>toml::result</code>, which communicates parsing failures without throwing exceptions.</p><p>This doesn’t mean exceptions are never thrown. Errors in the standard library being used, such as <code>std::bad_alloc</code> due to allocation failure from memory exhaustion, may still be thrown.</p><h3 id=support-for-parsing-byte-sequences>Support for Parsing Byte Sequences
|
||||
<a class=anchor href=#support-for-parsing-byte-sequences>#</a></h3><p>To allow for parsing TOML content obtained through means other than files, we have added <code>toml::parse</code> and <code>toml::try_parse</code> functions that accept <code>std::vector<unsigned char></code>.</p><h3 id=added-tomlspec>Added <code>toml::spec</code>
|
||||
<a class=anchor href=#added-tomlspec>#</a></h3><p>In toml11 v3, all new features of the TOML language were incorporated, and features that were decided to be introduced in future versions of the TOML language were controlled by the macro <code>TOML11_USE_UNRELEASED_TOML_FEATURES</code>.</p><p>This was because, at the time of developing toml11 v3, the TOML language had not yet reached version 1.0.0, being at versions 0.4.0 to 0.5.0.</p><p>As not all users are familiar with the latest TOML language specification, displaying error messages based on an older language usage could confuse the entire community. Therefore, until reaching version 1.0.0, it was necessary to provide new language specifications as quickly as possible and encourage users to update.</p><p>However, the current TOML language specification is at version 1.0.0. Therefore, there was a need to be mindful of the choice to continue using version 1.0.0 even after TOML v1.1.0 was released.</p><p>To allow for more flexibility in selecting the TOML language specification, we introduced <code>toml::spec</code>, enabling the TOML language version to be changed at runtime.</p><p>Additionally, in <code>toml::spec</code>, flags are set for each language feature, allowing for the testing of specific language features only.</p><p>This mechanism is also used for TOML-specific language extensions in toml11 v4.</p><h3 id=added-format-information>Added Format Information
|
||||
<a class=anchor href=#added-format-information>#</a></h3><p>In toml11 v3, format information was not saved except for strings, and during serialization, only width and precision were considered.</p><p>However, this resulted in hexadecimal integers being serialized as decimal integers and no reliable way to ensure inline tables.</p><p>In toml11 v4, format information (<code>integer_format</code>, etc.) has been added to all TOML types, and it is now considered during parsing and serialization.</p><p>This allows for more detailed format information to be set for values, such as hexadecimal integers or inline tables.</p><h3 id=changed-to-preserve_comments-by-default>Changed to <code>preserve_comments</code> by Default
|
||||
<a class=anchor href=#changed-to-preserve_comments-by-default>#</a></h3><p>In toml11 v3, comments were not parsed by default and were also not serialized.</p><p>This was because comments were a later introduced feature and were being read through a special hack.</p><p>In toml11 v4, comments are parsed, preserved, and serialized by default.</p><p>Furthermore, the parser implementation has been significantly changed to ensure comments are parsed alongside other elements.</p><h3 id=changed-to-preserve-comments-by-default>Changed to Preserve Comments by Default
|
||||
<a class=anchor href=#changed-to-preserve-comments-by-default>#</a></h3><p>In toml11 v3, comments were neither parsed nor serialized by default. This was because comment support was a late addition, implemented through a special hack.</p><p>In toml11 v4, comments are now parsed, preserved, and serialized by default. The parser implementation has also been significantly revised so that comments are parsed just like any other element.</p><h3 id=added-single_includetomlhpp>Added <code>single_include/toml.hpp</code>
|
||||
<a class=anchor href=#added-single_includetomlhpp>#</a></h3><p>toml11 is a versatile library with different header files for various features to enhance development efficiency. However, this required a certain amount of effort to install.</p><p>Starting with toml11 v4, a <code>single_include/toml.hpp</code> file has been added, which combines all the header files in the correct order. This allows the library to be installed by simply copying a single file.</p><h3 id=option-to-use-precompiled-library>Option to Use Precompiled Library
|
||||
<a class=anchor href=#option-to-use-precompiled-library>#</a></h3><p>Due to the extensive use of templates in toml11, compile times have been long.</p><p>In toml11 v4, the number of precompilable functions has been increased, allowing them to be compiled ahead of time into a library. This is expected to reduce compile times when using the library in large-scale development projects.</p><h3 id=reference-documentation>Reference Documentation
|
||||
<a class=anchor href=#reference-documentation>#</a></h3><p>Previously, all features were documented in the README, with no detailed function definitions or reference materials available in Japanese.</p><p>In toml11 v4, reference documentation has been included, provided in both Japanese and English. However, since the library author is a native Japanese speaker, the Japanese content is considered primary. If there are discrepancies between the Japanese and English content, the Japanese version takes precedence.</p></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#change-log>Change Log</a></li><li><a href=#v440>v4.4.0</a><ul><li><a href=#added>Added</a></li><li><a href=#fixed>Fixed</a></li><li><a href=#changed>Changed</a></li></ul></li><li><a href=#v430>v4.3.0</a><ul><li><a href=#added-1>Added</a></li><li><a href=#fixed-1>Fixed</a></li><li><a href=#changed-1>Changed</a></li></ul></li><li><a href=#v420>v4.2.0</a><ul><li><a href=#added-2>Added</a></li><li><a href=#fixed-2>Fixed</a></li></ul></li><li><a href=#v410>v4.1.0</a><ul><li><a href=#added-3>Added</a></li><li><a href=#fixed-3>Fixed</a></li><li><a href=#changed-2>Changed</a></li></ul></li><li><a href=#v403>v4.0.3</a><ul><li><a href=#fixed-4>Fixed</a></li><li><a href=#changed-3>Changed</a></li></ul></li><li><a href=#v402>v4.0.2</a><ul><li><a href=#fixed-5>Fixed</a></li><li><a href=#changed-4>Changed</a></li></ul></li><li><a href=#v401>v4.0.1</a><ul><li><a href=#fixed-6>Fixed</a></li><li><a href=#added-4>Added</a></li></ul></li><li><a href=#changes-from-v3-to-v4>Changes from v3 to v4</a><ul><li><a href=#breaking-changes>Breaking Changes</a><ul><li><a href=#changed-template-parameters-of-tomlbasic_value>Changed <code>template</code> Parameters of <code>toml::basic_value</code></a></li><li><a href=#removed-stdinitializer_list-support-for-tomlbasic_value>Removed <code>std::initializer_list</code> Support for <code>toml::basic_value</code></a></li><li><a href=#renamed-tomlbasic_valueis_uninitialized-to-is_empty>Renamed <code>toml::basic_value::is_uninitialized()</code> to <code>is_empty()</code></a></li><li><a href=#added-format-information-and-removed-tomlstring>Added Format Information and Removed <code>toml::string</code></a></li><li><a href=#changed-arguments-of-tomlformat>Changed Arguments of <code>toml::format</code></a></li><li><a href=#changed-member-functions-of-tomlsource_location>Changed Member Functions of <code>toml::source_location</code></a></li><li><a href=#renamed-tomlformat_underline-to-tomlformat_location>Renamed <code>toml::format_underline</code> to <code>toml::format_location</code></a></li></ul></li><li><a href=#changed-arguments-of-tomlformat_error>Changed Arguments of <code>toml::format_error</code></a><ul><li><a href=#changed-control-of-tomlcolor>Changed Control of <code>toml::color</code></a></li></ul></li><li><a href=#non-breaking-changes>Non-Breaking Changes</a><ul><li><a href=#added-parse_str>Added <code>parse_str</code></a></li><li><a href=#added-try_parse>Added <code>try_parse</code></a></li><li><a href=#support-for-parsing-byte-sequences>Support for Parsing Byte Sequences</a></li><li><a href=#added-tomlspec>Added <code>toml::spec</code></a></li><li><a href=#added-format-information>Added Format Information</a></li><li><a href=#changed-to-preserve_comments-by-default>Changed to <code>preserve_comments</code> by Default</a></li><li><a href=#changed-to-preserve-comments-by-default>Changed to Preserve Comments by Default</a></li><li><a href=#added-single_includetomlhpp>Added <code>single_include/toml.hpp</code></a></li><li><a href=#option-to-use-precompiled-library>Option to Use Precompiled Library</a></li><li><a href=#reference-documentation>Reference Documentation</a></li></ul></li></ul></li></ul></nav></div></aside></main></body></html>
|
||||
1
docs/changelog/index.xml
Normal file
1
docs/changelog/index.xml
Normal file
@@ -0,0 +1 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>changelog on toml11</title><link>https://toruniina.github.io/toml11/docs/changelog/</link><description>Recent content in changelog on toml11</description><generator>Hugo</generator><language>en</language><atom:link href="https://toruniina.github.io/toml11/docs/changelog/index.xml" rel="self" type="application/rss+xml"/></channel></rss>
|
||||
145
docs/features/configure_types/index.html
Normal file
145
docs/features/configure_types/index.html
Normal file
@@ -0,0 +1,145 @@
|
||||
<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
|
||||
Customizing Types
|
||||
#
|
||||
|
||||
The toml::value class uses std::int64_t for integer_type and std::unordered_map<key_type, value_type> for table_type.
|
||||
However, in some cases, you may want to use boost::multiprecision::int128_t or std::map.
|
||||
To accommodate this, toml::value is implemented with template parameters that allow you to change the stored types.
|
||||
Just as std::string is actually an alias for std::basic_string<char, std::char_traits<char>, std::allocator<char>>, toml::value is an alias for toml::basic_value<toml::type_config>.
|
||||
Here, we will explain the types contained in toml::type_config and how to define a different config type."><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/features/configure_types/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="configuring types"><meta property="og:description" content="Customizing Types # The toml::value class uses std::int64_t for integer_type and std::unordered_map<key_type, value_type> for table_type.
|
||||
However, in some cases, you may want to use boost::multiprecision::int128_t or std::map.
|
||||
To accommodate this, toml::value is implemented with template parameters that allow you to change the stored types.
|
||||
Just as std::string is actually an alias for std::basic_string<char, std::char_traits<char>, std::allocator<char>>, toml::value is an alias for toml::basic_value<toml::type_config>.
|
||||
Here, we will explain the types contained in toml::type_config and how to define a different config type."><meta property="og:locale" content="en"><meta property="og:type" content="article"><meta property="article:section" content="docs"><title>configuring types | toml11</title><link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/features/configure_types/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/features/configure_types/ title="configuring types"><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" crossorigin=anonymous></script></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
|
||||
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
|
||||
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
|
||||
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/features/configure_types/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle checked>
|
||||
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/ class=active>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle>
|
||||
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
|
||||
</label><strong>configuring types</strong>
|
||||
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#customizing-types>Customizing Types</a><ul><li><a href=#type_config><code>type_config</code></a></li><li><a href=#preserving-order-of-values-in-tables>Preserving Order of Values in Tables</a></li><li><a href=#not-preserving-comments>Not Preserving Comments</a></li><li><a href=#using-containers-other-than-stdvector-for-arrays>Using Containers Other Than <code>std::vector</code> for Arrays</a></li><li><a href=#using-boostmultiprecision-for-numeric-types>Using <code>boost::multiprecision</code> for Numeric Types</a></li></ul></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=customizing-types>Customizing Types
|
||||
<a class=anchor href=#customizing-types>#</a></h1><p>The <code>toml::value</code> class uses <code>std::int64_t</code> for <code>integer_type</code> and <code>std::unordered_map<key_type, value_type></code> for <code>table_type</code>.</p><p>However, in some cases, you may want to use <code>boost::multiprecision::int128_t</code> or <code>std::map</code>.</p><p>To accommodate this, <code>toml::value</code> is implemented with template parameters that allow you to change the stored types.</p><p>Just as <code>std::string</code> is actually an alias for <code>std::basic_string<char, std::char_traits<char>, std::allocator<char>></code>, <code>toml::value</code> is an alias for <code>toml::basic_value<toml::type_config></code>.</p><p>Here, we will explain the types contained in <code>toml::type_config</code> and how to define a different <code>config</code> type.</p><h2 id=type_config><code>type_config</code>
|
||||
<a class=anchor href=#type_config>#</a></h2><p>The <code>type_config</code> class contains the following member types and <code>static</code> member functions:</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>type_config</span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> comment_type <span style=color:#f92672>=</span> preserve_comments;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> boolean_type <span style=color:#f92672>=</span> <span style=color:#66d9ef>bool</span>;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> integer_type <span style=color:#f92672>=</span> std<span style=color:#f92672>::</span><span style=color:#66d9ef>int64_t</span>;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> floating_type <span style=color:#f92672>=</span> <span style=color:#66d9ef>double</span>;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> string_type <span style=color:#f92672>=</span> std<span style=color:#f92672>::</span>string;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> array_type <span style=color:#f92672>=</span> std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>T<span style=color:#f92672>></span>;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> K, <span style=color:#66d9ef>typename</span> T<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> table_type <span style=color:#f92672>=</span> std<span style=color:#f92672>::</span>unordered_map<span style=color:#f92672><</span>K, T<span style=color:#f92672>></span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>static</span> result<span style=color:#f92672><</span>integer_type, error_info<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> parse_int(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> str, <span style=color:#66d9ef>const</span> source_location src, <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span><span style=color:#66d9ef>uint8_t</span> base);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>static</span> result<span style=color:#f92672><</span>floating_type, error_info<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> parse_float(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> str, <span style=color:#66d9ef>const</span> source_location src, <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>bool</span> is_hex);
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p><code>toml::basic_value<TypeConfig></code> defines the stored <code>boolean_type</code> as <code>TypeConfig::boolean_type</code>, the stored <code>integer_type</code> as <code>TypeConfig::integer_type</code>, and so on.</p><p>Additionally, <code>array_type</code> is defined as <code>TypeConfig::array_type<toml::basic_value<TypeConfig>></code> and <code>table_type</code> is defined as <code>TypeConfig::table_type<key_type, toml::basic_value<TypeConfig>></code>.</p><p>By passing a class that defines these member types and functions to <code>toml::basic_value</code>, you can customize the types used by that <code>toml::basic_value</code>.</p><p>The <code>parse_int</code> and <code>parse_float</code> functions provide parsing methods when custom numeric types are used. These functions receive strings with prefixes like <code>0x</code> and digit separators like <code>_</code> removed, such as <code>123456</code> or <code>DEADBEEF</code>. The <code>base</code> parameter will be one of <code>10</code>, <code>16</code>, <code>8</code>, or <code>2</code>. Implement these functions to parse your custom <code>integer_type</code> and <code>floating_type</code>.</p><p>As a default implementation, <code>toml::read_int</code> and <code>toml::read_float</code> are provided.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>static</span> result<span style=color:#f92672><</span>integer_type, error_info<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>parse_int(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> str, <span style=color:#66d9ef>const</span> source_location src, <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span><span style=color:#66d9ef>uint8_t</span> base)
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> toml<span style=color:#f92672>::</span>read_int<span style=color:#f92672><</span>integer_type<span style=color:#f92672>></span>(str, src, base);
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>static</span> result<span style=color:#f92672><</span>floating_type, error_info<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>parse_float(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> str, <span style=color:#66d9ef>const</span> source_location src, <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>bool</span> is_hex)
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> toml<span style=color:#f92672>::</span>read_float<span style=color:#f92672><</span>floating_type<span style=color:#f92672>></span>(str, src, is_hex);
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>The <code>read_int</code> function uses <code>istream</code> and employs <code>std::hex</code> and <code>std::oct</code> for hexadecimal and octal parsing, respectively. For binary parsing, it is implemented using multiplication and addition. If your type supports these operations, you can use <code>read_int</code> as-is.</p><p>The <code>read_float</code> function also uses <code>istream</code>. Hexadecimal floating-point numbers are only supported for <code>double</code> and <code>float</code> types. If <code>read_float</code> is called with any other type and <code>hexfloat</code> is used, it will always return a parse error. Therefore, if you need to use a floating-point type other than <code>double</code> or <code>float</code> with <code>hexfloat</code>, you will need to implement support for that. If <code>hexfloat</code> is not used, no additional implementation is necessary.</p><h2 id=preserving-order-of-values-in-tables>Preserving Order of Values in Tables
|
||||
<a class=anchor href=#preserving-order-of-values-in-tables>#</a></h2><p>In addition to the default <code>toml::type_config</code>, there is also <code>toml::ordered_type_config</code>. This changes the <code>table_type</code> to an <a href=https://toruniina.github.io/toml11/docs/reference/ordered_map/>ordered_map</a>.</p><p>Using this, <code>toml::ordered_value</code> is defined, along with aliases for its array and table types as <code>toml::ordered_array</code> and <code>toml::ordered_table</code>, respectively.</p><p>You can use <code>toml::ordered_value</code> by calling <code>toml::parse(...)</code> as <code>toml::parse<toml::ordered_type_config>(...)</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><toml.hpp></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> toml<span style=color:#f92672>::</span>ordered_value input <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>parse<span style=color:#f92672><</span>toml<span style=color:#f92672>::</span>ordered_type_config<span style=color:#f92672>></span>(<span style=color:#e6db74>"example.toml"</span>);
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>cout <span style=color:#f92672><<</span> toml<span style=color:#f92672>::</span>format(input) <span style=color:#f92672><<</span> std<span style=color:#f92672>::</span>endl;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><h2 id=not-preserving-comments>Not Preserving Comments
|
||||
<a class=anchor href=#not-preserving-comments>#</a></h2><p>The <code>type_config</code> defines a container for storing comments via <code>comment_type</code>.</p><p>If comments do not contain significant information and can be discarded during parsing, specify <code>toml::discard_comments</code> for <code>comment_type</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>wo_comment_config</span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> comment_type <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>discard_comments; <span style=color:#75715e>// XXX
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> boolean_type <span style=color:#f92672>=</span> <span style=color:#66d9ef>bool</span>;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> integer_type <span style=color:#f92672>=</span> std<span style=color:#f92672>::</span><span style=color:#66d9ef>int64_t</span>;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> floating_type <span style=color:#f92672>=</span> <span style=color:#66d9ef>double</span>;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> string_type <span style=color:#f92672>=</span> std<span style=color:#f92672>::</span>string;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> array_type <span style=color:#f92672>=</span> std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>T<span style=color:#f92672>></span>;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> K, <span style=color:#66d9ef>typename</span> T<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> table_type <span style=color:#f92672>=</span> std<span style=color:#f92672>::</span>unordered_map<span style=color:#f92672><</span>K, T<span style=color:#f92672>></span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>static</span> result<span style=color:#f92672><</span>integer_type, error_info<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> parse_int(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> str, <span style=color:#66d9ef>const</span> source_location src, <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span><span style=color:#66d9ef>uint8_t</span> base)
|
||||
</span></span><span style=display:flex><span> {
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> toml<span style=color:#f92672>::</span>read_int<span style=color:#f92672><</span>integer_type<span style=color:#f92672>></span>(str, src, base);
|
||||
</span></span><span style=display:flex><span> }
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>static</span> result<span style=color:#f92672><</span>floating_type, error_info<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> parse_float(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> str, <span style=color:#66d9ef>const</span> source_location src, <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>bool</span> is_hex)
|
||||
</span></span><span style=display:flex><span> {
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> toml<span style=color:#f92672>::</span>read_float<span style=color:#f92672><</span>floating_type<span style=color:#f92672>></span>(str, src, is_hex);
|
||||
</span></span><span style=display:flex><span> }
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span></code></pre></div><h2 id=using-containers-other-than-stdvector-for-arrays>Using Containers Other Than <code>std::vector</code> for Arrays
|
||||
<a class=anchor href=#using-containers-other-than-stdvector-for-arrays>#</a></h2><p>To use a container other than <code>vector</code> (e.g., <code>std::deque</code>) for implementing TOML arrays, modify <code>array_type</code> as follows.</p><p>Similarly, to use a container other than <code>unordered_map</code> (e.g., <code>std::map</code>) for table types, modify <code>table_type</code> as shown below.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>deque_map_config</span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> comment_type <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>preserve_comments;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> boolean_type <span style=color:#f92672>=</span> <span style=color:#66d9ef>bool</span>;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> integer_type <span style=color:#f92672>=</span> std<span style=color:#f92672>::</span><span style=color:#66d9ef>int64_t</span>;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> floating_type <span style=color:#f92672>=</span> <span style=color:#66d9ef>double</span>;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> string_type <span style=color:#f92672>=</span> std<span style=color:#f92672>::</span>string;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> array_type <span style=color:#f92672>=</span> std<span style=color:#f92672>::</span>deque<span style=color:#f92672><</span>T<span style=color:#f92672>></span>; <span style=color:#75715e>// XXX
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span> <span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> K, <span style=color:#66d9ef>typename</span> T<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> table_type <span style=color:#f92672>=</span> std<span style=color:#f92672>::</span>map<span style=color:#f92672><</span>K, T<span style=color:#f92672>></span>; <span style=color:#75715e>// XXX
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>static</span> result<span style=color:#f92672><</span>integer_type, error_info<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> parse_int(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> str, <span style=color:#66d9ef>const</span> source_location src, <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span><span style=color:#66d9ef>uint8_t</span> base)
|
||||
</span></span><span style=display:flex><span> {
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> toml<span style=color:#f92672>::</span>read_int<span style=color:#f92672><</span>integer_type<span style=color:#f92672>></span>(str, src, base);
|
||||
</span></span><span style=display:flex><span> }
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>static</span> result<span style=color:#f92672><</span>floating_type, error_info<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> parse_float(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> str, <span style=color:#66d9ef>const</span> source_location src, <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>bool</span> is_hex)
|
||||
</span></span><span style=display:flex><span> {
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> toml<span style=color:#f92672>::</span>read_float<span style=color:#f92672><</span>floating_type<span style=color:#f92672>></span>(str, src, is_hex);
|
||||
</span></span><span style=display:flex><span> }
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span></code></pre></div><h2 id=using-boostmultiprecision-for-numeric-types>Using <code>boost::multiprecision</code> for Numeric Types
|
||||
<a class=anchor href=#using-boostmultiprecision-for-numeric-types>#</a></h2><p>By using <code>boost::multiprecision::cpp_int</code> and <code>boost::multiprecision::cpp_bin_float_oct</code>, you can utilize a wider integer type and a more precise floating-point type.</p><p>These types implement stream operators, so you can use the default implementations of <code>read_int</code> and <code>read_float</code> without modification.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>large_num_config</span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> comment_type <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>preserve_comments;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> boolean_type <span style=color:#f92672>=</span> <span style=color:#66d9ef>bool</span>;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> integer_type <span style=color:#f92672>=</span> boost<span style=color:#f92672>::</span>multiprecision<span style=color:#f92672>::</span>cpp_int;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> floating_type <span style=color:#f92672>=</span> boost<span style=color:#f92672>::</span>multiprecision<span style=color:#f92672>::</span>cpp_bin_float_oct;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> string_type <span style=color:#f92672>=</span> std<span style=color:#f92672>::</span>string;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> array_type <span style=color:#f92672>=</span> std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>T<span style=color:#f92672>></span>;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> K, <span style=color:#66d9ef>typename</span> T<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> table_type <span style=color:#f92672>=</span> std<span style=color:#f92672>::</span>unordered_map<span style=color:#f92672><</span>K, T<span style=color:#f92672>></span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>static</span> toml<span style=color:#f92672>::</span>result<span style=color:#f92672><</span>integer_type, toml<span style=color:#f92672>::</span>error_info<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> parse_int(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> str, <span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>source_location src, <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span><span style=color:#66d9ef>uint8_t</span> base)
|
||||
</span></span><span style=display:flex><span> {
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> toml<span style=color:#f92672>::</span>read_int<span style=color:#f92672><</span>integer_type<span style=color:#f92672>></span>(str, src, base);
|
||||
</span></span><span style=display:flex><span> }
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>static</span> toml<span style=color:#f92672>::</span>result<span style=color:#f92672><</span>floating_type, toml<span style=color:#f92672>::</span>error_info<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> parse_float(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> str, <span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>source_location src, <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>bool</span> is_hex)
|
||||
</span></span><span style=display:flex><span> {
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> toml<span style=color:#f92672>::</span>read_float<span style=color:#f92672><</span>floating_type<span style=color:#f92672>></span>(str, src, is_hex);
|
||||
</span></span><span style=display:flex><span> }
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span></code></pre></div></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#customizing-types>Customizing Types</a><ul><li><a href=#type_config><code>type_config</code></a></li><li><a href=#preserving-order-of-values-in-tables>Preserving Order of Values in Tables</a></li><li><a href=#not-preserving-comments>Not Preserving Comments</a></li><li><a href=#using-containers-other-than-stdvector-for-arrays>Using Containers Other Than <code>std::vector</code> for Arrays</a></li><li><a href=#using-boostmultiprecision-for-numeric-types>Using <code>boost::multiprecision</code> for Numeric Types</a></li></ul></li></ul></nav></div></aside></main></body></html>
|
||||
123
docs/features/error_message/index.html
Normal file
123
docs/features/error_message/index.html
Normal file
@@ -0,0 +1,123 @@
|
||||
<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
|
||||
Outputting Error Messages
|
||||
#
|
||||
|
||||
toml11 provides error messages that include location information within the file when using functions like toml::parse, toml::get<T>/find<T>, and as_integer(), among others.
|
||||
For instance, if a syntax error in an integer is detected during parsing, an error message might look like this:
|
||||
[error] bad integer: `_` must be surrounded by digits
|
||||
--> internal string at line 64 in file main.cpp
|
||||
|
|
||||
1 | a = 123__456
|
||||
| ^-- invalid underscore
|
||||
Hint: valid : -42, 1_000, 1_2_3_4_5, 0xC0FFEE, 0b0010, 0o755
|
||||
Hint: invalid: _42, 1__000, 0123
|
||||
Or, if a type different from the one actually stored is requested:"><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/features/error_message/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="error message"><meta property="og:description" content="Outputting Error Messages # toml11 provides error messages that include location information within the file when using functions like toml::parse, toml::get<T>/find<T>, and as_integer(), among others.
|
||||
For instance, if a syntax error in an integer is detected during parsing, an error message might look like this:
|
||||
[error] bad integer: `_` must be surrounded by digits --> internal string at line 64 in file main.cpp | 1 | a = 123__456 | ^-- invalid underscore Hint: valid : -42, 1_000, 1_2_3_4_5, 0xC0FFEE, 0b0010, 0o755 Hint: invalid: _42, 1__000, 0123 Or, if a type different from the one actually stored is requested:"><meta property="og:locale" content="en"><meta property="og:type" content="article"><meta property="article:section" content="docs"><title>error message | toml11</title><link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/features/error_message/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/features/error_message/ title="error message"><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" crossorigin=anonymous></script></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
|
||||
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
|
||||
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
|
||||
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/features/error_message/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle checked>
|
||||
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/ class=active>error message</a></li><li><a href=/toml11/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle>
|
||||
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
|
||||
</label><strong>error message</strong>
|
||||
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#outputting-error-messages>Outputting Error Messages</a><ul><li><a href=#creating-error-messages-from-tomlvalue-location-information>Creating Error Messages from <code>toml::value</code> Location Information</a></li><li><a href=#adding-colors-to-strings>Adding Colors to Strings</a></li><li><a href=#changing-the-prefix-of-error-messages-from-error>Changing the Prefix of Error Messages from <code>[error]</code></a></li><li><a href=#creating-error-messages-referencing-multiple-tomlvalue>Creating Error Messages Referencing Multiple <code>toml::value</code></a></li></ul></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=outputting-error-messages>Outputting Error Messages
|
||||
<a class=anchor href=#outputting-error-messages>#</a></h1><p><code>toml11</code> provides error messages that include location information within the file when using functions like <code>toml::parse</code>, <code>toml::get<T>/find<T></code>, and <code>as_integer()</code>, among others.</p><p>For instance, if a syntax error in an integer is detected during parsing, an error message might look like this:</p><pre tabindex=0><code>[error] bad integer: `_` must be surrounded by digits
|
||||
--> internal string at line 64 in file main.cpp
|
||||
|
|
||||
1 | a = 123__456
|
||||
| ^-- invalid underscore
|
||||
Hint: valid : -42, 1_000, 1_2_3_4_5, 0xC0FFEE, 0b0010, 0o755
|
||||
Hint: invalid: _42, 1__000, 0123
|
||||
</code></pre><p>Or, if a type different from the one actually stored is requested:</p><pre tabindex=0><code>[error] toml::value::as_string(): bad_cast to string
|
||||
--> input.toml
|
||||
|
|
||||
1 | a = 123_456
|
||||
| ^^^^^^^-- the actual type is integer
|
||||
</code></pre><p><code>toml11</code> provides methods to create such error messages from <code>toml::value</code>.</p><p>By utilizing this feature, you can inform users not only about TOML syntax errors but also about application-specific errors. For example, if a negative number appears where only positive values are allowed, you can highlight the location within the TOML file to convey the error to the user.</p><h2 id=creating-error-messages-from-tomlvalue-location-information>Creating Error Messages from <code>toml::value</code> Location Information
|
||||
<a class=anchor href=#creating-error-messages-from-tomlvalue-location-information>#</a></h2><p><code>toml::value</code> retains information about the location where it was parsed.</p><p>This information is encapsulated in <code>toml::source_location</code> and can be retrieved using <code>toml::value::location()</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value<span style=color:#f92672>&</span> a <span style=color:#f92672>=</span> input.at(<span style=color:#e6db74>"a"</span>);
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>source_location src <span style=color:#f92672>=</span> a.location();
|
||||
</span></span></code></pre></div><p>When a file is parsed with <code>toml::parse</code>, the TOML filename and line numbers are stored.</p><p>If parsed with <code>toml::parse_str</code>, the TOML filename is not available, but instead, the filename and line number of the C++ source code that called <code>toml::parse_str</code> are stored as the TOML filename. The first example on this page was output from <code>toml::parse_str</code>. Note the filename part.</p><p>For details, see the <a href=https://toruniina.github.io/toml11/docs/reference/source_location/>reference</a>.</p><p>You can build error information by passing a <code>toml::source_location</code> or <code>toml::value</code> and the associated error message to <code>toml::make_error_info</code>. Passing this to <code>toml::format_error</code> formats the error message into a <code>std::string</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value<span style=color:#f92672>&</span> a <span style=color:#f92672>=</span> input.at(<span style=color:#e6db74>"a"</span>);
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>if</span>(a.as_integer() <span style=color:#f92672><</span> <span style=color:#ae81ff>0</span>)
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>error_info err <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>make_error_info(
|
||||
</span></span><span style=display:flex><span> <span style=color:#e6db74>"positive integer is required"</span>, <span style=color:#75715e>// Error title
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span> a, <span style=color:#e6db74>"but got negative value"</span> <span style=color:#75715e>// Message next to the value
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span> );
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>cerr <span style=color:#f92672><<</span> toml<span style=color:#f92672>::</span>format_error(err) <span style=color:#f92672><<</span> std<span style=color:#f92672>::</span>endl;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>This will output:</p><pre tabindex=0><code>[error] positive integer is required
|
||||
--> input.toml
|
||||
|
|
||||
1 | a = -123456
|
||||
| ^^^^^^^-- but got negative value
|
||||
</code></pre><p>You can also add a supplementary message at the end. This part is not indented.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value<span style=color:#f92672>&</span> a <span style=color:#f92672>=</span> input.at(<span style=color:#e6db74>"a"</span>);
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>if</span>(a.as_integer() <span style=color:#f92672><</span> <span style=color:#ae81ff>0</span>)
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>error_info err <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>make_error_info(
|
||||
</span></span><span style=display:flex><span> <span style=color:#e6db74>"positive integer is required"</span>, <span style=color:#75715e>// Error title
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span> a, <span style=color:#e6db74>"but got negative value"</span>, <span style=color:#75715e>// Message next to the value
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span> <span style=color:#e6db74>"Hint: `a` means length of the data"</span> <span style=color:#75715e>// Supplementary message
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span> );
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>cerr <span style=color:#f92672><<</span> toml<span style=color:#f92672>::</span>format_error(err) <span style=color:#f92672><<</span> std<span style=color:#f92672>::</span>endl;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>This will output:</p><pre tabindex=0><code>[error] positive integer is required
|
||||
--> input.toml
|
||||
|
|
||||
1 | a = -123456
|
||||
| ^^^^^^^-- but got negative value
|
||||
Hint: `a` means length of the data
|
||||
</code></pre><blockquote class="book-hint info"><p>The ability to output lines from the file using <code>toml::value</code> is because the parsed file is retained in memory as a string.</p><p>The parsed string is shared by <code>toml::value</code> via a <code>std::shared_ptr</code>. Copying it does not duplicate the entire file string. The file information is freed from memory when all <code>toml::value</code> instances constructed from parsing the file are destructed.</p><p>Therefore, when using this in an application, it is recommended to extract and store the required values during loading rather than directly storing <code>toml::value</code>.</p></blockquote><h2 id=adding-colors-to-strings>Adding Colors to Strings
|
||||
<a class=anchor href=#adding-colors-to-strings>#</a></h2><p>You can add color to error messages using ANSI escape codes.</p><p>If <code>TOML11_COLORIZE_ERROR_MESSAGE</code> is defined at compile time, the error messages output by toml11 will be colored by default.</p><p>If not, you can enable color for subsequent error messages by calling <code>toml::color::enable()</code>. Conversely, if you do not want colored output, for example, because the output is not to a console, call <code>toml::color::disable()</code>. You can check whether coloring is enabled at any point by calling <code>toml::color::should_color()</code>.</p><p>Additionally, while the error title, error message, and supplementary information are not colored by default, you can use manipulators from toml::color to add color to them.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>std<span style=color:#f92672>::</span>ostringstream oss;
|
||||
</span></span><span style=display:flex><span>oss <span style=color:#f92672><<</span> toml<span style=color:#f92672>::</span>color<span style=color:#f92672>::</span>red <span style=color:#f92672><<</span> <span style=color:#e6db74>"but got negative value"</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>error_info err <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>make_error_info(
|
||||
</span></span><span style=display:flex><span> <span style=color:#e6db74>"positive integer is required"</span>, <span style=color:#75715e>// Error title
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span> a, oss.str(), <span style=color:#75715e>// Message next to the value
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span> <span style=color:#e6db74>"Hint: `a` means length of the data"</span> <span style=color:#75715e>// Supplementary message
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span> );
|
||||
</span></span></code></pre></div><p>For more details, see the <a href=https://toruniina.github.io/toml11/docs/reference/color/>reference</a>.</p><h2 id=changing-the-prefix-of-error-messages-from-error>Changing the Prefix of Error Messages from <code>[error]</code>
|
||||
<a class=anchor href=#changing-the-prefix-of-error-messages-from-error>#</a></h2><p>There may be different types of errors, and the default <code>[error]</code> prefix might not always be appropriate.</p><p>With <code>toml::format_error</code>, you can provide a <code>std::string</code> before <code>toml::error_info</code> to replace the <code>[error]</code> prefix.</p><p>For example:</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value<span style=color:#f92672>&</span> a <span style=color:#f92672>=</span> input.at(<span style=color:#e6db74>"a"</span>);
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>if</span>(a.as_integer() <span style=color:#f92672><</span> <span style=color:#ae81ff>0</span>)
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>error_info err <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>make_error_info(
|
||||
</span></span><span style=display:flex><span> <span style=color:#e6db74>"positive integer is required"</span>, <span style=color:#75715e>// Error title
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span> a, <span style=color:#e6db74>"but got negative value"</span> <span style=color:#75715e>// Message next to the value
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span> );
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>ostringstream prefix;
|
||||
</span></span><span style=display:flex><span> prefix <span style=color:#f92672><<</span> toml<span style=color:#f92672>::</span>color<span style=color:#f92672>::</span>bold <span style=color:#f92672><<</span> toml<span style=color:#f92672>::</span>color<span style=color:#f92672>::</span>yellow <span style=color:#f92672><<</span> <span style=color:#e6db74>"[warn]"</span>;
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>cerr <span style=color:#f92672><<</span> toml<span style=color:#f92672>::</span>format_error(prefix.str(), err) <span style=color:#f92672><<</span> std<span style=color:#f92672>::</span>endl;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>else</span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> a.as_integer();
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>This will output a warning starting with <code>[warn]</code>.</p><p>Additionally, you can create error messages without the <code>[error]</code> prefix by directly passing the components of <code>error_info</code> to <code>toml::format_error</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value<span style=color:#f92672>&</span> a <span style=color:#f92672>=</span> input.at(<span style=color:#e6db74>"a"</span>);
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>if</span>(a.as_integer() <span style=color:#f92672><</span> <span style=color:#ae81ff>0</span>)
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>cerr <span style=color:#f92672><<</span> toml<span style=color:#f92672>::</span>format_error(
|
||||
</span></span><span style=display:flex><span> <span style=color:#e6db74>"[warn] positive integer is required"</span>, <span style=color:#75715e>// Error title
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span> a, <span style=color:#e6db74>"but got negative value"</span> <span style=color:#75715e>// Message next to the value
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span> ) <span style=color:#f92672><<</span> std<span style=color:#f92672>::</span>endl;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>else</span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> a.as_integer()
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><h2 id=creating-error-messages-referencing-multiple-tomlvalue>Creating Error Messages Referencing Multiple <code>toml::value</code>
|
||||
<a class=anchor href=#creating-error-messages-referencing-multiple-tomlvalue>#</a></h2><p>In application settings, the range of permissible values might change based on previously read values.</p><p>In such cases, you may want to output the values causing the error simultaneously.</p><p><code>toml::format_error</code> and <code>toml::make_error_info</code> can take multiple pairs of <code>toml::value</code> and their corresponding error messages as <code>std::string</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>std<span style=color:#f92672>::</span>cerr <span style=color:#f92672><<</span> toml<span style=color:#f92672>::</span>format_error(
|
||||
</span></span><span style=display:flex><span> <span style=color:#e6db74>"[error] invalid range"</span>,
|
||||
</span></span><span style=display:flex><span> a, <span style=color:#e6db74>"minimum value is defined here"</span>,
|
||||
</span></span><span style=display:flex><span> b, <span style=color:#e6db74>"maximum value is defined here"</span>,
|
||||
</span></span><span style=display:flex><span> c, <span style=color:#e6db74>"and it exceeds the range"</span>
|
||||
</span></span><span style=display:flex><span> ) <span style=color:#f92672><<</span> std<span style=color:#f92672>::</span>endl;
|
||||
</span></span></code></pre></div><p>You can also add supplementary information at the end.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>std<span style=color:#f92672>::</span>cerr <span style=color:#f92672><<</span> toml<span style=color:#f92672>::</span>format_error(
|
||||
</span></span><span style=display:flex><span> <span style=color:#e6db74>"[error] invalid range"</span>,
|
||||
</span></span><span style=display:flex><span> a, <span style=color:#e6db74>"minimum value is defined here"</span>,
|
||||
</span></span><span style=display:flex><span> b, <span style=color:#e6db74>"maximum value is defined here"</span>,
|
||||
</span></span><span style=display:flex><span> c, <span style=color:#e6db74>"and it exceeds the range"</span>,
|
||||
</span></span><span style=display:flex><span> <span style=color:#e6db74>"Hint: all the values must be in the range [a, b)"</span>
|
||||
</span></span><span style=display:flex><span> ) <span style=color:#f92672><<</span> std<span style=color:#f92672>::</span>endl;
|
||||
</span></span></code></pre></div><p>When passing <code>toml::value</code> or <code>toml::source_location</code>, an error message related to it must follow. If not, it will result in a very confusing compilation error.</p></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#outputting-error-messages>Outputting Error Messages</a><ul><li><a href=#creating-error-messages-from-tomlvalue-location-information>Creating Error Messages from <code>toml::value</code> Location Information</a></li><li><a href=#adding-colors-to-strings>Adding Colors to Strings</a></li><li><a href=#changing-the-prefix-of-error-messages-from-error>Changing the Prefix of Error Messages from <code>[error]</code></a></li><li><a href=#creating-error-messages-referencing-multiple-tomlvalue>Creating Error Messages Referencing Multiple <code>toml::value</code></a></li></ul></li></ul></nav></div></aside></main></body></html>
|
||||
72
docs/features/extension/index.html
Normal file
72
docs/features/extension/index.html
Normal file
@@ -0,0 +1,72 @@
|
||||
<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
|
||||
TOML Language Extensions
|
||||
#
|
||||
|
||||
The TOML language is currently at version v1.0.0, but several new features have been discussed and merged, with ongoing discussions for v1.1.0.
|
||||
Among the proposed features, some were deemed to have limited use cases, some faced implementation challenges in their proposed form, and others were not adopted at all.
|
||||
In toml11, we have experimentally implemented a selection of these features. Please note that these features are supported in toml11 but are not supported by other parsers and are unlikely to be supported in the future."><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/features/extension/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="extension"><meta property="og:description" content="TOML Language Extensions # The TOML language is currently at version v1.0.0, but several new features have been discussed and merged, with ongoing discussions for v1.1.0.
|
||||
Among the proposed features, some were deemed to have limited use cases, some faced implementation challenges in their proposed form, and others were not adopted at all.
|
||||
In toml11, we have experimentally implemented a selection of these features. Please note that these features are supported in toml11 but are not supported by other parsers and are unlikely to be supported in the future."><meta property="og:locale" content="en"><meta property="og:type" content="article"><meta property="article:section" content="docs"><title>extension | toml11</title><link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/features/extension/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/features/extension/ title=extension><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" crossorigin=anonymous></script></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
|
||||
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
|
||||
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
|
||||
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/features/extension/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle checked>
|
||||
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/docs/features/extension/ class=active>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle>
|
||||
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
|
||||
</label><strong>extension</strong>
|
||||
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#toml-language-extensions>TOML Language Extensions</a><ul><li><a href=#null><code>null</code></a></li><li><a href=#hexadecimal-format-for-floating-point-numbers>Hexadecimal Format for Floating-Point Numbers</a></li><li><a href=#suffixes-for-integers-and-floating-point-numbers>Suffixes for Integers and Floating-Point Numbers</a></li></ul></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=toml-language-extensions>TOML Language Extensions
|
||||
<a class=anchor href=#toml-language-extensions>#</a></h1><p>The TOML language is currently at version v1.0.0, but several new features have been discussed and merged, with ongoing discussions for v1.1.0.</p><p>Among the proposed features, some were deemed to have limited use cases, some faced implementation challenges in their proposed form, and others were not adopted at all.</p><p>In toml11, we have experimentally implemented a selection of these features. Please note that these features are supported in toml11 but are not supported by other parsers and are unlikely to be supported in the future.</p><p>Additionally, these features are disabled by default. To use them, you must explicitly set the corresponding feature flags to <code>true</code>. This design choice ensures that non-standard features are only used intentionally.</p><p>Some of these features may eventually be merged into the TOML language itself. If a feature is officially adopted, the corresponding experimental implementation in toml11 may be removed in a minor version update after the official feature is implemented.</p><h2 id=null><code>null</code>
|
||||
<a class=anchor href=#null>#</a></h2><p>This feature allows the use of <code>null</code> as a value in TOML files.</p><pre tabindex=0><code>a = null
|
||||
b = [ 1, 2, 3, null, 5]
|
||||
</code></pre><p>To enable this, set the <code>ext_null_value</code> flag in <code>toml::spec</code> to <code>true</code>.</p><p>When parsed, it will be treated as <code>toml::value_t::empty</code>, similar to a default-constructed value. However, the location information within the file will be set.</p><p><code>null</code> is parsed only in the context of values. Therefore, if <code>null</code> is used as a key, it will be interpreted as the string <code>"null"</code>, as it has been in the standard TOML.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><toml.hpp></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> toml<span style=color:#f92672>::</span>spec spec;
|
||||
</span></span><span style=display:flex><span> spec.ext_null_value <span style=color:#f92672>=</span> true;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> v <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>parse_str(<span style=color:#e6db74>"a = null"</span>, spec);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> assert(v.at(<span style=color:#e6db74>"a"</span>).is_empty());
|
||||
</span></span><span style=display:flex><span> assert(v.at(<span style=color:#e6db74>"a"</span>).is(toml<span style=color:#f92672>::</span>value_t<span style=color:#f92672>::</span>empty));
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><h2 id=hexadecimal-format-for-floating-point-numbers>Hexadecimal Format for Floating-Point Numbers
|
||||
<a class=anchor href=#hexadecimal-format-for-floating-point-numbers>#</a></h2><p>This feature allows the use of hexadecimal format for floating-point numbers in TOML files.</p><pre tabindex=0><code>a = 0x1.91eb851eb851fp+1 # 3.14
|
||||
</code></pre><p>To enable this, set the <code>ext_hex_float</code> flag in <code>toml::spec</code> to <code>true</code>.</p><p>The format follows the <code>printf</code> specification for <code>%a/%A</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><toml.hpp></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> toml<span style=color:#f92672>::</span>spec spec;
|
||||
</span></span><span style=display:flex><span> spec.ext_hex_float <span style=color:#f92672>=</span> true;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> v <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>parse_str(<span style=color:#e6db74>"a = 0x1.91eb851eb851fp+1"</span>, spec);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> assert(v.at(<span style=color:#e6db74>"a"</span>).is_floating());
|
||||
</span></span><span style=display:flex><span> assert(v.at(<span style=color:#e6db74>"a"</span>).as_floating() <span style=color:#f92672>==</span> <span style=color:#ae81ff>3.14</span>);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><h2 id=suffixes-for-integers-and-floating-point-numbers>Suffixes for Integers and Floating-Point Numbers
|
||||
<a class=anchor href=#suffixes-for-integers-and-floating-point-numbers>#</a></h2><p>This feature allows the use of suffixes for numbers in TOML files. It can be applied to integers and floating-point numbers in decimal notation.</p><p>This is particularly useful for displaying units.</p><pre tabindex=0><code>a = 86_400_sec
|
||||
b = 3.1416_rad
|
||||
c = 10_μm
|
||||
</code></pre><p>However, these are purely suffixes and do not perform any unit conversion. If unit conversion is needed, users should implement it by referencing the suffix.</p><p>To enable this, set the <code>ext_num_suffix</code> flag in <code>toml::spec</code> to <code>true</code>.</p><p>The suffix must be separated from the number by an underscore (<code>_</code>).</p><p>For clarity, the suffix cannot start with a digit.</p><pre tabindex=0><code>distance = 100_m # valid
|
||||
distance = 10_0m # invalid
|
||||
distance = 10_0_m # valid
|
||||
</code></pre><p>The suffix is stored as <code>std::string suffix</code> in the format information.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><toml.hpp></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> toml<span style=color:#f92672>::</span>spec spec;
|
||||
</span></span><span style=display:flex><span> spec.ext_hex_float <span style=color:#f92672>=</span> true;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> v <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>parse_str(<span style=color:#e6db74>"a = 86_400_sec"</span>, spec);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> assert(v.at(<span style=color:#e6db74>"a"</span>).is_integer());
|
||||
</span></span><span style=display:flex><span> assert(v.at(<span style=color:#e6db74>"a"</span>).as_integer() <span style=color:#f92672>==</span> <span style=color:#ae81ff>86400</span>);
|
||||
</span></span><span style=display:flex><span> assert(v.at(<span style=color:#e6db74>"a"</span>).as_integer_fmt().suffix <span style=color:#f92672>==</span> <span style=color:#e6db74>"sec"</span>);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#toml-language-extensions>TOML Language Extensions</a><ul><li><a href=#null><code>null</code></a></li><li><a href=#hexadecimal-format-for-floating-point-numbers>Hexadecimal Format for Floating-Point Numbers</a></li><li><a href=#suffixes-for-integers-and-floating-point-numbers>Suffixes for Integers and Floating-Point Numbers</a></li></ul></li></ul></nav></div></aside></main></body></html>
|
||||
43
docs/features/index.html
Normal file
43
docs/features/index.html
Normal file
@@ -0,0 +1,43 @@
|
||||
<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
|
||||
Features
|
||||
#
|
||||
|
||||
This section explains the main features provided by toml11, with examples.
|
||||
|
||||
Parsing Files and Strings
|
||||
#
|
||||
|
||||
Describes the functions for parsing files and strings, and how to handle the errors they produce.
|
||||
Includes:
|
||||
|
||||
Parsing files
|
||||
Parsing strings
|
||||
Parsing byte arrays
|
||||
Parsing files without throwing exceptions
|
||||
Parsing strings without throwing exceptions
|
||||
Parsing byte arrays without throwing exceptions
|
||||
|
||||
|
||||
Extracting Values from toml::value
|
||||
#
|
||||
|
||||
Explains how to examine, extract, and convert the data types held by toml::value."><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/features/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="features"><meta property="og:description" content="Features # This section explains the main features provided by toml11, with examples.
|
||||
Parsing Files and Strings # Describes the functions for parsing files and strings, and how to handle the errors they produce.
|
||||
Includes:
|
||||
Parsing files Parsing strings Parsing byte arrays Parsing files without throwing exceptions Parsing strings without throwing exceptions Parsing byte arrays without throwing exceptions Extracting Values from toml::value # Explains how to examine, extract, and convert the data types held by toml::value."><meta property="og:locale" content="en"><meta property="og:type" content="website"><title>features | toml11</title><link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/features/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/features/ title=features><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" crossorigin=anonymous></script><link rel=alternate type=application/rss+xml href=https://toruniina.github.io/toml11/docs/features/index.xml title=toml11></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
|
||||
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
|
||||
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
|
||||
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/features/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle checked>
|
||||
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/ class=active>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle>
|
||||
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
|
||||
</label><strong>features</strong>
|
||||
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#features>Features</a><ul><li><a href=#parsing-files-and-strings>Parsing Files and Strings</a></li><li><a href=#extracting-values-from>Extracting Values from <code>toml::value</code></a></li><li><a href=#creating-error-messages>Creating Error Messages</a></li><li><a href=#serializing-toml-files>Serializing TOML Files</a></li><li><a href=#configuring-types-of>Configuring Types of <code>toml::value</code></a></li><li><a href=#toml-literals>TOML Literals</a></li><li><a href=#toml-language-version>TOML Language Version</a></li><li><a href=#toml-language-extensions>TOML Language Extensions</a></li></ul></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=features>Features
|
||||
<a class=anchor href=#features>#</a></h1><p>This section explains the main features provided by toml11, with examples.</p><h2 id=parsing-files-and-strings><a href=parsing_files>Parsing Files and Strings</a>
|
||||
<a class=anchor href=#parsing-files-and-strings>#</a></h2><p>Describes the functions for parsing files and strings, and how to handle the errors they produce.</p><p>Includes:</p><ul><li>Parsing files</li><li>Parsing strings</li><li>Parsing byte arrays</li><li>Parsing files without throwing exceptions</li><li>Parsing strings without throwing exceptions</li><li>Parsing byte arrays without throwing exceptions</li></ul><h2 id=extracting-values-from><a href=value>Extracting Values from <code>toml::value</code></a>
|
||||
<a class=anchor href=#extracting-values-from>#</a></h2><p>Explains how to examine, extract, and convert the data types held by <code>toml::value</code>.</p><p>Includes:</p><ul><li>Checking the type of a value using member functions</li><li>Accessing values using member functions</li><li>Accessing comments</li><li>Handling inline tables and dotted keys</li><li>Handling date information</li><li>Using <code>toml::get<T></code> for conversion</li><li>Using <code>toml::get_or</code> to specify a fallback value</li><li>Using <code>toml::find<T></code> for searching and conversion</li><li>Using <code>toml::find_or</code> to specify a fallback value</li><li>Defining conversions with user-defined types</li><li>Applying functions with <code>toml::visit</code></li><li>Constructing <code>toml::value</code></li></ul><h2 id=creating-error-messages><a href=error_message>Creating Error Messages</a>
|
||||
<a class=anchor href=#creating-error-messages>#</a></h2><p>Explains how to generate error messages with location information from a TOML file using <code>toml::value</code>.</p><p>Includes:</p><ul><li>Extracting location information from <code>toml::value</code></li><li>Constructing error messages</li><li>Adding color to the output</li></ul><h2 id=serializing-toml-files><a href=serialize>Serializing TOML Files</a>
|
||||
<a class=anchor href=#serializing-toml-files>#</a></h2><p>Describes how to format the values of <code>toml::value</code> and the available formatting options.</p><p>Includes:</p><ul><li>Specifying formats for each value of <code>toml::value</code></li><li>Formatting <code>toml::value</code> into a string</li></ul><h2 id=configuring-types-of><a href=configure_types>Configuring Types of <code>toml::value</code></a>
|
||||
<a class=anchor href=#configuring-types-of>#</a></h2><p>Explains how to customize the types stored in <code>toml::value</code> (such as <code>integer_type</code> and <code>table_type</code>).</p><p>Includes:</p><ul><li>Defining <code>type_config</code></li><li>Using <code>ordered_type_config</code></li><li>Disabling comment preservation</li><li>Using different containers like <code>std::deque</code></li><li>Using different numeric types like <code>boost::multiprecision</code></li></ul><h2 id=toml-literals><a href=literal>TOML Literals</a>
|
||||
<a class=anchor href=#toml-literals>#</a></h2><p>Explains the <code>_toml</code> literal for embedding TOML files directly in C++ code.</p><p>Includes:</p><ul><li>Using TOML literals</li></ul><h2 id=toml-language-version><a href=toml_spec>TOML Language Version</a>
|
||||
<a class=anchor href=#toml-language-version>#</a></h2><p>Describes the versions of the TOML language supported by toml11 and how to control language features added in TOML-v1.1.0.</p><p>Includes:</p><ul><li>Using TOML language version 1.1.0</li><li>Using specific features of TOML language version 1.1.0</li></ul><h2 id=toml-language-extensions><a href=extension>TOML Language Extensions</a>
|
||||
<a class=anchor href=#toml-language-extensions>#</a></h2><p>Explains the custom extensions to the TOML language provided by toml11.</p><p>Includes:</p><ul><li>Supporting <code>null</code></li><li>Supporting hexadecimal format for floating-point numbers</li><li>Allowing units for numbers</li></ul></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#features>Features</a><ul><li><a href=#parsing-files-and-strings>Parsing Files and Strings</a></li><li><a href=#extracting-values-from>Extracting Values from <code>toml::value</code></a></li><li><a href=#creating-error-messages>Creating Error Messages</a></li><li><a href=#serializing-toml-files>Serializing TOML Files</a></li><li><a href=#configuring-types-of>Configuring Types of <code>toml::value</code></a></li><li><a href=#toml-literals>TOML Literals</a></li><li><a href=#toml-language-version>TOML Language Version</a></li><li><a href=#toml-language-extensions>TOML Language Extensions</a></li></ul></li></ul></nav></div></aside></main></body></html>
|
||||
135
docs/features/index.xml
Normal file
135
docs/features/index.xml
Normal file
@@ -0,0 +1,135 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>features on toml11</title><link>https://toruniina.github.io/toml11/docs/features/</link><description>Recent content in features on toml11</description><generator>Hugo</generator><language>en</language><atom:link href="https://toruniina.github.io/toml11/docs/features/index.xml" rel="self" type="application/rss+xml"/><item><title>parsing files</title><link>https://toruniina.github.io/toml11/docs/features/parsing_files/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/docs/features/parsing_files/</guid><description><h1 id="parsing-files-and-strings">
|
||||
Parsing Files and Strings
|
||||
<a class="anchor" href="#parsing-files-and-strings">#</a>
|
||||
</h1>
|
||||
<p>In toml11, you can parse files, strings, and byte arrays using <code>toml::parse</code> or <code>toml::try_parse</code>.</p>
|
||||
<p>Upon success, these functions return a <code>toml::value</code>.
|
||||
Although the parsed file is always a table, the return type is not <code>toml::table</code>.
|
||||
This is because <code>toml::value</code> contains metadata about the file, whereas <code>toml::table</code> is merely an alias for <code>std::unordered_map&lt;std::string, toml::value&gt;</code>.
|
||||
To include metadata, a <code>toml::value</code> is returned instead of a <code>toml::table</code>.
|
||||
The <code>toml::value</code> corresponding to the root of the file will always hold a <code>table_type</code>.</p></description></item><item><title>getting values</title><link>https://toruniina.github.io/toml11/docs/features/value/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/docs/features/value/</guid><description><h1 id="retrieving-values">
|
||||
Retrieving Values
|
||||
<a class="anchor" href="#retrieving-values">#</a>
|
||||
</h1>
|
||||
<p>This section explains how to access the values stored in <code>toml::value</code>.</p>
|
||||
<h2 id="accessing-values-using-member-functions">
|
||||
Accessing Values Using Member Functions
|
||||
<a class="anchor" href="#accessing-values-using-member-functions">#</a>
|
||||
</h2>
|
||||
<h3 id="is_something-and-as_something">
|
||||
<code>is_something</code> and <code>as_something</code>
|
||||
<a class="anchor" href="#is_something-and-as_something">#</a>
|
||||
</h3>
|
||||
<p><code>toml::value</code> has member functions like <code>is_boolean()</code> and <code>is_integer()</code> which allow you to check the type of the stored value.</p>
|
||||
<p>Additionally, it has member functions like <code>as_boolean()</code> and <code>as_integer()</code> that allow you to access the value of that type.</p>
|
||||
<p>For a complete list, refer to the <a href="https://toruniina.github.io/toml11/docs/reference/value/#is_xxx"><code>toml::value</code> reference</a>.</p></description></item><item><title>error message</title><link>https://toruniina.github.io/toml11/docs/features/error_message/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/docs/features/error_message/</guid><description><h1 id="outputting-error-messages">
|
||||
Outputting Error Messages
|
||||
<a class="anchor" href="#outputting-error-messages">#</a>
|
||||
</h1>
|
||||
<p><code>toml11</code> provides error messages that include location information within the file when using functions like <code>toml::parse</code>, <code>toml::get&lt;T&gt;/find&lt;T&gt;</code>, and <code>as_integer()</code>, among others.</p>
|
||||
<p>For instance, if a syntax error in an integer is detected during parsing, an error message might look like this:</p>
|
||||
<pre tabindex="0"><code>[error] bad integer: `_` must be surrounded by digits
|
||||
--&gt; internal string at line 64 in file main.cpp
|
||||
|
|
||||
1 | a = 123__456
|
||||
| ^-- invalid underscore
|
||||
Hint: valid : -42, 1_000, 1_2_3_4_5, 0xC0FFEE, 0b0010, 0o755
|
||||
Hint: invalid: _42, 1__000, 0123
|
||||
</code></pre><p>Or, if a type different from the one actually stored is requested:</p></description></item><item><title>serializing values</title><link>https://toruniina.github.io/toml11/docs/features/serialize/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/docs/features/serialize/</guid><description><h1 id="outputting-toml-files">
|
||||
Outputting TOML Files
|
||||
<a class="anchor" href="#outputting-toml-files">#</a>
|
||||
</h1>
|
||||
<p>Using <code>toml::format</code>, you can convert a <code>toml::value</code> to a string.</p>
|
||||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#75715e">#include</span> <span style="color:#75715e">&lt;toml.hpp&gt;</span><span style="color:#75715e">
|
||||
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">#include</span> <span style="color:#75715e">&lt;cassert&gt;</span><span style="color:#75715e">
|
||||
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>()
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">const</span> toml<span style="color:#f92672">::</span>value v(toml<span style="color:#f92672">::</span>table{
|
||||
</span></span><span style="display:flex;"><span> {<span style="color:#e6db74">&#34;a&#34;</span>, <span style="color:#ae81ff">42</span>},
|
||||
</span></span><span style="display:flex;"><span> {<span style="color:#e6db74">&#34;b&#34;</span>, <span style="color:#e6db74">&#34;foo&#34;</span>},
|
||||
</span></span><span style="display:flex;"><span> });
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">const</span> std<span style="color:#f92672">::</span>string s <span style="color:#f92672">=</span> toml<span style="color:#f92672">::</span>format(v);
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">const</span> toml<span style="color:#f92672">::</span>value u <span style="color:#f92672">=</span> toml<span style="color:#f92672">::</span>parse_str(s);
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span> assert(u.at(<span style="color:#e6db74">&#34;a&#34;</span>).as_integer() <span style="color:#f92672">==</span> <span style="color:#ae81ff">42</span>);
|
||||
</span></span><span style="display:flex;"><span> assert(u.at(<span style="color:#e6db74">&#34;b&#34;</span>).as_string() <span style="color:#f92672">==</span> <span style="color:#e6db74">&#34;foo&#34;</span>);
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> <span style="color:#ae81ff">0</span>;
|
||||
</span></span><span style="display:flex;"><span>}
|
||||
</span></span></code></pre></div><p>If the <code>toml::value</code> contains a <code>table_type</code>, it is interpreted as the root table of the file.</p>
|
||||
<p>If a <code>toml::value</code> containing anything other than <code>table_type</code> is passed, only that value is formatted.</p></description></item><item><title>configuring types</title><link>https://toruniina.github.io/toml11/docs/features/configure_types/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/docs/features/configure_types/</guid><description><h1 id="customizing-types">
|
||||
Customizing Types
|
||||
<a class="anchor" href="#customizing-types">#</a>
|
||||
</h1>
|
||||
<p>The <code>toml::value</code> class uses <code>std::int64_t</code> for <code>integer_type</code> and <code>std::unordered_map&lt;key_type, value_type&gt;</code> for <code>table_type</code>.</p>
|
||||
<p>However, in some cases, you may want to use <code>boost::multiprecision::int128_t</code> or <code>std::map</code>.</p>
|
||||
<p>To accommodate this, <code>toml::value</code> is implemented with template parameters that allow you to change the stored types.</p>
|
||||
<p>Just as <code>std::string</code> is actually an alias for <code>std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt;</code>, <code>toml::value</code> is an alias for <code>toml::basic_value&lt;toml::type_config&gt;</code>.</p>
|
||||
<p>Here, we will explain the types contained in <code>toml::type_config</code> and how to define a different <code>config</code> type.</p></description></item><item><title>toml literal</title><link>https://toruniina.github.io/toml11/docs/features/literal/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/docs/features/literal/</guid><description><h1 id="_toml-literal">
|
||||
<code>_toml</code> Literal
|
||||
<a class="anchor" href="#_toml-literal">#</a>
|
||||
</h1>
|
||||
<p>With the <code>&quot;&quot;_toml</code> literal, you can format TOML files inline.</p>
|
||||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#75715e">#include</span> <span style="color:#75715e">&lt;toml.hpp&gt;</span><span style="color:#75715e">
|
||||
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>()
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">using</span> <span style="color:#66d9ef">namespace</span> toml<span style="color:#f92672">::</span>literals<span style="color:#f92672">::</span>toml_literals;
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">const</span> <span style="color:#66d9ef">auto</span> v <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;a = 42&#34;</span>_toml;
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span> assert(v.at(<span style="color:#e6db74">&#34;a&#34;</span>).as_integer() <span style="color:#f92672">==</span> <span style="color:#ae81ff">42</span>);
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> <span style="color:#ae81ff">0</span>;
|
||||
</span></span><span style="display:flex;"><span>}
|
||||
</span></span></code></pre></div><p>When including line breaks, raw string literals come in handy.</p>
|
||||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#75715e">#include</span> <span style="color:#75715e">&lt;toml.hpp&gt;</span><span style="color:#75715e">
|
||||
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>()
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">using</span> <span style="color:#66d9ef">namespace</span> toml<span style="color:#f92672">::</span>literals<span style="color:#f92672">::</span>toml_literals;
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">const</span> <span style="color:#66d9ef">auto</span> v <span style="color:#f92672">=</span> R<span style="color:#e6db74">&#34;(</span>
|
||||
</span></span><span style="display:flex;"><span> a <span style="color:#f92672">=</span> <span style="color:#ae81ff">42</span>
|
||||
</span></span><span style="display:flex;"><span> b <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;foo&#34;</span>
|
||||
</span></span><span style="display:flex;"><span> )<span style="color:#e6db74">&#34;_toml;</span>
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span> assert(v.at(<span style="color:#e6db74">&#34;a&#34;</span>).as_integer() <span style="color:#f92672">==</span> <span style="color:#ae81ff">42</span>);
|
||||
</span></span><span style="display:flex;"><span> assert(v.at(<span style="color:#e6db74">&#34;b&#34;</span>).as_string() <span style="color:#f92672">==</span> <span style="color:#e6db74">&#34;foo&#34;</span>);
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> <span style="color:#ae81ff">0</span>;
|
||||
</span></span><span style="display:flex;"><span>}
|
||||
</span></span></code></pre></div><p>If a value is written on its own, that value is returned.</p></description></item><item><title>toml spec</title><link>https://toruniina.github.io/toml11/docs/features/toml_spec/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/docs/features/toml_spec/</guid><description><h1 id="toml-language-version">
|
||||
TOML Language Version
|
||||
<a class="anchor" href="#toml-language-version">#</a>
|
||||
</h1>
|
||||
<p>You can specify the version of the TOML language and individual feature flags to use with <code>toml::parse</code> or <code>toml::format</code> through <a href="https://toruniina.github.io/toml11/docs/reference/spec/#tomlspec"><code>toml::spec</code></a>.</p>
|
||||
<h2 id="specifying-toml-version">
|
||||
Specifying TOML Version
|
||||
<a class="anchor" href="#specifying-toml-version">#</a>
|
||||
</h2>
|
||||
<p>You can construct a <a href="https://toruniina.github.io/toml11/docs/reference/spec/#tomlspec"><code>toml::spec</code></a> from <a href="https://toruniina.github.io/toml11/docs/reference/spec/#tomlsemantic_version"><code>toml::semantic_version</code></a>.</p>
|
||||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#75715e">#include</span> <span style="color:#75715e">&lt;toml.hpp&gt;</span><span style="color:#75715e">
|
||||
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>()
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span> toml<span style="color:#f92672">::</span>spec spec(toml<span style="color:#f92672">::</span>semantic_version(<span style="color:#ae81ff">1</span>, <span style="color:#ae81ff">1</span>, <span style="color:#ae81ff">0</span>));
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> <span style="color:#ae81ff">0</span>;
|
||||
</span></span><span style="display:flex;"><span>}
|
||||
</span></span></code></pre></div><p>However, to make this shorter, the <code>toml::spec::v()</code> function is provided.</p>
|
||||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#75715e">#include</span> <span style="color:#75715e">&lt;toml.hpp&gt;</span><span style="color:#75715e">
|
||||
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>()
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span> toml<span style="color:#f92672">::</span>spec spec <span style="color:#f92672">=</span> toml<span style="color:#f92672">::</span>spec<span style="color:#f92672">::</span>v(<span style="color:#ae81ff">1</span>, <span style="color:#ae81ff">1</span>, <span style="color:#ae81ff">0</span>);
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> <span style="color:#ae81ff">0</span>;
|
||||
</span></span><span style="display:flex;"><span>}
|
||||
</span></span></code></pre></div><p>If not specified explicitly, <code>toml::spec::default_version()</code> is used to construct with default values.</p></description></item><item><title>extension</title><link>https://toruniina.github.io/toml11/docs/features/extension/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/docs/features/extension/</guid><description><h1 id="toml-language-extensions">
|
||||
TOML Language Extensions
|
||||
<a class="anchor" href="#toml-language-extensions">#</a>
|
||||
</h1>
|
||||
<p>The TOML language is currently at version v1.0.0, but several new features have been discussed and merged, with ongoing discussions for v1.1.0.</p>
|
||||
<p>Among the proposed features, some were deemed to have limited use cases, some faced implementation challenges in their proposed form, and others were not adopted at all.</p>
|
||||
<p>In toml11, we have experimentally implemented a selection of these features. Please note that these features are supported in toml11 but are not supported by other parsers and are unlikely to be supported in the future.</p></description></item></channel></rss>
|
||||
106
docs/features/literal/index.html
Normal file
106
docs/features/literal/index.html
Normal file
@@ -0,0 +1,106 @@
|
||||
<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content='
|
||||
_toml Literal
|
||||
#
|
||||
|
||||
With the ""_toml literal, you can format TOML files inline.
|
||||
#include <toml.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace toml::literals::toml_literals;
|
||||
|
||||
const auto v = "a = 42"_toml;
|
||||
|
||||
assert(v.at("a").as_integer() == 42);
|
||||
|
||||
return 0;
|
||||
}
|
||||
When including line breaks, raw string literals come in handy.
|
||||
#include <toml.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace toml::literals::toml_literals;
|
||||
|
||||
const auto v = R"(
|
||||
a = 42
|
||||
b = "foo"
|
||||
)"_toml;
|
||||
|
||||
assert(v.at("a").as_integer() == 42);
|
||||
assert(v.at("b").as_string() == "foo");
|
||||
|
||||
return 0;
|
||||
}
|
||||
If a value is written on its own, that value is returned.'><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/features/literal/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="toml literal"><meta property="og:description" content='_toml Literal # With the ""_toml literal, you can format TOML files inline.
|
||||
#include <toml.hpp> int main() { using namespace toml::literals::toml_literals; const auto v = "a = 42"_toml; assert(v.at("a").as_integer() == 42); return 0; } When including line breaks, raw string literals come in handy.
|
||||
#include <toml.hpp> int main() { using namespace toml::literals::toml_literals; const auto v = R"( a = 42 b = "foo" )"_toml; assert(v.at("a").as_integer() == 42); assert(v.at("b").as_string() == "foo"); return 0; } If a value is written on its own, that value is returned.'><meta property="og:locale" content="en"><meta property="og:type" content="article"><meta property="article:section" content="docs"><title>toml literal | toml11</title><link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/features/literal/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/features/literal/ title="toml literal"><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" crossorigin=anonymous></script></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
|
||||
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
|
||||
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
|
||||
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/features/literal/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle checked>
|
||||
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/ class=active>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle>
|
||||
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
|
||||
</label><strong>toml literal</strong>
|
||||
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#_toml-literal><code>_toml</code> Literal</a></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=_toml-literal><code>_toml</code> Literal
|
||||
<a class=anchor href=#_toml-literal>#</a></h1><p>With the <code>""_toml</code> literal, you can format TOML files inline.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><toml.hpp></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> <span style=color:#66d9ef>namespace</span> toml<span style=color:#f92672>::</span>literals<span style=color:#f92672>::</span>toml_literals;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> v <span style=color:#f92672>=</span> <span style=color:#e6db74>"a = 42"</span>_toml;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> assert(v.at(<span style=color:#e6db74>"a"</span>).as_integer() <span style=color:#f92672>==</span> <span style=color:#ae81ff>42</span>);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>When including line breaks, raw string literals come in handy.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><toml.hpp></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> <span style=color:#66d9ef>namespace</span> toml<span style=color:#f92672>::</span>literals<span style=color:#f92672>::</span>toml_literals;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> v <span style=color:#f92672>=</span> R<span style=color:#e6db74>"(</span>
|
||||
</span></span><span style=display:flex><span> a <span style=color:#f92672>=</span> <span style=color:#ae81ff>42</span>
|
||||
</span></span><span style=display:flex><span> b <span style=color:#f92672>=</span> <span style=color:#e6db74>"foo"</span>
|
||||
</span></span><span style=display:flex><span> )<span style=color:#e6db74>"_toml;</span>
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> assert(v.at(<span style=color:#e6db74>"a"</span>).as_integer() <span style=color:#f92672>==</span> <span style=color:#ae81ff>42</span>);
|
||||
</span></span><span style=display:flex><span> assert(v.at(<span style=color:#e6db74>"b"</span>).as_string() <span style=color:#f92672>==</span> <span style=color:#e6db74>"foo"</span>);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>If a value is written on its own, that value is returned.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><toml.hpp></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> <span style=color:#66d9ef>namespace</span> toml<span style=color:#f92672>::</span>literals<span style=color:#f92672>::</span>toml_literals;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> a <span style=color:#f92672>=</span> <span style=color:#e6db74>"42"</span>_toml;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> b <span style=color:#f92672>=</span> <span style=color:#e6db74>"12:34:56"</span>_toml;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> assert(a.as_integer() <span style=color:#f92672>==</span> <span style=color:#ae81ff>42</span>);
|
||||
</span></span><span style=display:flex><span> assert(b.as_local_time().hour <span style=color:#f92672>==</span> <span style=color:#ae81ff>12</span>);
|
||||
</span></span><span style=display:flex><span> assert(b.as_local_time().minute <span style=color:#f92672>==</span> <span style=color:#ae81ff>34</span>);
|
||||
</span></span><span style=display:flex><span> assert(b.as_local_time().second <span style=color:#f92672>==</span> <span style=color:#ae81ff>56</span>);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>TOML allows keys consisting solely of numbers. Therefore, <code>[1]</code> is a valid table name.</p><p>When there’s ambiguity between table definitions and arrays, table definitions take precedence.</p><p>To interpret as an array, please use a trailing comma.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><toml.hpp></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> <span style=color:#66d9ef>namespace</span> toml<span style=color:#f92672>::</span>literals<span style=color:#f92672>::</span>toml_literals;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> t <span style=color:#f92672>=</span> <span style=color:#e6db74>"[1]"</span>_toml; <span style=color:#75715e>// {1 = {}}
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span> <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> a <span style=color:#f92672>=</span> <span style=color:#e6db74>"[1,]"</span>_toml; <span style=color:#75715e>// [1,]
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span> assert(t.is_table());
|
||||
</span></span><span style=display:flex><span> assert(t.at(<span style=color:#e6db74>"1"</span>).is_table());
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> assert(a.is_array());
|
||||
</span></span><span style=display:flex><span> assert(a.at(<span style=color:#ae81ff>0</span>).as_integer() <span style=color:#f92672>==</span> <span style=color:#ae81ff>1</span>);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#_toml-literal><code>_toml</code> Literal</a></li></ul></nav></div></aside></main></body></html>
|
||||
143
docs/features/parsing_files/index.html
Normal file
143
docs/features/parsing_files/index.html
Normal file
@@ -0,0 +1,143 @@
|
||||
<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
|
||||
Parsing Files and Strings
|
||||
#
|
||||
|
||||
In toml11, you can parse files, strings, and byte arrays using toml::parse or toml::try_parse.
|
||||
Upon success, these functions return a toml::value.
|
||||
Although the parsed file is always a table, the return type is not toml::table.
|
||||
This is because toml::value contains metadata about the file, whereas toml::table is merely an alias for std::unordered_map<std::string, toml::value>.
|
||||
To include metadata, a toml::value is returned instead of a toml::table.
|
||||
The toml::value corresponding to the root of the file will always hold a table_type."><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/features/parsing_files/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="parsing files"><meta property="og:description" content="Parsing Files and Strings # In toml11, you can parse files, strings, and byte arrays using toml::parse or toml::try_parse.
|
||||
Upon success, these functions return a toml::value. Although the parsed file is always a table, the return type is not toml::table. This is because toml::value contains metadata about the file, whereas toml::table is merely an alias for std::unordered_map<std::string, toml::value>. To include metadata, a toml::value is returned instead of a toml::table. The toml::value corresponding to the root of the file will always hold a table_type."><meta property="og:locale" content="en"><meta property="og:type" content="article"><meta property="article:section" content="docs"><title>parsing files | toml11</title><link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/features/parsing_files/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/features/parsing_files/ title="parsing files"><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" crossorigin=anonymous></script></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
|
||||
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
|
||||
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
|
||||
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/features/parsing_files/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle checked>
|
||||
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/ class=active>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle>
|
||||
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
|
||||
</label><strong>parsing files</strong>
|
||||
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#parsing-files-and-strings>Parsing Files and Strings</a><ul><li><a href=#parsing-files>Parsing Files</a><ul><li><a href=#tomlparse><code>toml::parse</code></a></li><li><a href=#tomltry_parse><code>toml::try_parse</code></a></li></ul></li><li><a href=#parsing-strings>Parsing Strings</a><ul><li><a href=#tomlparse_str><code>toml::parse_str</code></a></li><li><a href=#tomltry_parse_str><code>toml::try_parse_str</code></a></li></ul></li><li><a href=#parsing-byte-arrays>Parsing Byte Arrays</a><ul><li><a href=#tomlparsestdvectorunsigned-char><code>toml::parse(std::vector<unsigned char>)</code></a></li><li><a href=#tomltry_parsestdvectorunsigned-char><code>toml::try_parse(std::vector<unsigned char>)</code></a></li></ul></li></ul></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=parsing-files-and-strings>Parsing Files and Strings
|
||||
<a class=anchor href=#parsing-files-and-strings>#</a></h1><p>In toml11, you can parse files, strings, and byte arrays using <code>toml::parse</code> or <code>toml::try_parse</code>.</p><p>Upon success, these functions return a <code>toml::value</code>.
|
||||
Although the parsed file is always a table, the return type is not <code>toml::table</code>.
|
||||
This is because <code>toml::value</code> contains metadata about the file, whereas <code>toml::table</code> is merely an alias for <code>std::unordered_map<std::string, toml::value></code>.
|
||||
To include metadata, a <code>toml::value</code> is returned instead of a <code>toml::table</code>.
|
||||
The <code>toml::value</code> corresponding to the root of the file will always hold a <code>table_type</code>.</p><h2 id=parsing-files>Parsing Files
|
||||
<a class=anchor href=#parsing-files>#</a></h2><p>To parse files, use either
|
||||
<a href=https://toruniina.github.io/toml11/docs/reference/parser/#parse><code>toml::parse</code></a>
|
||||
or
|
||||
<a href=https://toruniina.github.io/toml11/docs/reference/parser/#try_parse><code>toml::try_parse</code></a>.</p><h3 id=tomlparse><code>toml::parse</code>
|
||||
<a class=anchor href=#tomlparse>#</a></h3><h4 id=specifying-the-filename-with-stdstring>Specifying the Filename with <code>std::string</code>
|
||||
<a class=anchor href=#specifying-the-filename-with-stdstring>#</a></h4><p><a href=https://toruniina.github.io/toml11/docs/reference/parser/#parse><code>toml::parse</code></a>
|
||||
accepts a filename as a string, opens the file, and parses it.</p><p>The following sample code parses a file named <code>input.toml</code>, extracts the <code>title</code> variable as a string, and prints it.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><toml.hpp></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><iostream></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value input <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>parse(<span style=color:#e6db74>"input.toml"</span>);
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>cout <span style=color:#f92672><<</span> input.at(<span style=color:#e6db74>"title"</span>).as_string() <span style=color:#f92672><<</span> std<span style=color:#f92672>::</span>endl;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><h4 id=specifying-a-file-with-stdfilesystempath>Specifying a File with <code>std::filesystem::path</code>
|
||||
<a class=anchor href=#specifying-a-file-with-stdfilesystempath>#</a></h4><p><a href=https://toruniina.github.io/toml11/docs/reference/parser/#parse><code>toml::parse</code></a> can accept a <code>std::filesystem::path</code>.</p><p>This requires C++17 or later, as it relies on the <code><filesystem></code> support.</p><h4 id=specifying-an-input-stream-with-stdistream>Specifying an Input Stream with <code>std::istream</code>
|
||||
<a class=anchor href=#specifying-an-input-stream-with-stdistream>#</a></h4><p><a href=https://toruniina.github.io/toml11/docs/reference/parser/#parse><code>toml::parse</code></a> can also accept an <code>std::istream</code>.</p><p>Open a stream in binary mode by passing <code>std::ios::binary</code> to avoid inconsistency between the file size and the number of characters due to automatic conversion of newline characters by the standard library.</p><p>Without the filename information, error messages will display <code>"unknown file"</code>. To avoid this, you can pass the filename as a <code>std::string</code> in the second argument when using <code>std::istream</code>.</p><p>You can use streams other than <code>std::ifstream</code>, such as <code>std::istringstream</code>. Note that the entire content is readable at the time of the call.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><toml.hpp></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><iostream></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string filename(<span style=color:#e6db74>"input.toml"</span>);
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>ifstream ifs(filename);
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value input <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>parse(ifs, filename);
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>cout <span style=color:#f92672><<</span> input.at(<span style=color:#e6db74>"title"</span>).as_string() <span style=color:#f92672><<</span> std<span style=color:#f92672>::</span>endl;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><h4 id=specifying-a-file-with-file>Specifying a File with <code>FILE*</code>
|
||||
<a class=anchor href=#specifying-a-file-with-file>#</a></h4><p><a href=https://toruniina.github.io/toml11/docs/reference/parser/#parse><code>toml::parse</code></a> can also accept a <code>FILE*</code>.</p><p>Open a stream in binary mode by passing <code>"rb"</code> to avoid inconsistency between the file size and the number of characters due to automatic conversion of newline characters by the standard library.</p><p>As with <code>std::istream</code>, you need to provide the filename as a string in the second argument.</p><p>When passing a <code>FILE*</code>, if the file read fails, <code>errno</code> will be reported.</p><h4 id=error-handling>Error Handling
|
||||
<a class=anchor href=#error-handling>#</a></h4><p><a href=https://toruniina.github.io/toml11/docs/reference/parser/#parse><code>toml::parse</code></a> throws a <a href=https://toruniina.github.io/toml11/docs/reference/parser/#syntax_error><code>toml::syntax_error</code></a> if it encounters a syntax error.</p><p><a href=https://toruniina.github.io/toml11/docs/reference/parser/#syntax_error><code>toml::syntax_error</code></a> is derived from <a href=https://toruniina.github.io/toml11/docs/reference/exception/><code>toml::exception</code></a>, which in turn is derived from <code>std::exception</code>.</p><p>Therefore, you can use the <code>what()</code> member function to retrieve the error message from a <a href=https://toruniina.github.io/toml11/docs/reference/parser/#syntax_error><code>toml::syntax_error</code></a>.</p><p>Additionally, <a href=https://toruniina.github.io/toml11/docs/reference/parser/#syntax_error><code>toml::syntax_error</code></a> contains a <a href=https://toruniina.github.io/toml11/docs/reference/error_info/><code>std::vector<toml::error_info></code></a>, which can be accessed using the <code>errors()</code> member function.</p><p><code>toml::parse</code> attempts to recover from minor errors and report multiple errors whenever possible. While it can often recover from simple errors like number format issues, errors within arrays or tables might not be recoverable and may lead to multiple similar error reports. If you find the error messages redundant, you can use only the <code>front()</code> of the <code>std::vector<toml::error_info></code> to get a message about the most critical issue.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><toml.hpp></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>try</span> {
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value input <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>parse(<span style=color:#e6db74>"input.toml"</span>);
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>cout <span style=color:#f92672><<</span> input.at(<span style=color:#e6db74>"title"</span>).as_string() <span style=color:#f92672><<</span> std<span style=color:#f92672>::</span>endl;
|
||||
</span></span><span style=display:flex><span> } <span style=color:#66d9ef>catch</span>(<span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>syntax_error<span style=color:#f92672>&</span> err) {
|
||||
</span></span><span style=display:flex><span> <span style=color:#75715e>// report all the errors
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span> std<span style=color:#f92672>::</span>cerr <span style=color:#f92672><<</span> err.what() <span style=color:#f92672><<</span> std<span style=color:#f92672>::</span>endl;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#75715e>// report the first error only
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span> std<span style=color:#f92672>::</span>cerr <span style=color:#f92672><<</span> err.errors().front() <span style=color:#f92672><<</span> std<span style=color:#f92672>::</span>endl;
|
||||
</span></span><span style=display:flex><span> }
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><h3 id=tomltry_parse><code>toml::try_parse</code>
|
||||
<a class=anchor href=#tomltry_parse>#</a></h3><p>While <code>toml::parse</code> throws an exception on failure, <code>toml::try_parse</code> does not throw exceptions when it fails.</p><p>Instead, its return type is <a href=https://toruniina.github.io/toml11/docs/reference/result/#result><code>toml::result<toml::value, std::vector<toml::error_info>></code></a>.</p><p>The <a href=https://toruniina.github.io/toml11/docs/reference/result/#result><code>result</code></a> type holds either a success value or a failure value, similar to Rust’s <code>Result</code> or Haskell’s <code>Either</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><toml.hpp></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> parse_result <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>try_parse(<span style=color:#e6db74>"input.toml"</span>);
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>if</span>(parse_result.is_ok())
|
||||
</span></span><span style=display:flex><span> {
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>cout <span style=color:#f92672><<</span> parse_result.unwrap().at(<span style=color:#e6db74>"title"</span>).as_string() <span style=color:#f92672><<</span> std<span style=color:#f92672>::</span>endl;
|
||||
</span></span><span style=display:flex><span> }
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>else</span>
|
||||
</span></span><span style=display:flex><span> {
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>cerr <span style=color:#f92672><<</span> parse_result.unwrap_err().at(<span style=color:#ae81ff>0</span>) <span style=color:#f92672><<</span> std<span style=color:#f92672>::</span>endl;
|
||||
</span></span><span style=display:flex><span> }
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>To check which value the <a href=https://toruniina.github.io/toml11/docs/reference/result/#result><code>result</code></a> type holds, use the <code>is_ok()</code> and <code>is_err()</code> functions. The success or failure value can be retrieved using <code>unwrap()</code> and <code>unwrap_err()</code>, respectively. If <code>unwrap</code> fails, it throws a <code>bad_result_access</code> exception. Using the <code>as_ok()</code> and <code>as_err()</code> functions does not throw exceptions on failure, but results in undefined behavior.</p><blockquote class="book-hint warning"><p>Although <code>try_parse</code> does not throw <code>syntax_error</code> or <code>file_io_error</code>, it returns the same <code>toml::error_info</code> as the failure type in the <code>result</code>. However, it is not entirely exception-free.</p><p>If an internal standard library error occurs, such as <code>std::bad_alloc</code> when a <code>vector</code> fails to allocate memory, <code>toml::try_parse</code> does not catch this and will let it propagate. Thus, exceptions originating from the standard library may still be thrown.</p></blockquote><h2 id=parsing-strings>Parsing Strings
|
||||
<a class=anchor href=#parsing-strings>#</a></h2><h3 id=tomlparse_str><code>toml::parse_str</code>
|
||||
<a class=anchor href=#tomlparse_str>#</a></h3><p><a href=https://toruniina.github.io/toml11/docs/reference/parser/#parse_str><code>toml::parse_str</code></a> accepts the string to be parsed directly, instead of a filename.</p><p>For the part of the error message that corresponds to the TOML file’s name, if the <code>std::source_location</code> equivalent compiler extension is available, the name and line number of the C++ file that called <code>parse_str</code> will be used instead.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><toml.hpp></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><iostream></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value input <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>parse_str(<span style=color:#e6db74>"title = </span><span style=color:#ae81ff>\"</span><span style=color:#e6db74>parse_str</span><span style=color:#ae81ff>\"</span><span style=color:#e6db74>"</span>);
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>cout <span style=color:#f92672><<</span> input.at(<span style=color:#e6db74>"title"</span>).as_string() <span style=color:#f92672><<</span> std<span style=color:#f92672>::</span>endl;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><h3 id=tomltry_parse_str><code>toml::try_parse_str</code>
|
||||
<a class=anchor href=#tomltry_parse_str>#</a></h3><p><a href=https://toruniina.github.io/toml11/docs/reference/parser/#try_parse_str><code>toml::try_parse_str</code></a> also takes the string to be parsed directly, similar to <code>parse_str</code>. Like <code>try_parse</code>, it uses <a href=https://toruniina.github.io/toml11/docs/reference/result/#result><code>toml::result</code></a> to report errors.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><toml.hpp></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><iostream></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> parse_result <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>try_parse_str(<span style=color:#e6db74>"title = </span><span style=color:#ae81ff>\"</span><span style=color:#e6db74>parse_str</span><span style=color:#ae81ff>\"</span><span style=color:#e6db74>"</span>);
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>if</span>(parse_result.is_ok())
|
||||
</span></span><span style=display:flex><span> {
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>cout <span style=color:#f92672><<</span> parse_result.unwrap().at(<span style=color:#e6db74>"title"</span>).as_string() <span style=color:#f92672><<</span> std<span style=color:#f92672>::</span>endl;
|
||||
</span></span><span style=display:flex><span> }
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>else</span>
|
||||
</span></span><span style=display:flex><span> {
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>cerr <span style=color:#f92672><<</span> parse_result.unwrap_err().at(<span style=color:#ae81ff>0</span>) <span style=color:#f92672><<</span> std<span style=color:#f92672>::</span>endl;
|
||||
</span></span><span style=display:flex><span> }
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><h2 id=parsing-byte-arrays>Parsing Byte Arrays
|
||||
<a class=anchor href=#parsing-byte-arrays>#</a></h2><p>It is also possible to parse byte arrays instead of files.</p><p>Since the byte arrays must be encoded in UTF-8, <code>unsigned char</code> is used.</p><h3 id=tomlparsestdvectorunsigned-char><code>toml::parse(std::vector<unsigned char>)</code>
|
||||
<a class=anchor href=#tomlparsestdvectorunsigned-char>#</a></h3><p>The behavior is the same as <a href=https://toruniina.github.io/toml11/docs/reference/parser/#parse><code>toml::parse</code></a>.</p><p>When parsing byte arrays, a <code>filename</code> is required.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><toml.hpp></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><iostream></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span><span style=color:#66d9ef>unsigned</span> <span style=color:#66d9ef>char</span><span style=color:#f92672>></span> bytes{<span style=color:#75715e>/* ... */</span>};
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value input <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>parse(bytes, <span style=color:#e6db74>"internal bytes"</span>);
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>cout <span style=color:#f92672><<</span> input.at(<span style=color:#e6db74>"title"</span>).as_string() <span style=color:#f92672><<</span> std<span style=color:#f92672>::</span>endl;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><h3 id=tomltry_parsestdvectorunsigned-char><code>toml::try_parse(std::vector<unsigned char>)</code>
|
||||
<a class=anchor href=#tomltry_parsestdvectorunsigned-char>#</a></h3><p>The behavior is the same as <a href=https://toruniina.github.io/toml11/docs/reference/parser/#try_parse><code>toml::try_parse</code></a>.</p><p>When parsing byte arrays, a <code>filename</code> is required.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><toml.hpp></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><iostream></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span><span style=color:#66d9ef>unsigned</span> <span style=color:#66d9ef>char</span><span style=color:#f92672>></span> bytes{<span style=color:#75715e>/* ... */</span>};
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> parse_result <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>try_parse(bytes, <span style=color:#e6db74>"internal bytes"</span>);
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>if</span>(parse_result.is_ok())
|
||||
</span></span><span style=display:flex><span> {
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>cout <span style=color:#f92672><<</span> parse_result.unwrap().at(<span style=color:#e6db74>"title"</span>).as_string() <span style=color:#f92672><<</span> std<span style=color:#f92672>::</span>endl;
|
||||
</span></span><span style=display:flex><span> }
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>else</span>
|
||||
</span></span><span style=display:flex><span> {
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>cerr <span style=color:#f92672><<</span> parse_result.unwrap_err().at(<span style=color:#ae81ff>0</span>) <span style=color:#f92672><<</span> std<span style=color:#f92672>::</span>endl;
|
||||
</span></span><span style=display:flex><span> }
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#parsing-files-and-strings>Parsing Files and Strings</a><ul><li><a href=#parsing-files>Parsing Files</a><ul><li><a href=#tomlparse><code>toml::parse</code></a></li><li><a href=#tomltry_parse><code>toml::try_parse</code></a></li></ul></li><li><a href=#parsing-strings>Parsing Strings</a><ul><li><a href=#tomlparse_str><code>toml::parse_str</code></a></li><li><a href=#tomltry_parse_str><code>toml::try_parse_str</code></a></li></ul></li><li><a href=#parsing-byte-arrays>Parsing Byte Arrays</a><ul><li><a href=#tomlparsestdvectorunsigned-char><code>toml::parse(std::vector<unsigned char>)</code></a></li><li><a href=#tomltry_parsestdvectorunsigned-char><code>toml::try_parse(std::vector<unsigned char>)</code></a></li></ul></li></ul></li></ul></nav></div></aside></main></body></html>
|
||||
125
docs/features/serialize/index.html
Normal file
125
docs/features/serialize/index.html
Normal file
@@ -0,0 +1,125 @@
|
||||
<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content='
|
||||
Outputting TOML Files
|
||||
#
|
||||
|
||||
Using toml::format, you can convert a toml::value to a string.
|
||||
#include <toml.hpp>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
const toml::value v(toml::table{
|
||||
{"a", 42},
|
||||
{"b", "foo"},
|
||||
});
|
||||
const std::string s = toml::format(v);
|
||||
|
||||
const toml::value u = toml::parse_str(s);
|
||||
|
||||
assert(u.at("a").as_integer() == 42);
|
||||
assert(u.at("b").as_string() == "foo");
|
||||
|
||||
return 0;
|
||||
}
|
||||
If the toml::value contains a table_type, it is interpreted as the root table of the file.
|
||||
If a toml::value containing anything other than table_type is passed, only that value is formatted.'><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/features/serialize/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="serializing values"><meta property="og:description" content='Outputting TOML Files # Using toml::format, you can convert a toml::value to a string.
|
||||
#include <toml.hpp> #include <cassert> int main() { const toml::value v(toml::table{ {"a", 42}, {"b", "foo"}, }); const std::string s = toml::format(v); const toml::value u = toml::parse_str(s); assert(u.at("a").as_integer() == 42); assert(u.at("b").as_string() == "foo"); return 0; } If the toml::value contains a table_type, it is interpreted as the root table of the file.
|
||||
If a toml::value containing anything other than table_type is passed, only that value is formatted.'><meta property="og:locale" content="en"><meta property="og:type" content="article"><meta property="article:section" content="docs"><title>serializing values | toml11</title><link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/features/serialize/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/features/serialize/ title="serializing values"><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" crossorigin=anonymous></script></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
|
||||
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
|
||||
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
|
||||
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/features/serialize/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle checked>
|
||||
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/ class=active>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle>
|
||||
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
|
||||
</label><strong>serializing values</strong>
|
||||
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#outputting-toml-files>Outputting TOML Files</a><ul><li><a href=#outputting-with-keys>Outputting with Keys</a></li><li><a href=#specifying-formats>Specifying Formats</a><ul><li><a href=#specifying-integer-formats>Specifying Integer Formats</a></li><li><a href=#single-line-and-multi-line-arrays>Single-Line and Multi-Line Arrays</a></li><li><a href=#inline-tables>Inline Tables</a></li></ul></li><li><a href=#specifying-the-toml-language-version-for-output>Specifying the TOML Language Version for Output</a></li></ul></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=outputting-toml-files>Outputting TOML Files
|
||||
<a class=anchor href=#outputting-toml-files>#</a></h1><p>Using <code>toml::format</code>, you can convert a <code>toml::value</code> to a string.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><toml.hpp></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><cassert></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value v(toml<span style=color:#f92672>::</span>table{
|
||||
</span></span><span style=display:flex><span> {<span style=color:#e6db74>"a"</span>, <span style=color:#ae81ff>42</span>},
|
||||
</span></span><span style=display:flex><span> {<span style=color:#e6db74>"b"</span>, <span style=color:#e6db74>"foo"</span>},
|
||||
</span></span><span style=display:flex><span> });
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string s <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>format(v);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value u <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>parse_str(s);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> assert(u.at(<span style=color:#e6db74>"a"</span>).as_integer() <span style=color:#f92672>==</span> <span style=color:#ae81ff>42</span>);
|
||||
</span></span><span style=display:flex><span> assert(u.at(<span style=color:#e6db74>"b"</span>).as_string() <span style=color:#f92672>==</span> <span style=color:#e6db74>"foo"</span>);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>If the <code>toml::value</code> contains a <code>table_type</code>, it is interpreted as the root table of the file.</p><p>If a <code>toml::value</code> containing anything other than <code>table_type</code> is passed, only that value is formatted.</p><p>Certain format specifications may require a key to be provided for formatting. For example, <code>toml::array_format::array_of_tables</code> formats as <code>[[array.of.tables]]</code>, which requires key access.</p><p>If a format specification that requires a key is provided without a key, a <code>toml::serialization_error</code> is thrown.</p><p>Additionally, if there are values that contradict the format specification, a <code>toml::serialization_error</code> is thrown. For instance, specifying <code>integer_format::hex</code> for a negative integer, or <code>string_format::literal</code> for a string containing newlines, will cause an error.</p><p>The method for specifying formats is explained later.</p><h2 id=outputting-with-keys>Outputting with Keys
|
||||
<a class=anchor href=#outputting-with-keys>#</a></h2><p>You can pass a key to <code>toml::format</code> as a <code>std::string</code>.</p><p>In this case, the key is considered to be under the root table, and the passed value corresponds to that key.</p><p>For nested keys, you can pass a <code>std::vector<std::string></code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><toml.hpp></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><cassert></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value v(toml<span style=color:#f92672>::</span>table{
|
||||
</span></span><span style=display:flex><span> {<span style=color:#e6db74>"a"</span>, <span style=color:#ae81ff>42</span>},
|
||||
</span></span><span style=display:flex><span> {<span style=color:#e6db74>"b"</span>, <span style=color:#e6db74>"foo"</span>},
|
||||
</span></span><span style=display:flex><span> });
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string s <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>format(<span style=color:#e6db74>"bar"</span>, v);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value u <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>parse_str(s);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> assert(u.at(<span style=color:#e6db74>"bar"</span>).at(<span style=color:#e6db74>"a"</span>).as_integer() <span style=color:#f92672>==</span> <span style=color:#ae81ff>42</span>);
|
||||
</span></span><span style=display:flex><span> assert(u.at(<span style=color:#e6db74>"bar"</span>).at(<span style=color:#e6db74>"b"</span>).as_string() <span style=color:#f92672>==</span> <span style=color:#e6db74>"foo"</span>);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><h2 id=specifying-formats>Specifying Formats
|
||||
<a class=anchor href=#specifying-formats>#</a></h2><p>Each type in <code>toml::value</code> has a corresponding format information type.</p><p>For <code>toml::value::integer_type</code>, there is <code>toml::integer_format_info</code>.
|
||||
For <code>toml::value::table_type</code>, there is <code>toml::table_format_info</code>.</p><p>These format information types are set when parsing and are retained even if the value is changed, as long as the type remains the same.</p><p>You can access and directly edit these formats using member functions like <code>as_integer_fmt()</code> or <code>as_table_fmt()</code>.</p><p>Below are some examples explaining how to use these formats.</p><p>For more details on how to access formats, refer to the <a href=https://toruniina.github.io/toml11/docs/reference/value/><code>toml::value</code> reference</a>. For a complete list and detailed information on format information classes, see the <a href=https://toruniina.github.io/toml11/docs/reference/format/>format reference</a>.</p><h3 id=specifying-integer-formats>Specifying Integer Formats
|
||||
<a class=anchor href=#specifying-integer-formats>#</a></h3><p>For integers, you can specify the radix, width, and the position of <code>_</code>.</p><p>When using <code>hex</code>, <code>oct</code>, or <code>bin</code>, values are padded with zeros until the specified width is reached. For <code>dec</code>, the width specification adds spaces, which are not parsed.</p><p>For more details, see the <a href=https://toruniina.github.io/toml11/docs/reference/format/#integer_format>integer format reference</a>.</p><h3 id=single-line-and-multi-line-arrays>Single-Line and Multi-Line Arrays
|
||||
<a class=anchor href=#single-line-and-multi-line-arrays>#</a></h3><p>For arrays, you can specify <code>toml::array_format::oneline</code> or <code>toml::array_format::multiline</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-toml data-lang=toml><span style=display:flex><span><span style=color:#75715e># oneline</span>
|
||||
</span></span><span style=display:flex><span><span style=color:#a6e22e>a</span> = [<span style=color:#ae81ff>1</span>, <span style=color:#ae81ff>2</span>, <span style=color:#ae81ff>3</span>, <span style=color:#ae81ff>4</span>, <span style=color:#ae81ff>5</span>]
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e># multiline</span>
|
||||
</span></span><span style=display:flex><span><span style=color:#a6e22e>a</span> = [
|
||||
</span></span><span style=display:flex><span> <span style=color:#ae81ff>1</span>,
|
||||
</span></span><span style=display:flex><span> <span style=color:#ae81ff>2</span>,
|
||||
</span></span><span style=display:flex><span> <span style=color:#ae81ff>3</span>,
|
||||
</span></span><span style=display:flex><span> <span style=color:#ae81ff>4</span>,
|
||||
</span></span><span style=display:flex><span> <span style=color:#ae81ff>5</span>
|
||||
</span></span><span style=display:flex><span>]
|
||||
</span></span></code></pre></div><p>When using <code>multiline</code>, you can specify the indentation. Each element is indented by the amount specified in <code>body_indent</code>, and the closing bracket <code>]</code> is indented by the amount specified in <code>closing_indent</code>.</p><p>The type of character used for indentation is specified by <code>indent_type</code>, and you can choose between <code>toml::indent_char::space</code> or <code>toml::indent_char::tab</code>.</p><blockquote class="book-hint warning"><p>Ensure that the same type of character is used for indentation throughout the document.</p><p>If different types of characters are specified for indentation within the same file, the result is undefined. Some form of indentation will be applied, but the type of character and the depth of the indentation may be inconsistent.</p></blockquote><p>If all elements of an <code>array</code> have <code>table_type</code>, you can specify <code>toml::array_format::array_of_tables</code>.</p><p>If you do not specify <code>array_of_tables</code> and use <code>multiline</code>, the tables will be formatted as inline tables.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-toml data-lang=toml><span style=display:flex><span><span style=color:#75715e># multiline</span>
|
||||
</span></span><span style=display:flex><span><span style=color:#a6e22e>a</span> = [
|
||||
</span></span><span style=display:flex><span> {<span style=color:#a6e22e>foo</span> = <span style=color:#ae81ff>42</span>},
|
||||
</span></span><span style=display:flex><span> {<span style=color:#a6e22e>bar</span> = <span style=color:#e6db74>"hoge"</span>},
|
||||
</span></span><span style=display:flex><span>]
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e># array_of_tables</span>
|
||||
</span></span><span style=display:flex><span>[[<span style=color:#a6e22e>a</span>]]
|
||||
</span></span><span style=display:flex><span><span style=color:#a6e22e>foo</span> = <span style=color:#ae81ff>42</span>
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span>[[<span style=color:#a6e22e>a</span>]]
|
||||
</span></span><span style=display:flex><span><span style=color:#a6e22e>bar</span> = <span style=color:#e6db74>"hoge"</span>
|
||||
</span></span></code></pre></div><p>By default, <code>toml::array_format::default_format</code> is used. This automatically selects an appropriate format.</p><p>For example, with <code>default_format</code>, if all elements are <code>table_type</code>, it will choose <code>array_of_tables</code>. Short arrays are formatted as <code>oneline</code>, while long or nested arrays, or those with complex elements, are formatted as <code>multiline</code>.</p><p>For more details, see the <a href=https://toruniina.github.io/toml11/docs/reference/format/#array_format>array format reference</a>.</p><h3 id=inline-tables>Inline Tables
|
||||
<a class=anchor href=#inline-tables>#</a></h3><p>To format a table as an inline table, specify <code>toml::table_format::oneline</code>.
|
||||
For standard tables, use <code>toml::table_format::multiline</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-toml data-lang=toml><span style=display:flex><span><span style=color:#a6e22e>oneline</span> = {<span style=color:#a6e22e>a</span> = <span style=color:#ae81ff>42</span>, <span style=color:#a6e22e>b</span> = <span style=color:#e6db74>"foo"</span>}
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span>[<span style=color:#a6e22e>multiline</span>]
|
||||
</span></span><span style=display:flex><span><span style=color:#a6e22e>a</span> = <span style=color:#ae81ff>42</span>
|
||||
</span></span><span style=display:flex><span><span style=color:#a6e22e>b</span> = <span style=color:#e6db74>"foo"</span>
|
||||
</span></span></code></pre></div><p>In TOML v1.1.0, line breaks within inline tables are allowed. In this case, use <code>toml::table_format::multiline_oneline</code>. This is only applied if the corresponding feature flag is set to <code>true</code> as per the TOML version specification described later.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-toml data-lang=toml><span style=display:flex><span><span style=color:#a6e22e>multiline_oneline</span> = {
|
||||
</span></span><span style=display:flex><span> <span style=color:#a6e22e>a</span> = <span style=color:#ae81ff>42</span>,
|
||||
</span></span><span style=display:flex><span> <span style=color:#a6e22e>b</span> = <span style=color:#e6db74>"foo"</span>
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>For more details, see the <a href=https://toruniina.github.io/toml11/docs/reference/format/#table_format>table format reference</a>.</p><h2 id=specifying-the-toml-language-version-for-output>Specifying the TOML Language Version for Output
|
||||
<a class=anchor href=#specifying-the-toml-language-version-for-output>#</a></h2><p>Certain language features, such as line breaks within inline tables and <code>\x</code> escape sequences, are only available after TOML v1.1.0.</p><p>The <code>toml::format</code> function accepts a <code>toml::spec</code> as its argument.</p><p>This allows you to specify the version of TOML to use during serialization.</p><p>When you use <code>toml::parse</code> with a <code>toml::spec</code> to leverage new features,
|
||||
the parsed values may contain format information that is only compatible with that specific version.
|
||||
Ensure that you pass the same <code>toml::spec</code> to <code>toml::format</code> to maintain compatibility.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><toml.hpp></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><iostream></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> spec <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>spec<span style=color:#f92672>::</span>v(<span style=color:#ae81ff>1</span>, <span style=color:#ae81ff>1</span>, <span style=color:#ae81ff>0</span>);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value v <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>parse(<span style=color:#e6db74>"input.toml"</span>, spec);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>cout <span style=color:#f92672><<</span> toml<span style=color:#f92672>::</span>format(v, spec) <span style=color:#f92672><<</span> std<span style=color:#f92672>::</span>endl;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#outputting-toml-files>Outputting TOML Files</a><ul><li><a href=#outputting-with-keys>Outputting with Keys</a></li><li><a href=#specifying-formats>Specifying Formats</a><ul><li><a href=#specifying-integer-formats>Specifying Integer Formats</a></li><li><a href=#single-line-and-multi-line-arrays>Single-Line and Multi-Line Arrays</a></li><li><a href=#inline-tables>Inline Tables</a></li></ul></li><li><a href=#specifying-the-toml-language-version-for-output>Specifying the TOML Language Version for Output</a></li></ul></li></ul></nav></div></aside></main></body></html>
|
||||
82
docs/features/toml_spec/index.html
Normal file
82
docs/features/toml_spec/index.html
Normal file
@@ -0,0 +1,82 @@
|
||||
<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
|
||||
TOML Language Version
|
||||
#
|
||||
|
||||
You can specify the version of the TOML language and individual feature flags to use with toml::parse or toml::format through toml::spec.
|
||||
|
||||
Specifying TOML Version
|
||||
#
|
||||
|
||||
You can construct a toml::spec from toml::semantic_version.
|
||||
#include <toml.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
toml::spec spec(toml::semantic_version(1, 1, 0));
|
||||
return 0;
|
||||
}
|
||||
However, to make this shorter, the toml::spec::v() function is provided.
|
||||
#include <toml.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
toml::spec spec = toml::spec::v(1, 1, 0);
|
||||
return 0;
|
||||
}
|
||||
If not specified explicitly, toml::spec::default_version() is used to construct with default values."><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/features/toml_spec/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="toml spec"><meta property="og:description" content="TOML Language Version # You can specify the version of the TOML language and individual feature flags to use with toml::parse or toml::format through toml::spec.
|
||||
Specifying TOML Version # You can construct a toml::spec from toml::semantic_version.
|
||||
#include <toml.hpp> int main() { toml::spec spec(toml::semantic_version(1, 1, 0)); return 0; } However, to make this shorter, the toml::spec::v() function is provided.
|
||||
#include <toml.hpp> int main() { toml::spec spec = toml::spec::v(1, 1, 0); return 0; } If not specified explicitly, toml::spec::default_version() is used to construct with default values."><meta property="og:locale" content="en"><meta property="og:type" content="article"><meta property="article:section" content="docs"><title>toml spec | toml11</title><link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/features/toml_spec/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/features/toml_spec/ title="toml spec"><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" crossorigin=anonymous></script></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
|
||||
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
|
||||
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
|
||||
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/features/toml_spec/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle checked>
|
||||
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/ class=active>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle>
|
||||
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
|
||||
</label><strong>toml spec</strong>
|
||||
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#toml-language-version>TOML Language Version</a><ul><li><a href=#specifying-toml-version>Specifying TOML Version</a><ul><li><a href=#parsing-with-version-specification>Parsing with Version Specification</a></li><li><a href=#serializing-with-version-specification>Serializing with Version Specification</a></li></ul></li><li><a href=#specifying-newly-added-features-in-toml>Specifying Newly Added Features in TOML</a></li></ul></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=toml-language-version>TOML Language Version
|
||||
<a class=anchor href=#toml-language-version>#</a></h1><p>You can specify the version of the TOML language and individual feature flags to use with <code>toml::parse</code> or <code>toml::format</code> through <a href=https://toruniina.github.io/toml11/docs/reference/spec/#tomlspec><code>toml::spec</code></a>.</p><h2 id=specifying-toml-version>Specifying TOML Version
|
||||
<a class=anchor href=#specifying-toml-version>#</a></h2><p>You can construct a <a href=https://toruniina.github.io/toml11/docs/reference/spec/#tomlspec><code>toml::spec</code></a> from <a href=https://toruniina.github.io/toml11/docs/reference/spec/#tomlsemantic_version><code>toml::semantic_version</code></a>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><toml.hpp></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> toml<span style=color:#f92672>::</span>spec spec(toml<span style=color:#f92672>::</span>semantic_version(<span style=color:#ae81ff>1</span>, <span style=color:#ae81ff>1</span>, <span style=color:#ae81ff>0</span>));
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>However, to make this shorter, the <code>toml::spec::v()</code> function is provided.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><toml.hpp></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> toml<span style=color:#f92672>::</span>spec spec <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>spec<span style=color:#f92672>::</span>v(<span style=color:#ae81ff>1</span>, <span style=color:#ae81ff>1</span>, <span style=color:#ae81ff>0</span>);
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>If not specified explicitly, <code>toml::spec::default_version()</code> is used to construct with default values.</p><p>The default value depends on the version of toml11 and follows the latest version of the TOML language released at that time.</p><p>As of v4.4.0, TOML v1.1.0 has not been released yet, so the default TOML version is v1.0.0.</p><blockquote class="book-hint warning"><p>Some features of TOML v1.1.0 are still under fairly lengthy discussion and may still be reverted.</p><p>If they are indeed reverted, toml11 will remove those features in a minor version upgrade or move them to a corresponding later version.</p><p>As such, any features related to future versions should be considered unstable.</p></blockquote><h3 id=parsing-with-version-specification>Parsing with Version Specification
|
||||
<a class=anchor href=#parsing-with-version-specification>#</a></h3><p>The overload of <a href=https://toruniina.github.io/toml11/docs/reference/parser/#parse><code>toml::parse</code></a> takes a <code>toml::spec</code> following the file name.</p><p>This allows you to change the TOML version being used.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><toml.hpp></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> toml<span style=color:#f92672>::</span>value input <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>parse(<span style=color:#e6db74>"input.toml"</span>, toml<span style=color:#f92672>::</span>spec<span style=color:#f92672>::</span>v(<span style=color:#ae81ff>1</span>, <span style=color:#ae81ff>1</span>, <span style=color:#ae81ff>0</span>));
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><h3 id=serializing-with-version-specification>Serializing with Version Specification
|
||||
<a class=anchor href=#serializing-with-version-specification>#</a></h3><p>The overload of <a href=https://toruniina.github.io/toml11/docs/reference/serializer/><code>toml::format</code></a> takes a <code>toml::spec</code> following the <code>toml::value</code>.</p><p>This allows you to change the TOML version being used.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><toml.hpp></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> toml<span style=color:#f92672>::</span>value v <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>parse(<span style=color:#e6db74>"input.toml"</span>, toml<span style=color:#f92672>::</span>spec<span style=color:#f92672>::</span>v(<span style=color:#ae81ff>1</span>, <span style=color:#ae81ff>1</span>, <span style=color:#ae81ff>0</span>));
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>cout <span style=color:#f92672><<</span> toml<span style=color:#f92672>::</span>format(v, toml<span style=color:#f92672>::</span>spec<span style=color:#f92672>::</span>v(<span style=color:#ae81ff>1</span>, <span style=color:#ae81ff>1</span>, <span style=color:#ae81ff>0</span>)) <span style=color:#f92672><<</span> std<span style=color:#f92672>::</span>endl;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>If a format is passed that is not permitted by the provided <code>toml::spec</code>, it will be ignored, and another format will be used as a fallback.</p><h2 id=specifying-newly-added-features-in-toml>Specifying Newly Added Features in TOML
|
||||
<a class=anchor href=#specifying-newly-added-features-in-toml>#</a></h2><p>With version upgrades in TOML, multiple new features are introduced, and it’s possible to enable only some of them.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><toml.hpp></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> toml<span style=color:#f92672>::</span>spec spec <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>spec<span style=color:#f92672>::</span>v(<span style=color:#ae81ff>1</span>, <span style=color:#ae81ff>0</span>, <span style=color:#ae81ff>0</span>);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#75715e>// Allowing newlines in inline tables
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span> spec.v1_1_0_allow_newlines_in_inline_tables <span style=color:#f92672>=</span> true;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> toml<span style=color:#f92672>::</span>value input <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>parse(<span style=color:#e6db74>"input.toml"</span>, spec);
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>For a full list of all flags, refer to <a href=https://toruniina.github.io/toml11/docs/reference/spec/#tomlspec><code>toml::spec</code></a>.</p></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#toml-language-version>TOML Language Version</a><ul><li><a href=#specifying-toml-version>Specifying TOML Version</a><ul><li><a href=#parsing-with-version-specification>Parsing with Version Specification</a></li><li><a href=#serializing-with-version-specification>Serializing with Version Specification</a></li></ul></li><li><a href=#specifying-newly-added-features-in-toml>Specifying Newly Added Features in TOML</a></li></ul></li></ul></nav></div></aside></main></body></html>
|
||||
439
docs/features/value/index.html
Normal file
439
docs/features/value/index.html
Normal file
@@ -0,0 +1,439 @@
|
||||
<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
|
||||
Retrieving Values
|
||||
#
|
||||
|
||||
This section explains how to access the values stored in toml::value.
|
||||
|
||||
Accessing Values Using Member Functions
|
||||
#
|
||||
|
||||
|
||||
is_something and as_something
|
||||
#
|
||||
|
||||
toml::value has member functions like is_boolean() and is_integer() which allow you to check the type of the stored value.
|
||||
Additionally, it has member functions like as_boolean() and as_integer() that allow you to access the value of that type.
|
||||
For a complete list, refer to the toml::value reference."><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/features/value/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="getting values"><meta property="og:description" content="Retrieving Values # This section explains how to access the values stored in toml::value.
|
||||
Accessing Values Using Member Functions # is_something and as_something # toml::value has member functions like is_boolean() and is_integer() which allow you to check the type of the stored value.
|
||||
Additionally, it has member functions like as_boolean() and as_integer() that allow you to access the value of that type.
|
||||
For a complete list, refer to the toml::value reference."><meta property="og:locale" content="en"><meta property="og:type" content="article"><meta property="article:section" content="docs"><title>getting values | toml11</title><link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/features/value/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/features/value/ title="getting values"><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" crossorigin=anonymous></script></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
|
||||
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
|
||||
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
|
||||
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/features/value/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle checked>
|
||||
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/ class=active>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle>
|
||||
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
|
||||
</label><strong>getting values</strong>
|
||||
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#retrieving-values>Retrieving Values</a><ul><li><a href=#accessing-values-using-member-functions>Accessing Values Using Member Functions</a><ul><li><a href=#is_something-and-as_something><code>is_something</code> and <code>as_something</code></a></li><li><a href=#tomlvalue_t><code>toml::value_t</code></a></li><li><a href=#at--contains-size-push_back-emplace_back><code>at</code>, <code>[]</code>, <code>contains</code>, <code>size</code>, <code>push_back</code>, <code>emplace_back</code></a></li></ul></li><li><a href=#accessing-comments>Accessing Comments</a></li><li><a href=#handling-inline-tables-and-dotted-keys>Handling Inline Tables and Dotted Keys</a></li><li><a href=#handling-date-and-time-information>Handling Date and Time Information</a></li><li><a href=#converting-using-tomlgett>Converting Using <code>toml::get<T></code></a><ul><li><a href=#simple-conversions>Simple Conversions</a></li><li><a href=#conditions-for-obtaining-references>Conditions for Obtaining References</a></li><li><a href=#converting-arrays-to-stl-containers>Converting Arrays to STL Containers</a></li><li><a href=#converting-arrays-to-stdpair-or-stdtuple>Converting Arrays to <code>std::pair</code> or <code>std::tuple</code></a></li><li><a href=#converting-nested-arrays>Converting Nested Arrays</a></li><li><a href=#converting-tables-to-stdmap>Converting Tables to <code>std::map</code></a></li></ul></li><li><a href=#using-tomlget_or-to-specify-a-value-on-failure>Using <code>toml::get_or</code> to Specify a Value on Failure</a></li><li><a href=#using-tomlfindt-to-search-and-convert-simultaneously>Using <code>toml::find<T></code> to Search and Convert Simultaneously</a></li><li><a href=#using-tomlfind_or-to-search-and-specify-a-value-on-failure>Using <code>toml::find_or</code> to Search and Specify a Value on Failure</a></li><li><a href=#using-tomlfind_or_default-to-search-and-use-the-default-value-on-failure>Using <code>toml::find_or_default</code> to Search and Use the Default Value on Failure</a></li><li><a href=#tomlfindstdoptionalt><code>toml::find<std::optional<T>></code></a></li><li><a href=#defining-conversions-for-user-defined-types>Defining Conversions for User-Defined Types</a><ul><li><a href=#defining-tomlfrom>Defining <code>toml::from</code></a></li><li><a href=#defining-a-from_toml-member-function>Defining a <code>from_toml</code> Member Function</a></li><li><a href=#constructor-accepting-tomlvalue>Constructor Accepting <code>toml::value</code></a></li></ul></li><li><a href=#applying-functions-with-tomlvisit>Applying Functions with <code>toml::visit</code></a></li><li><a href=#constructing-tomlvalue>Constructing <code>toml::value</code></a></li><li><a href=#converting-to-tomlvalue>Converting to <code>toml::value</code></a><ul><li><a href=#defining-tomlinto>Defining <code>toml::into</code></a></li><li><a href=#defining-into_toml-member-function>Defining <code>into_toml</code> Member Function</a></li></ul></li></ul></li><li><a href=#checking-whether-a-value-has-been-accessed>Checking Whether a Value Has Been Accessed</a></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=retrieving-values>Retrieving Values
|
||||
<a class=anchor href=#retrieving-values>#</a></h1><p>This section explains how to access the values stored in <code>toml::value</code>.</p><h2 id=accessing-values-using-member-functions>Accessing Values Using Member Functions
|
||||
<a class=anchor href=#accessing-values-using-member-functions>#</a></h2><h3 id=is_something-and-as_something><code>is_something</code> and <code>as_something</code>
|
||||
<a class=anchor href=#is_something-and-as_something>#</a></h3><p><code>toml::value</code> has member functions like <code>is_boolean()</code> and <code>is_integer()</code> which allow you to check the type of the stored value.</p><p>Additionally, it has member functions like <code>as_boolean()</code> and <code>as_integer()</code> that allow you to access the value of that type.</p><p>For a complete list, refer to the <a href=https://toruniina.github.io/toml11/docs/reference/value/#is_xxx><code>toml::value</code> reference</a>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>toml<span style=color:#f92672>::</span>value v <span style=color:#f92672>=</span> <span style=color:#75715e>/* ... */</span>;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>if</span>(v.is_string())
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>cout <span style=color:#f92672><<</span> v.as_string() <span style=color:#f92672><<</span> std<span style=color:#f92672>::</span>endl;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>If the stored value is of a different type than specified, a <a href=https://toruniina.github.io/toml11/docs/reference/value/#tomltype_error><code>toml::type_error</code></a> is thrown.</p><p>The <code>what()</code> method will contain a message like the following:</p><pre tabindex=0><code>[error] toml::value::as_string(): bad_cast to string
|
||||
--> input.toml
|
||||
|
|
||||
1 | a = 123_456
|
||||
| ^^^^^^^-- the actual type is integer
|
||||
</code></pre><h3 id=tomlvalue_t><code>toml::value_t</code>
|
||||
<a class=anchor href=#tomlvalue_t>#</a></h3><p>Type information can be identified using <a href=https://toruniina.github.io/toml11/docs/reference/value_t/><code>enum class toml::value_t</code></a>.</p><p>The <a href=https://toruniina.github.io/toml11/docs/reference/value/#type><code>type()</code></a> member function returns the type information of the currently stored value.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>toml<span style=color:#f92672>::</span>value v <span style=color:#f92672>=</span> <span style=color:#75715e>/* ... */</span>;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>switch</span>(v.type())
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>case</span> toml:value_t<span style=color:#f92672>::</span>empty : { <span style=color:#75715e>/*...*/</span> <span style=color:#66d9ef>break</span>; }
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>case</span> toml:value_t<span style=color:#f92672>::</span>boolean : { <span style=color:#75715e>/*...*/</span> <span style=color:#66d9ef>break</span>; }
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>case</span> toml:value_t<span style=color:#f92672>::</span>integer : { <span style=color:#75715e>/*...*/</span> <span style=color:#66d9ef>break</span>; }
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>case</span> toml:value_t<span style=color:#f92672>::</span>floating : { <span style=color:#75715e>/*...*/</span> <span style=color:#66d9ef>break</span>; }
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>case</span> toml:value_t<span style=color:#f92672>::</span>string : { <span style=color:#75715e>/*...*/</span> <span style=color:#66d9ef>break</span>; }
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>case</span> toml:value_t<span style=color:#f92672>::</span>offset_datetime: { <span style=color:#75715e>/*...*/</span> <span style=color:#66d9ef>break</span>; }
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>case</span> toml:value_t<span style=color:#f92672>::</span>local_datetime : { <span style=color:#75715e>/*...*/</span> <span style=color:#66d9ef>break</span>; }
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>case</span> toml:value_t<span style=color:#f92672>::</span>local_date : { <span style=color:#75715e>/*...*/</span> <span style=color:#66d9ef>break</span>; }
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>case</span> toml:value_t<span style=color:#f92672>::</span>local_time : { <span style=color:#75715e>/*...*/</span> <span style=color:#66d9ef>break</span>; }
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>case</span> toml:value_t<span style=color:#f92672>::</span>array : { <span style=color:#75715e>/*...*/</span> <span style=color:#66d9ef>break</span>; }
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>case</span> toml:value_t<span style=color:#f92672>::</span>table : { <span style=color:#75715e>/*...*/</span> <span style=color:#66d9ef>break</span>; }
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>default</span><span style=color:#f92672>:</span> {<span style=color:#66d9ef>break</span>;}
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>The <a href=https://toruniina.github.io/toml11/docs/reference/value/#istomlvalue_t><code>is(toml::value_t)</code></a> member function returns <code>true</code> if the stored value is of the given <code>value_t</code> type, otherwise it returns <code>false</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>toml<span style=color:#f92672>::</span>value v <span style=color:#f92672>=</span> <span style=color:#75715e>/* ... */</span>;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>if</span>(v.is(toml<span style=color:#f92672>::</span>value_t<span style=color:#f92672>::</span>integer))
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>cout <span style=color:#f92672><<</span> v.as_integer() <span style=color:#f92672><<</span> std<span style=color:#f92672>::</span>endl;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><h3 id=at--contains-size-push_back-emplace_back><code>at</code>, <code>[]</code>, <code>contains</code>, <code>size</code>, <code>push_back</code>, <code>emplace_back</code>
|
||||
<a class=anchor href=#at--contains-size-push_back-emplace_back>#</a></h3><p><code>toml::value</code> provides some member functions similar to those of standard library containers.</p><p>These functions internally convert <code>toml::value</code> to the corresponding type and call the respective member functions.</p><h4 id=atstdsize_t-i-operatorstdsize_t-i><code>at(std::size_t i)</code>, <code>operator[](std::size_t i)</code>
|
||||
<a class=anchor href=#atstdsize_t-i-operatorstdsize_t-i>#</a></h4><p>These are equivalent to <code>as_array().at(i)</code> and <code>as_array()[i]</code>.</p><p><code>toml::value</code> uses <code>std::vector<toml::value></code> as <code>array_type</code> by default, so <code>at</code> throws <code>std::out_of_range</code> on error, while <code>operator[]</code> results in undefined behavior.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>toml<span style=color:#f92672>::</span>value v(toml<span style=color:#f92672>::</span>array{<span style=color:#ae81ff>1</span>,<span style=color:#ae81ff>2</span>,<span style=color:#ae81ff>3</span>});
|
||||
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>cout <span style=color:#f92672><<</span> v.at(<span style=color:#ae81ff>1</span>);
|
||||
</span></span></code></pre></div><p>If the stored type is not <code>array_type</code>, a <code>type_error</code> is thrown.</p><h4 id=atstdstring-key-operatorstdstring-key><code>at(std::string key)</code>, <code>operator[](std::string key)</code>
|
||||
<a class=anchor href=#atstdstring-key-operatorstdstring-key>#</a></h4><p>These are equivalent to <code>as_table().at(key)</code> and <code>as_table()[key]</code>.</p><p><code>toml::value</code> uses <code>std::unordered_map<std::string, toml::value></code> as <code>table_type</code> by default, so if the corresponding value does not exist, <code>at</code> throws <code>std::out_of_range</code>, while <code>operator[]</code> constructs a new <code>toml::value</code> and returns a reference to it. Therefore, there is no <code>const</code> version of <code>operator[]</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>toml<span style=color:#f92672>::</span>value v(toml<span style=color:#f92672>::</span>table{});
|
||||
</span></span><span style=display:flex><span>v[<span style=color:#e6db74>"a"</span>] <span style=color:#f92672>=</span> <span style=color:#ae81ff>42</span>;
|
||||
</span></span></code></pre></div><p>If the stored type is not <code>table_type</code>, a <code>type_error</code> is thrown.</p><h4 id=size><code>size()</code>
|
||||
<a class=anchor href=#size>#</a></h4><p>Returns the length.</p><p>For <code>array_type</code> or <code>table_type</code>, it returns the number of elements; for <code>string_type</code>, it returns the number of characters (in bytes).</p><p>If the stored type is none of these, a <code>type_error</code> is thrown.</p><h4 id=push_back-emplace_back><code>push_back()</code>, <code>emplace_back()</code>
|
||||
<a class=anchor href=#push_back-emplace_back>#</a></h4><p>These are equivalent to <code>as_array().push_back()</code> and <code>as_array().emplace_back()</code>.</p><p>If the stored type is not <code>array_type</code>, a <code>type_error</code> is thrown.</p><h2 id=accessing-comments>Accessing Comments
|
||||
<a class=anchor href=#accessing-comments>#</a></h2><p>In toml11, comments are parsed by default and saved line by line with the corresponding value.</p><p>A comment corresponds to the value that comes immediately after the consecutive lines of comments, or to the value on the same line as the comment.</p><p>If there is no value immediately before or after the comment, it is not associated with any value and is ignored.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-toml data-lang=toml><span style=display:flex><span><span style=color:#75715e># input.toml</span>
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e># This is a comment about a.</span>
|
||||
</span></span><span style=display:flex><span><span style=color:#a6e22e>a</span> = <span style=color:#ae81ff>42</span>
|
||||
</span></span><span style=display:flex><span><span style=color:#a6e22e>b</span> = <span style=color:#ae81ff>3.14</span> <span style=color:#75715e># This is a comment about b.</span>
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e># This comment is ignored because it has no corresponding value.</span>
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e># This is the 1st comment about c.</span>
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e># This is the 2nd comment about c.</span>
|
||||
</span></span><span style=display:flex><span><span style=color:#a6e22e>c</span> = <span style=color:#e6db74>"foo"</span> <span style=color:#75715e># This is the final comment about c.</span>
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e># This comment is NOT a comment about c.</span>
|
||||
</span></span></code></pre></div><p>Comments corresponding to a value can be accessed using the <code>comments()</code> member function of <code>toml::value</code>.</p><p><code>comments()</code> returns a container that has the same member functions as <code>std::vector<std::string></code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> v <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>parse(<span style=color:#e6db74>"input.toml"</span>);
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span><span style=color:#f92672>&</span> a <span style=color:#f92672>=</span> v.at(<span style=color:#e6db74>"a"</span>);
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span><span style=color:#f92672>&</span> b <span style=color:#f92672>=</span> v.at(<span style=color:#e6db74>"b"</span>);
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span><span style=color:#f92672>&</span> c <span style=color:#f92672>=</span> v.at(<span style=color:#e6db74>"c"</span>);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span>assert(a.comments().size() <span style=color:#f92672>==</span> <span style=color:#ae81ff>1</span>);
|
||||
</span></span><span style=display:flex><span>assert(a.comments().at(<span style=color:#ae81ff>0</span>) <span style=color:#f92672>==</span> <span style=color:#e6db74>"# This is a comment about a."</span>);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span>assert(b.comments().size() <span style=color:#f92672>==</span> <span style=color:#ae81ff>1</span>);
|
||||
</span></span><span style=display:flex><span>assert(b.comments().at(<span style=color:#ae81ff>0</span>) <span style=color:#f92672>==</span> <span style=color:#e6db74>"# This is a comment about b."</span>);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span>assert(c.comments().size() <span style=color:#f92672>==</span> <span style=color:#ae81ff>3</span>);
|
||||
</span></span><span style=display:flex><span>assert(c.comments().at(<span style=color:#ae81ff>0</span>) <span style=color:#f92672>==</span> <span style=color:#e6db74>"# This is the 1st comment about c."</span>);
|
||||
</span></span><span style=display:flex><span>assert(c.comments().at(<span style=color:#ae81ff>1</span>) <span style=color:#f92672>==</span> <span style=color:#e6db74>"# This is the 2nd comment about c."</span>);
|
||||
</span></span><span style=display:flex><span>assert(c.comments().at(<span style=color:#ae81ff>2</span>) <span style=color:#f92672>==</span> <span style=color:#e6db74>"# This is the final comment about c."</span>);
|
||||
</span></span></code></pre></div><p>Comments related to the root table of the entire file are written at the beginning of the file.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-toml data-lang=toml><span style=display:flex><span><span style=color:#75715e># This is a comment about the root table.</span>
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e># This is also a comment about the root table.</span>
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e># This comment is ignored.</span>
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e># This is a comment about a.</span>
|
||||
</span></span><span style=display:flex><span><span style=color:#a6e22e>a</span> = <span style=color:#ae81ff>42</span>
|
||||
</span></span></code></pre></div><p>However, if a value immediately follows the initial comment, the comment is interpreted as pertaining to that value, and there are no comments for the root table.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-toml data-lang=toml><span style=display:flex><span><span style=color:#75715e># This is a comment about a.</span>
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e># This is also a comment about a.</span>
|
||||
</span></span><span style=display:flex><span><span style=color:#a6e22e>a</span> = <span style=color:#ae81ff>42</span>
|
||||
</span></span></code></pre></div><h2 id=handling-inline-tables-and-dotted-keys>Handling Inline Tables and Dotted Keys
|
||||
<a class=anchor href=#handling-inline-tables-and-dotted-keys>#</a></h2><p>An inline table is simply a table, and there is no difference in handling it compared to other tables in C++ code.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-toml data-lang=toml><span style=display:flex><span><span style=color:#a6e22e>a</span> = {<span style=color:#a6e22e>b</span> = <span style=color:#ae81ff>42</span>, <span style=color:#a6e22e>c</span> = <span style=color:#e6db74>"foo"</span>}
|
||||
</span></span></code></pre></div><p>Dotted keys are also just tables, with no difference in handling compared to other tables in C++ code.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-toml data-lang=toml><span style=display:flex><span><span style=color:#a6e22e>a</span>.<span style=color:#a6e22e>b</span> = <span style=color:#ae81ff>42</span>
|
||||
</span></span><span style=display:flex><span><span style=color:#a6e22e>a</span>.<span style=color:#a6e22e>c</span> = <span style=color:#e6db74>"foo"</span>
|
||||
</span></span></code></pre></div><p>These TOML files are identical to the following file.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-toml data-lang=toml><span style=display:flex><span>[<span style=color:#a6e22e>a</span>]
|
||||
</span></span><span style=display:flex><span><span style=color:#a6e22e>b</span> = <span style=color:#ae81ff>42</span>
|
||||
</span></span><span style=display:flex><span><span style=color:#a6e22e>c</span> = <span style=color:#e6db74>"foo"</span>
|
||||
</span></span></code></pre></div><p>Thus, they can all be processed with the exact same code.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> input <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>parse(<span style=color:#e6db74>"input.toml"</span>);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span>assert(input.at(<span style=color:#e6db74>"a"</span>).at(<span style=color:#e6db74>"b"</span>).as_integer() <span style=color:#f92672>==</span> <span style=color:#ae81ff>42</span>);
|
||||
</span></span><span style=display:flex><span>assert(input.at(<span style=color:#e6db74>"a"</span>).at(<span style=color:#e6db74>"c"</span>).as_string() <span style=color:#f92672>==</span> <span style=color:#e6db74>"foo"</span>);
|
||||
</span></span></code></pre></div><p>However, it is possible to distinguish them based on format information.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> input <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>parse(<span style=color:#e6db74>"input.toml"</span>);
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>switch</span>(input.at(<span style=color:#e6db74>"a"</span>).as_table_fmt().fmt)
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>case</span> toml<span style=color:#f92672>::</span>table_format<span style=color:#f92672>::</span>oneline:
|
||||
</span></span><span style=display:flex><span> {
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>cout <span style=color:#f92672><<</span> <span style=color:#e6db74>"inline table"</span> <span style=color:#f92672><<</span> std<span style=color:#f92672>::</span>endl;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>break</span>;
|
||||
</span></span><span style=display:flex><span> }
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>case</span> toml<span style=color:#f92672>::</span>table_format<span style=color:#f92672>::</span>multiline:
|
||||
</span></span><span style=display:flex><span> {
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>cout <span style=color:#f92672><<</span> <span style=color:#e6db74>"normal table"</span> <span style=color:#f92672><<</span> std<span style=color:#f92672>::</span>endl;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>break</span>;
|
||||
</span></span><span style=display:flex><span> }
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>case</span> toml<span style=color:#f92672>::</span>table_format<span style=color:#f92672>::</span>dotted:
|
||||
</span></span><span style=display:flex><span> {
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>cout <span style=color:#f92672><<</span> <span style=color:#e6db74>"dotted keys"</span> <span style=color:#f92672><<</span> std<span style=color:#f92672>::</span>endl;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>break</span>;
|
||||
</span></span><span style=display:flex><span> }
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>This format information is also considered during serialization, which will be described later.</p><h2 id=handling-date-and-time-information>Handling Date and Time Information
|
||||
<a class=anchor href=#handling-date-and-time-information>#</a></h2><p><a href=https://toruniina.github.io/toml11/docs/reference/datetime/#local_date><code>local_date</code></a>,
|
||||
<a href=https://toruniina.github.io/toml11/docs/reference/datetime/#local_time><code>local_time</code></a>,
|
||||
<a href=https://toruniina.github.io/toml11/docs/reference/datetime/#local_datetime><code>local_datetime</code></a>, and
|
||||
<a href=https://toruniina.github.io/toml11/docs/reference/datetime/#offset_datetime><code>offset_datetime</code></a>
|
||||
are parsed into dedicated structures with corresponding member variables in toml11.</p><p>When using these, you can directly extract the values or use <code>toml::get</code> and <code>toml::find</code> to convert them into types such as <code>std::chrono::system_clock::time_point</code> or <code>std::tm</code>.</p><h2 id=converting-using-tomlgett>Converting Using <code>toml::get<T></code>
|
||||
<a class=anchor href=#converting-using-tomlgett>#</a></h2><p><code>toml::get<T></code> is a function that converts and retrieves the value stored in <code>toml::value</code>.
|
||||
Specify the desired target type as <code>T</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value v <span style=color:#f92672>=</span> <span style=color:#75715e>/*...*/</span>;
|
||||
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>cout <span style=color:#f92672><<</span> toml<span style=color:#f92672>::</span>get<span style=color:#f92672><</span><span style=color:#66d9ef>int</span><span style=color:#f92672>></span>(v) <span style=color:#f92672><<</span> std<span style=color:#f92672>::</span>endl;
|
||||
</span></span></code></pre></div><p>The <code>toml::find<T></code> function, described later, also has the same functionality for type conversion.</p><p>If an unsupported type is specified for the stored value, a <code>toml::type_error</code> is thrown.</p><h3 id=simple-conversions>Simple Conversions
|
||||
<a class=anchor href=#simple-conversions>#</a></h3><h4 id=boolean_type>boolean_type
|
||||
<a class=anchor href=#boolean_type>#</a></h4><p>Conversion from <code>boolean_type</code> is possible only to <code>bool</code>.</p><h4 id=integer_type>integer_type
|
||||
<a class=anchor href=#integer_type>#</a></h4><p>Any type for which <code>std::is_integral<T></code> is <code>true</code>, except <code>bool</code>, can be converted from <code>integer_type</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>toml<span style=color:#f92672>::</span>value v(<span style=color:#ae81ff>42</span>);
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> u32 <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>get<span style=color:#f92672><</span>std<span style=color:#f92672>::</span><span style=color:#66d9ef>uint32_t</span><span style=color:#f92672>></span>(v);
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> i16 <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>get<span style=color:#f92672><</span><span style=color:#66d9ef>short</span><span style=color:#f92672>></span>(v);
|
||||
</span></span></code></pre></div><h4 id=floating_type>floating_type
|
||||
<a class=anchor href=#floating_type>#</a></h4><p>Any type for which <code>std::is_floating_point<T></code> is <code>true</code> can be converted from <code>floating_type</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>toml<span style=color:#f92672>::</span>value v(<span style=color:#ae81ff>3.14</span>);
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> f64 <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>get<span style=color:#f92672><</span><span style=color:#66d9ef>double</span><span style=color:#f92672>></span>(v);
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> f32 <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>get<span style=color:#f92672><</span><span style=color:#66d9ef>float</span> <span style=color:#f92672>></span>(v);
|
||||
</span></span></code></pre></div><h4 id=string_type>string_type
|
||||
<a class=anchor href=#string_type>#</a></h4><p><code>string_type</code> can be converted to <code>std::string</code>.
|
||||
From C++17 onwards, it can also be converted to <code>std::string_view</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>toml<span style=color:#f92672>::</span>value v(<span style=color:#e6db74>"foo"</span>);
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> s <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>get<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span>(v);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e>// C++17
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> sv <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>get<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string_view<span style=color:#f92672>></span>(v);
|
||||
</span></span></code></pre></div><h4 id=datetime-variants>datetime variants
|
||||
<a class=anchor href=#datetime-variants>#</a></h4><p><a href=https://toruniina.github.io/toml11/docs/reference/datetime/#local_date><code>local_date</code></a>,
|
||||
<a href=https://toruniina.github.io/toml11/docs/reference/datetime/#local_datetime><code>local_datetime</code></a>, and
|
||||
<a href=https://toruniina.github.io/toml11/docs/reference/datetime/#offset_datetime><code>offset_datetime</code></a> represent specific dates and times,
|
||||
so they can be converted to <code>std::chrono::system_clock::time_point</code>.</p><p>However, since <a href=https://toruniina.github.io/toml11/docs/reference/datetime/#local_time><code>local_time</code></a> does not include date information, it supports conversion to <code>std::chrono::duration</code> as the elapsed time from <code>00:00.00</code>.</p><p>Additionally, <code>local_date</code> and <code>local_datetime</code> conversions take the executing machine’s timezone into account.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-toml data-lang=toml><span style=display:flex><span><span style=color:#a6e22e>date</span> = <span style=color:#ae81ff>2024-01-23</span>
|
||||
</span></span><span style=display:flex><span><span style=color:#a6e22e>time</span> = <span style=color:#ae81ff>12</span><span style=color:#960050;background-color:#1e0010>:</span><span style=color:#ae81ff>30</span><span style=color:#960050;background-color:#1e0010>:</span><span style=color:#ae81ff>00</span>
|
||||
</span></span><span style=display:flex><span><span style=color:#a6e22e>l_dt</span> = <span style=color:#ae81ff>2024-01-23</span><span style=color:#a6e22e>T12</span><span style=color:#960050;background-color:#1e0010>:</span><span style=color:#ae81ff>30</span><span style=color:#960050;background-color:#1e0010>:</span><span style=color:#ae81ff>00</span>
|
||||
</span></span><span style=display:flex><span><span style=color:#a6e22e>o_dt</span> = <span style=color:#e6db74>2024-01-23T12:30:00+09:00</span>
|
||||
</span></span></code></pre></div><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> input <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>parse(<span style=color:#e6db74>"input.toml"</span>);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> date <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>get<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>chrono<span style=color:#f92672>::</span>system_clock<span style=color:#f92672>::</span>time_point<span style=color:#f92672>></span>(input.at(<span style=color:#e6db74>"date"</span>));
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> l_dt <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>get<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>chrono<span style=color:#f92672>::</span>system_clock<span style=color:#f92672>::</span>time_point<span style=color:#f92672>></span>(input.at(<span style=color:#e6db74>"l_dt"</span>));
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> o_dt <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>get<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>chrono<span style=color:#f92672>::</span>system_clock<span style=color:#f92672>::</span>time_point<span style=color:#f92672>></span>(input.at(<span style=color:#e6db74>"o_dt"</span>));
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> time <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>get<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>chrono<span style=color:#f92672>::</span>minutes<span style=color:#f92672>></span>(input.at(<span style=color:#e6db74>"time"</span>)); <span style=color:#75715e>// 12 * 60 + 30 min
|
||||
</span></span></span></code></pre></div><h3 id=conditions-for-obtaining-references>Conditions for Obtaining References
|
||||
<a class=anchor href=#conditions-for-obtaining-references>#</a></h3><p><code>toml::get<T></code> can return a reference if <code>T</code> is the exact type stored in <code>toml::value</code>.</p><p>Conversely, if a conversion is necessary (e.g., extracting an integer stored as <code>std::int64_t</code> into <code>std::uint32_t</code>), it is not possible to return a reference to the converted type.</p><p>When no conversion is needed, the returned reference can be used to modify the value.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>toml<span style=color:#f92672>::</span>value v(<span style=color:#ae81ff>42</span>);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span>toml<span style=color:#f92672>::</span>get<span style=color:#f92672><</span>toml<span style=color:#f92672>::</span>value<span style=color:#f92672>::</span>integer_type<span style=color:#f92672>></span>(v) <span style=color:#f92672>=</span> <span style=color:#ae81ff>6</span> <span style=color:#f92672>*</span> <span style=color:#ae81ff>9</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span>assert(v.as_integer() <span style=color:#f92672>==</span> <span style=color:#ae81ff>54</span>);
|
||||
</span></span></code></pre></div><h3 id=converting-arrays-to-stl-containers>Converting Arrays to STL Containers
|
||||
<a class=anchor href=#converting-arrays-to-stl-containers>#</a></h3><p>If all elements in an array have the same type and can be converted to <code>T</code>, it is possible to convert them to <code>std::vector<T></code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-toml data-lang=toml><span style=display:flex><span><span style=color:#a6e22e>a</span> = [<span style=color:#ae81ff>1</span>, <span style=color:#ae81ff>2</span>, <span style=color:#ae81ff>3</span>, <span style=color:#ae81ff>4</span>, <span style=color:#ae81ff>5</span>]
|
||||
</span></span></code></pre></div><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> a <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>get<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span><span style=color:#66d9ef>int</span><span style=color:#f92672>>></span>(input.at(<span style=color:#e6db74>"a"</span>));
|
||||
</span></span></code></pre></div><p>Other STL containers can also be used.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> a1 <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>get<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>deque<span style=color:#f92672><</span><span style=color:#66d9ef>int</span><span style=color:#f92672>>></span>(input.at(<span style=color:#e6db74>"a"</span>));
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> a2 <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>get<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>list <span style=color:#f92672><</span><span style=color:#66d9ef>int</span><span style=color:#f92672>>></span>(input.at(<span style=color:#e6db74>"a"</span>));
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> a3 <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>get<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>array<span style=color:#f92672><</span><span style=color:#66d9ef>int</span>, <span style=color:#ae81ff>5</span><span style=color:#f92672>>></span>(input.at(<span style=color:#e6db74>"a"</span>));
|
||||
</span></span></code></pre></div><p>When converting to <code>std::array</code>, the number of elements must match. If they don’t match, a <code>std::out_of_range</code> exception is thrown.</p><p>Non-STL containers that have a default constructor and a <code>push_back</code> method can also be converted using <code>toml::get</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> a <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>get<span style=color:#f92672><</span>boost<span style=color:#f92672>::</span>container<span style=color:#f92672>::</span>small_vector<span style=color:#f92672><</span><span style=color:#66d9ef>int</span>, <span style=color:#ae81ff>8</span><span style=color:#f92672>>></span>(input.at(<span style=color:#e6db74>"a"</span>));
|
||||
</span></span></code></pre></div><h3 id=converting-arrays-to-stdpair-or-stdtuple>Converting Arrays to <code>std::pair</code> or <code>std::tuple</code>
|
||||
<a class=anchor href=#converting-arrays-to-stdpair-or-stdtuple>#</a></h3><p>If an array contains elements of different types, it can be converted to <code>std::pair</code> or <code>std::tuple</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-toml data-lang=toml><span style=display:flex><span><span style=color:#a6e22e>a</span> = [<span style=color:#66d9ef>true</span>, <span style=color:#ae81ff>3.14</span>]
|
||||
</span></span><span style=display:flex><span><span style=color:#a6e22e>b</span> = [<span style=color:#ae81ff>42</span>, <span style=color:#ae81ff>2.718</span>, <span style=color:#e6db74>"foo"</span>]
|
||||
</span></span></code></pre></div><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> a <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>get<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>pair<span style=color:#f92672><</span><span style=color:#66d9ef>bool</span>, <span style=color:#66d9ef>double</span><span style=color:#f92672>>></span>(input.at(<span style=color:#e6db74>"a"</span>));
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> b <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>get<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>tuple<span style=color:#f92672><</span><span style=color:#66d9ef>int</span>, <span style=color:#66d9ef>double</span>, std<span style=color:#f92672>::</span>string<span style=color:#f92672>>></span>(input.at(<span style=color:#e6db74>"b"</span>));
|
||||
</span></span></code></pre></div><p>As with <code>std::array</code>, the length of the array must match the number of elements in the <code>std::pair</code> or <code>std::tuple</code>. If they don’t match, a <code>std::out_of_range</code> exception is thrown.</p><p>Additionally, each element must be convertible to the corresponding element in the <code>std::pair</code> or <code>std::tuple</code>. If conversion is not possible, a <code>toml::type_error</code> exception is thrown.</p><h3 id=converting-nested-arrays>Converting Nested Arrays
|
||||
<a class=anchor href=#converting-nested-arrays>#</a></h3><p>Nested arrays can be converted to nested containers.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-toml data-lang=toml><span style=display:flex><span><span style=color:#a6e22e>a</span> = [ [<span style=color:#ae81ff>1</span>, <span style=color:#ae81ff>2</span>, <span style=color:#ae81ff>3</span>], [<span style=color:#ae81ff>4</span>, <span style=color:#ae81ff>5</span>, <span style=color:#ae81ff>6</span>] ]
|
||||
</span></span></code></pre></div><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> a <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>get<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span><span style=color:#66d9ef>int</span><span style=color:#f92672>>>></span>(input.at(<span style=color:#e6db74>"a"</span>));
|
||||
</span></span></code></pre></div><p>If the types are different, <code>std::pair</code> or <code>std::tuple</code> can be useful.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-toml data-lang=toml><span style=display:flex><span><span style=color:#a6e22e>a</span> = [ [<span style=color:#ae81ff>1</span>, <span style=color:#ae81ff>2</span>, <span style=color:#ae81ff>3</span>], [<span style=color:#e6db74>"foo"</span>, <span style=color:#e6db74>"bar"</span>] ]
|
||||
</span></span></code></pre></div><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> a <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>get<span style=color:#f92672><</span>
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>pair<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span><span style=color:#66d9ef>int</span><span style=color:#f92672>></span>, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>>></span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#f92672>></span>(input.at(<span style=color:#e6db74>"a"</span>));
|
||||
</span></span></code></pre></div><h3 id=converting-tables-to-stdmap>Converting Tables to <code>std::map</code>
|
||||
<a class=anchor href=#converting-tables-to-stdmap>#</a></h3><p>If all values in a table have the same type, they can be converted to <code>std::map</code> or <code>std::unordered_map</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-toml data-lang=toml><span style=display:flex><span><span style=color:#a6e22e>t</span> = {<span style=color:#a6e22e>a</span> = <span style=color:#ae81ff>1</span>, <span style=color:#a6e22e>b</span> = <span style=color:#ae81ff>2</span>}
|
||||
</span></span></code></pre></div><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> t <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>get<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>map<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string, <span style=color:#66d9ef>int</span><span style=color:#f92672>>></span>(input.at(<span style=color:#e6db74>"t"</span>));
|
||||
</span></span></code></pre></div><p>Non-STL containers that have a default constructor and an <code>emplace(key, mapped)</code> method can also be converted using <code>toml::get</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> t <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>get<span style=color:#f92672><</span>boost<span style=color:#f92672>::</span>container<span style=color:#f92672>::</span>flat_map<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string, <span style=color:#66d9ef>int</span><span style=color:#f92672>>></span>(input.at(<span style=color:#e6db74>"t"</span>));
|
||||
</span></span></code></pre></div><p>If the conversion of any element fails, a <code>toml::type_error</code> exception is thrown.</p><h2 id=using-tomlget_or-to-specify-a-value-on-failure>Using <code>toml::get_or</code> to Specify a Value on Failure
|
||||
<a class=anchor href=#using-tomlget_or-to-specify-a-value-on-failure>#</a></h2><p><code>toml::get</code> throws a <code>toml::type_error</code> exception if the conversion fails.</p><p>By using <code>toml::get_or</code>, you can specify a default value to return instead of an exception in case of a conversion failure.</p><p>Unlike <code>toml::get<T></code>, <code>get_or</code> infers the target type from the arguments, so there is no need to specify <code><T></code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> a <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>get_or(input.at(<span style=color:#e6db74>"a"</span>), <span style=color:#ae81ff>42</span>);
|
||||
</span></span></code></pre></div><p>The types that can be converted are the same as for <code>toml::get</code>.</p><p>If you specify <code>toml::value::xxx_type</code>, you can also retrieve a reference, but in that case, the argument must also be a reference.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>toml<span style=color:#f92672>::</span>value<span style=color:#f92672>::</span>integer_type a_default <span style=color:#f92672>=</span> <span style=color:#ae81ff>42</span>;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>auto</span> a<span style=color:#f92672>&</span> <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>get_or(input.at(<span style=color:#e6db74>"a"</span>), a_default);
|
||||
</span></span></code></pre></div><h2 id=using-tomlfindt-to-search-and-convert-simultaneously>Using <code>toml::find<T></code> to Search and Convert Simultaneously
|
||||
<a class=anchor href=#using-tomlfindt-to-search-and-convert-simultaneously>#</a></h2><p><code>toml::find<T></code> is a function that searches for a value in a <code>toml::value</code> holding a table and simultaneously performs the same type conversion as <code>toml::get</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> a <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>find<span style=color:#f92672><</span><span style=color:#66d9ef>int</span><span style=color:#f92672>></span>(input, <span style=color:#e6db74>"a"</span>);
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e>// Equivalent to: const auto a = toml::get<int>(input.at("a"));
|
||||
</span></span></span></code></pre></div><p><code>toml::find<T></code> can also be used with arrays.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> a <span style=color:#f92672>=</span> input.at(<span style=color:#e6db74>"a"</span>);
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> a2 <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>find<span style=color:#f92672><</span><span style=color:#66d9ef>int</span><span style=color:#f92672>></span>(a, <span style=color:#ae81ff>2</span>);
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e>// Equivalent to: const auto a2 = toml::get<int>(input.at("a").at(2));
|
||||
</span></span></span></code></pre></div><p>If an error occurs during type conversion, <code>toml::find<T></code> throws the same <code>toml::type_error</code> as <code>toml::get</code>.
|
||||
If the key is not found or the index does not exist, it throws <code>std::out_of_range</code>.</p><p>If no type is specified, <code>toml::find</code> returns a <code>toml::value</code> without type conversion.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> a <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>find(input, <span style=color:#e6db74>"a"</span>);
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e>// Equivalent to: const auto a = input.at("a");
|
||||
</span></span></span></code></pre></div><p><code>toml::find<T></code> can access values recursively.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-toml data-lang=toml><span style=display:flex><span><span style=color:#a6e22e>a</span> = {<span style=color:#a6e22e>b</span> = {<span style=color:#a6e22e>c</span> = <span style=color:#ae81ff>42</span>}}
|
||||
</span></span></code></pre></div><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> a_b_c <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>find<span style=color:#f92672><</span><span style=color:#66d9ef>int</span><span style=color:#f92672>></span>(input, <span style=color:#e6db74>"a"</span>, <span style=color:#e6db74>"b"</span>, <span style=color:#e6db74>"c"</span>);
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e>// Equivalent to: const auto a = toml::get<int>(input.at("a").at("b").at("c"));
|
||||
</span></span></span></code></pre></div><p>You can mix keys and indexes.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-toml data-lang=toml><span style=display:flex><span><span style=color:#a6e22e>a</span> = [ {<span style=color:#a6e22e>b</span> = <span style=color:#ae81ff>1</span>}, {<span style=color:#a6e22e>b</span> = <span style=color:#ae81ff>2</span>}, {<span style=color:#a6e22e>b</span> = <span style=color:#ae81ff>3</span>} ]
|
||||
</span></span></code></pre></div><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> a_2_b <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>find<span style=color:#f92672><</span><span style=color:#66d9ef>int</span><span style=color:#f92672>></span>(input, <span style=color:#e6db74>"a"</span>, <span style=color:#ae81ff>2</span>, <span style=color:#e6db74>"b"</span>);
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e>// Equivalent to: const auto a = toml::get<int>(input.at("a").at(2).at("c"));
|
||||
</span></span></span></code></pre></div><blockquote class="book-hint info"><p>TOML supports a feature called quoted keys, which allows using normally disallowed characters in keys by enclosing them in <code>""</code> or <code>''</code>. Within quoted keys, <code>.</code> does <strong>not</strong> introduce tables.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-toml data-lang=toml><span style=display:flex><span><span style=color:#e6db74>"127.0.0.1"</span> = <span style=color:#e6db74>"value"</span>
|
||||
</span></span><span style=display:flex><span><span style=color:#a6e22e>site</span>.<span style=color:#e6db74>"google.com"</span> = <span style=color:#66d9ef>true</span>
|
||||
</span></span></code></pre></div><p>You can read this TOML file as follows:</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> input <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>parse(<span style=color:#e6db74>"input.toml"</span>);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span>assert(input.at(<span style=color:#e6db74>"127.0.0.1"</span>).as_string() <span style=color:#f92672>==</span> <span style=color:#e6db74>"value"</span>);
|
||||
</span></span><span style=display:flex><span>assert(input.at(<span style=color:#e6db74>"site"</span>).at(<span style=color:#e6db74>"google.com"</span>).as_boolean());
|
||||
</span></span></code></pre></div><p>To handle such cases seamlessly, toml11 does not automatically split keys containing <code>.</code>. Explicitly specifying the table hierarchy helps in structuring the input file correctly.</p><p>Reference: <a href=https://toml.io/en/v1.0.0#key>toml.io/Key</a></p></blockquote><h2 id=using-tomlfind_or-to-search-and-specify-a-value-on-failure>Using <code>toml::find_or</code> to Search and Specify a Value on Failure
|
||||
<a class=anchor href=#using-tomlfind_or-to-search-and-specify-a-value-on-failure>#</a></h2><p><code>toml::find_or</code> works similarly to <code>toml::find<T></code>, but allows specifying a default value to return if the search or conversion fails.</p><p>This is useful when you want to provide a fallback value instead of handling exceptions.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> a <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>find_or(input, <span style=color:#e6db74>"a"</span>, <span style=color:#ae81ff>42</span>);
|
||||
</span></span></code></pre></div><h2 id=using-tomlfind_or_default-to-search-and-use-the-default-value-on-failure>Using <code>toml::find_or_default</code> to Search and Use the Default Value on Failure
|
||||
<a class=anchor href=#using-tomlfind_or_default-to-search-and-use-the-default-value-on-failure>#</a></h2><p><code>toml::find_or_default</code> works similarly to <code>toml::find_or<T></code> but returns the default constructor result if the search or conversion fails.</p><p>This is useful when you want to use the default value instead of handling exceptions, especially when the default construction is costly, as this delays it until the actual failure happens.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> a <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>find_or(input, <span style=color:#e6db74>"a"</span>, expensive()); <span style=color:#75715e>// ctor is called before the function call
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> a <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>find_or_default<span style=color:#f92672><</span>expensive<span style=color:#f92672>></span>(input, <span style=color:#e6db74>"a"</span>); <span style=color:#75715e>// ctor will be called only on failure
|
||||
</span></span></span></code></pre></div><h2 id=tomlfindstdoptionalt><code>toml::find<std::optional<T>></code>
|
||||
<a class=anchor href=#tomlfindstdoptionalt>#</a></h2><p>If <code>std::optional</code> is available, you can specify <code>std::optional</code> as a template argument of <code>toml::find</code>.</p><p>Recursive access is also supported.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> input <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>parse_str(R<span style=color:#e6db74>"(</span>
|
||||
</span></span><span style=display:flex><span>integer <span style=color:#f92672>=</span> <span style=color:#ae81ff>1</span>
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span>[table]
|
||||
</span></span><span style=display:flex><span>key <span style=color:#f92672>=</span> <span style=color:#ae81ff>2</span>
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#a6e22e>[[array-of-tables]]</span>
|
||||
</span></span><span style=display:flex><span>key <span style=color:#f92672>=</span> <span style=color:#ae81ff>3</span>
|
||||
</span></span><span style=display:flex><span>)<span style=color:#e6db74>");</span>
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> a <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>find<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>optional<span style=color:#f92672><</span><span style=color:#66d9ef>int</span><span style=color:#f92672>>></span>(input, <span style=color:#e6db74>"integer"</span>);
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> b <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>find<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>optional<span style=color:#f92672><</span><span style=color:#66d9ef>int</span><span style=color:#f92672>>></span>(input, <span style=color:#e6db74>"table"</span>, <span style=color:#e6db74>"key"</span>);
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> c <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>find<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>optional<span style=color:#f92672><</span><span style=color:#66d9ef>int</span><span style=color:#f92672>>></span>(input, <span style=color:#e6db74>"array-of-tables"</span>, <span style=color:#ae81ff>0</span>, <span style=color:#e6db74>"key"</span>);
|
||||
</span></span></code></pre></div><p>If a key does not exist, no exception is thrown, and <code>std::nullopt</code> is returned.</p><p>However, if a type conversion fails, or if you attempt to access a key on a value that is not a table, or an index on a value that is not an array, a <code>toml::type_error</code> is thrown.</p><h2 id=defining-conversions-for-user-defined-types>Defining Conversions for User-Defined Types
|
||||
<a class=anchor href=#defining-conversions-for-user-defined-types>#</a></h2><p>With <code>toml::get</code> and <code>toml::find</code>, you can use user-defined types by employing one of the following methods.</p><h3 id=defining-tomlfrom>Defining <code>toml::from</code>
|
||||
<a class=anchor href=#defining-tomlfrom>#</a></h3><p>In toml11, there is a <code>toml::from</code> type that supports conversions from user-defined types by specializing it as follows:</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> extlib
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>foo</span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>int</span> a;
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string b;
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span><span style=display:flex><span>} <span style=color:#75715e>// extlib
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>from</span><span style=color:#f92672><</span>extlib<span style=color:#f92672>::</span>foo<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>static</span> extlib<span style=color:#f92672>::</span>foo from_toml(<span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value<span style=color:#f92672>&</span> v)
|
||||
</span></span><span style=display:flex><span> {
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> extlib<span style=color:#f92672>::</span>foo{
|
||||
</span></span><span style=display:flex><span> toml<span style=color:#f92672>::</span>find<span style=color:#f92672><</span><span style=color:#66d9ef>int</span><span style=color:#f92672>></span>(v, <span style=color:#e6db74>"a"</span>),
|
||||
</span></span><span style=display:flex><span> toml<span style=color:#f92672>::</span>find<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span>(v, <span style=color:#e6db74>"b"</span>)
|
||||
</span></span><span style=display:flex><span> };
|
||||
</span></span><span style=display:flex><span> }
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span><span style=display:flex><span>} <span style=color:#75715e>// toml
|
||||
</span></span></span></code></pre></div><p>If you also want to support <code>toml::value</code> with a modified type configuration, do as follows:</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> extlib
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>foo</span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>int</span> a;
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string b;
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span><span style=display:flex><span>} <span style=color:#75715e>// extlib
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>from</span><span style=color:#f92672><</span>extlib<span style=color:#f92672>::</span>foo<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>static</span> extlib<span style=color:#f92672>::</span>foo from_toml(<span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v)
|
||||
</span></span><span style=display:flex><span> {
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> extlib<span style=color:#f92672>::</span>foo{
|
||||
</span></span><span style=display:flex><span> toml<span style=color:#f92672>::</span>find<span style=color:#f92672><</span><span style=color:#66d9ef>int</span><span style=color:#f92672>></span>(v, <span style=color:#e6db74>"a"</span>),
|
||||
</span></span><span style=display:flex><span> toml<span style=color:#f92672>::</span>find<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span>(v, <span style=color:#e6db74>"b"</span>)
|
||||
</span></span><span style=display:flex><span> };
|
||||
</span></span><span style=display:flex><span> }
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span><span style=display:flex><span>} <span style=color:#75715e>// toml
|
||||
</span></span></span></code></pre></div><p>This definition can be automatically generated using <code>TOML11_DEFINE_CONVERSION_NON_INTRUSIVE</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> extlib
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>foo</span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>int</span> a;
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string b;
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span><span style=display:flex><span>} <span style=color:#75715e>// extlib
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span>TOML11_DEFINE_CONVERSION_NON_INTRUSIVE(extlib<span style=color:#f92672>::</span>foo, a, b)
|
||||
</span></span></code></pre></div><p>Alternatively, you can use a reflection library. Refer to the sample in <code>example</code> using <code>boost-ext/reflect</code>.</p><h3 id=defining-a-from_toml-member-function>Defining a <code>from_toml</code> Member Function
|
||||
<a class=anchor href=#defining-a-from_toml-member-function>#</a></h3><p>You can also define a conversion by defining a <code>from_toml</code> member function.</p><p>When using this method, a default constructor is required.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>bar</span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>int</span> a;
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string b;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>void</span> <span style=color:#a6e22e>from_toml</span>(<span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value<span style=color:#f92672>&</span> v)
|
||||
</span></span><span style=display:flex><span> {
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>this</span><span style=color:#f92672>-></span>a <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>find<span style=color:#f92672><</span><span style=color:#66d9ef>int</span><span style=color:#f92672>></span>(v, <span style=color:#e6db74>"a"</span>);
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>this</span><span style=color:#f92672>-></span>b <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>find<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span>(v, <span style=color:#e6db74>"b"</span>);
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> ;
|
||||
</span></span><span style=display:flex><span> }
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span></code></pre></div><p>If both are defined, <code>toml::from</code> takes precedence.</p><h3 id=constructor-accepting-tomlvalue>Constructor Accepting <code>toml::value</code>
|
||||
<a class=anchor href=#constructor-accepting-tomlvalue>#</a></h3><p>If there is a constructor that accepts <code>toml::value</code>, conversion via <code>toml::get</code> can be performed.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>baz</span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>explicit</span> <span style=color:#a6e22e>baz</span>(<span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value<span style=color:#f92672>&</span> v)
|
||||
</span></span><span style=display:flex><span> <span style=color:#f92672>:</span> a(toml<span style=color:#f92672>::</span>find<span style=color:#f92672><</span><span style=color:#66d9ef>int</span><span style=color:#f92672>></span>(v, <span style=color:#e6db74>"a"</span>)), b(toml<span style=color:#f92672>::</span>find<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span>(v, <span style=color:#e6db74>"b"</span>))
|
||||
</span></span><span style=display:flex><span> {}
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>int</span> a;
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string b;
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span></code></pre></div><p>If both are defined, <code>toml::from</code> and <code>from_toml</code> take precedence.</p><h2 id=applying-functions-with-tomlvisit>Applying Functions with <code>toml::visit</code>
|
||||
<a class=anchor href=#applying-functions-with-tomlvisit>#</a></h2><p>If you have a function object that can be applied to all types stored in <code>toml::value</code>, you can directly call that function without type conversion using <code>toml::visit</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>type_name_of</span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string <span style=color:#66d9ef>operator</span>()(<span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value<span style=color:#f92672>::</span>boolean_type <span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> {<span style=color:#66d9ef>return</span> <span style=color:#e6db74>"boolean"</span>;}
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string <span style=color:#66d9ef>operator</span>()(<span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value<span style=color:#f92672>::</span>integer_type <span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> {<span style=color:#66d9ef>return</span> <span style=color:#e6db74>"integer"</span>;}
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string <span style=color:#66d9ef>operator</span>()(<span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value<span style=color:#f92672>::</span>floating_type <span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> {<span style=color:#66d9ef>return</span> <span style=color:#e6db74>"floating"</span>;}
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string <span style=color:#66d9ef>operator</span>()(<span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value<span style=color:#f92672>::</span>string_type <span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> {<span style=color:#66d9ef>return</span> <span style=color:#e6db74>"string"</span>;}
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string <span style=color:#66d9ef>operator</span>()(<span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value<span style=color:#f92672>::</span>local_time_type <span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> {<span style=color:#66d9ef>return</span> <span style=color:#e6db74>"local_time"</span>;}
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string <span style=color:#66d9ef>operator</span>()(<span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value<span style=color:#f92672>::</span>local_date_type <span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> {<span style=color:#66d9ef>return</span> <span style=color:#e6db74>"local_date"</span>;}
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string <span style=color:#66d9ef>operator</span>()(<span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value<span style=color:#f92672>::</span>local_datetime_type <span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> {<span style=color:#66d9ef>return</span> <span style=color:#e6db74>"local_datetime"</span>;}
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string <span style=color:#66d9ef>operator</span>()(<span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value<span style=color:#f92672>::</span>offset_datetime_type<span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> {<span style=color:#66d9ef>return</span> <span style=color:#e6db74>"offset_datetime"</span>;}
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string <span style=color:#66d9ef>operator</span>()(<span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value<span style=color:#f92672>::</span>array_type <span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> {<span style=color:#66d9ef>return</span> <span style=color:#e6db74>"array"</span>;}
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string <span style=color:#66d9ef>operator</span>()(<span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value<span style=color:#f92672>::</span>table_type <span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> {<span style=color:#66d9ef>return</span> <span style=color:#e6db74>"table"</span>;}
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span>toml<span style=color:#f92672>::</span>value v(<span style=color:#ae81ff>3.14</span>);
|
||||
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>cout <span style=color:#f92672><<</span> toml<span style=color:#f92672>::</span>visit(type_name_of{}, v) <span style=color:#f92672><<</span> std<span style=color:#f92672>::</span>endl; <span style=color:#75715e>// floating
|
||||
</span></span></span></code></pre></div><h2 id=constructing-tomlvalue>Constructing <code>toml::value</code>
|
||||
<a class=anchor href=#constructing-tomlvalue>#</a></h2><p><code>toml::value</code> can be constructed not only internally by the parser but also in user code.</p><p>You can construct it by passing a type that is either the same as or convertible to the types stored in <code>toml::value</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>toml<span style=color:#f92672>::</span>value v1(true);
|
||||
</span></span><span style=display:flex><span>toml<span style=color:#f92672>::</span>value v2(<span style=color:#ae81ff>42</span>);
|
||||
</span></span><span style=display:flex><span>toml<span style=color:#f92672>::</span>value v3(<span style=color:#ae81ff>3.14</span>);
|
||||
</span></span></code></pre></div><p>For arrays, you can use <code>toml::array</code>:</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>toml<span style=color:#f92672>::</span>value v(toml<span style=color:#f92672>::</span>array{<span style=color:#ae81ff>1</span>, <span style=color:#ae81ff>2</span>, <span style=color:#ae81ff>3</span>});
|
||||
</span></span></code></pre></div><p>Alternatively, you can pass containers such as <code>std::vector</code> directly:</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>toml<span style=color:#f92672>::</span>value<span style=color:#f92672>></span> a{<span style=color:#ae81ff>1</span>,<span style=color:#ae81ff>2</span>,<span style=color:#ae81ff>3</span>};
|
||||
</span></span><span style=display:flex><span>toml<span style=color:#f92672>::</span>value v(a);
|
||||
</span></span></code></pre></div><p>For tables, you can use <code>toml::table</code>:</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>toml<span style=color:#f92672>::</span>value v(toml<span style=color:#f92672>::</span>table{{<span style=color:#e6db74>"foo"</span>, <span style=color:#ae81ff>1</span>}, {<span style=color:#e6db74>"bar"</span>, <span style=color:#ae81ff>2</span>}, {<span style=color:#e6db74>"baz"</span>, <span style=color:#ae81ff>3</span>}});
|
||||
</span></span></code></pre></div><p>Or pass containers such as <code>std::map</code> directly:</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>map<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string, toml<span style=color:#f92672>::</span>value<span style=color:#f92672>></span> t{
|
||||
</span></span><span style=display:flex><span> {<span style=color:#e6db74>"foo"</span>, <span style=color:#ae81ff>1</span>}, {<span style=color:#e6db74>"bar"</span>, <span style=color:#ae81ff>2</span>}, {<span style=color:#e6db74>"baz"</span>, <span style=color:#ae81ff>3</span>}
|
||||
</span></span><span style=display:flex><span> }
|
||||
</span></span><span style=display:flex><span>toml<span style=color:#f92672>::</span>value v(t);
|
||||
</span></span></code></pre></div><p>You can pass <code>format_info</code> and comments to the constructor.</p><p>The type of comments is <code>std::vector<std::string></code>.
|
||||
Each element corresponds to a line.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>toml<span style=color:#f92672>::</span>integer_format_info fmt;
|
||||
</span></span><span style=display:flex><span>fmt.fmt <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>integer_format<span style=color:#f92672>::</span>hex;
|
||||
</span></span><span style=display:flex><span>fmt.spacer <span style=color:#f92672>=</span> <span style=color:#ae81ff>4</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span>toml<span style=color:#f92672>::</span>value v1(<span style=color:#ae81ff>0xDEADBEEF</span>, fmt);
|
||||
</span></span><span style=display:flex><span>toml<span style=color:#f92672>::</span>value v2(<span style=color:#ae81ff>0xC0FFEE</span>, fmt, {<span style=color:#e6db74>"hex value!"</span>});
|
||||
</span></span></code></pre></div><h2 id=converting-to-tomlvalue>Converting to <code>toml::value</code>
|
||||
<a class=anchor href=#converting-to-tomlvalue>#</a></h2><p>When constructing <code>toml::value</code> from user-defined types, you can customize the behavior by defining <code>toml::into</code> or <code>into_toml</code>.</p><p><code>toml::into</code> is particularly useful when converting types from other libraries.</p><h3 id=defining-tomlinto>Defining <code>toml::into</code>
|
||||
<a class=anchor href=#defining-tomlinto>#</a></h3><p>By specializing <code>toml::into</code>, you can enable conversions to <code>toml::value</code>.</p><p>This is useful for types from external libraries that do not provide a conversion to <code>toml::value</code>.</p><p>Since <code>toml::value</code> passes <code>type_config</code> during conversion, you need to accept the <code>template</code> argument of <code>basic_value</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> extlib
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>foo</span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>int</span> a;
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string b;
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span><span style=display:flex><span>} <span style=color:#75715e>// extlib
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>into</span><span style=color:#f92672><</span>extlib<span style=color:#f92672>::</span>foo<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>static</span> toml<span style=color:#f92672>::</span>basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>></span> into_toml(<span style=color:#66d9ef>const</span> extlib<span style=color:#f92672>::</span>foo<span style=color:#f92672>&</span> f)
|
||||
</span></span><span style=display:flex><span> {
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> toml<span style=color:#f92672>::</span>basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>></span>(<span style=color:#66d9ef>typename</span> toml<span style=color:#f92672>::</span>basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>::</span>table_type{{<span style=color:#e6db74>"a"</span>, f.a}, {<span style=color:#e6db74>"b"</span>, f.b}});
|
||||
</span></span><span style=display:flex><span> }
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span></code></pre></div><h3 id=defining-into_toml-member-function>Defining <code>into_toml</code> Member Function
|
||||
<a class=anchor href=#defining-into_toml-member-function>#</a></h3><p>Similar to <code>from_toml</code>, you can define the conversion through a member function.</p><p>If <code>toml::into</code> is defined, it takes precedence.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>bar</span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>int</span> a;
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string b;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> toml<span style=color:#f92672>::</span>basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>></span> into_toml() <span style=color:#66d9ef>const</span>
|
||||
</span></span><span style=display:flex><span> {
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> toml<span style=color:#f92672>::</span>basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>></span>(<span style=color:#66d9ef>typename</span> toml<span style=color:#f92672>::</span>basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>::</span>table_type{
|
||||
</span></span><span style=display:flex><span> {<span style=color:#e6db74>"a"</span>, <span style=color:#66d9ef>this</span><span style=color:#f92672>-></span>a}, {<span style=color:#e6db74>"b"</span>, <span style=color:#66d9ef>this</span><span style=color:#f92672>-></span>b}
|
||||
</span></span><span style=display:flex><span> });
|
||||
</span></span><span style=display:flex><span> }
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span></code></pre></div><h1 id=checking-whether-a-value-has-been-accessed>Checking Whether a Value Has Been Accessed
|
||||
<a class=anchor href=#checking-whether-a-value-has-been-accessed>#</a></h1><p>When compiled with the <code>TOML11_ENABLE_ACCESS_CHECK</code> macro defined, the <code>toml::value</code> class gains an additional method: <code>bool accessed() const</code>.
|
||||
This allows you to check whether a value has been accessed after parsing.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-console data-lang=console><span style=display:flex><span>$ g++ -std<span style=color:#f92672>=</span>c++17 -O2 -DTOML11_ENABLE_ACCESS_CHECK -I/path/to/toml11/include main.cpp
|
||||
</span></span></code></pre></div><p>or</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-console data-lang=console><span style=display:flex><span>$ cmake -B ./build -DTOML11_ENABLE_ACCESS_CHECK<span style=color:#f92672>=</span>ON
|
||||
</span></span></code></pre></div><p>or</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cmake data-lang=cmake><span style=display:flex><span>CPMAddPackage(
|
||||
</span></span><span style=display:flex><span> <span style=color:#e6db74>NAME</span> <span style=color:#e6db74>toml11</span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#e6db74>GITHUB_REPOSITORY</span> <span style=color:#e6db74>"ToruNiina/toml11"</span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#e6db74>VERSION</span> <span style=color:#e6db74>4.4.0</span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#e6db74>OPTIONS</span> <span style=color:#e6db74>"CMAKE_CXX_STANDARD 17"</span> <span style=color:#e6db74>"TOML11_PRECOMPILE ON"</span> <span style=color:#e6db74>"TOML11_ENABLE_ACCESS_CHECK ON"</span>
|
||||
</span></span><span style=display:flex><span> )<span style=color:#960050;background-color:#1e0010>
|
||||
</span></span></span></code></pre></div><p>This feature allows users to implement code that warns about values defined in a table but never used.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><toml.hpp></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>namespace</span> yours
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span>Config <span style=color:#a6e22e>read_config</span>(<span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value<span style=color:#f92672>&</span> input)
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> cfg <span style=color:#f92672>=</span> read_your_config(input);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>for</span> (<span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span><span style=color:#f92672>&</span> [k, v] <span style=color:#f92672>:</span> input.as_table())
|
||||
</span></span><span style=display:flex><span> {
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>if</span> (<span style=color:#f92672>!</span>v.accessed())
|
||||
</span></span><span style=display:flex><span> {
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>cerr <span style=color:#f92672><<</span> toml<span style=color:#f92672>::</span>format_error(<span style=color:#e6db74>"value defined but not used"</span>,
|
||||
</span></span><span style=display:flex><span> v.source_location(), <span style=color:#e6db74>"not used"</span>);
|
||||
</span></span><span style=display:flex><span> }
|
||||
</span></span><span style=display:flex><span> }
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> cfg;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span><span style=display:flex><span>} <span style=color:#75715e>// namespace yours
|
||||
</span></span></span></code></pre></div><p>This feature is useful when a value is mistakenly defined under the wrong name but is never accessed. For example:</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-toml data-lang=toml><span style=display:flex><span><span style=color:#75715e># The correct key is "reactions"</span>
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e># reactions = [ ":+1:", "star" ]</span>
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e># This key is incorrect and will not be read</span>
|
||||
</span></span><span style=display:flex><span><span style=color:#a6e22e>reaction</span> = [ <span style=color:#e6db74>":+1:"</span>, <span style=color:#e6db74>"star"</span> ]
|
||||
</span></span></code></pre></div><p>If this file is read using the above code, <code>read_your_config</code> will search for <code>reactions</code>. Since it is not defined, it will process <code>reactions</code> as an empty array.
|
||||
In this case, <code>input.at("reaction").accessed()</code> will be <code>false</code>, allowing it to be detected as an error.</p></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#retrieving-values>Retrieving Values</a><ul><li><a href=#accessing-values-using-member-functions>Accessing Values Using Member Functions</a><ul><li><a href=#is_something-and-as_something><code>is_something</code> and <code>as_something</code></a></li><li><a href=#tomlvalue_t><code>toml::value_t</code></a></li><li><a href=#at--contains-size-push_back-emplace_back><code>at</code>, <code>[]</code>, <code>contains</code>, <code>size</code>, <code>push_back</code>, <code>emplace_back</code></a></li></ul></li><li><a href=#accessing-comments>Accessing Comments</a></li><li><a href=#handling-inline-tables-and-dotted-keys>Handling Inline Tables and Dotted Keys</a></li><li><a href=#handling-date-and-time-information>Handling Date and Time Information</a></li><li><a href=#converting-using-tomlgett>Converting Using <code>toml::get<T></code></a><ul><li><a href=#simple-conversions>Simple Conversions</a></li><li><a href=#conditions-for-obtaining-references>Conditions for Obtaining References</a></li><li><a href=#converting-arrays-to-stl-containers>Converting Arrays to STL Containers</a></li><li><a href=#converting-arrays-to-stdpair-or-stdtuple>Converting Arrays to <code>std::pair</code> or <code>std::tuple</code></a></li><li><a href=#converting-nested-arrays>Converting Nested Arrays</a></li><li><a href=#converting-tables-to-stdmap>Converting Tables to <code>std::map</code></a></li></ul></li><li><a href=#using-tomlget_or-to-specify-a-value-on-failure>Using <code>toml::get_or</code> to Specify a Value on Failure</a></li><li><a href=#using-tomlfindt-to-search-and-convert-simultaneously>Using <code>toml::find<T></code> to Search and Convert Simultaneously</a></li><li><a href=#using-tomlfind_or-to-search-and-specify-a-value-on-failure>Using <code>toml::find_or</code> to Search and Specify a Value on Failure</a></li><li><a href=#using-tomlfind_or_default-to-search-and-use-the-default-value-on-failure>Using <code>toml::find_or_default</code> to Search and Use the Default Value on Failure</a></li><li><a href=#tomlfindstdoptionalt><code>toml::find<std::optional<T>></code></a></li><li><a href=#defining-conversions-for-user-defined-types>Defining Conversions for User-Defined Types</a><ul><li><a href=#defining-tomlfrom>Defining <code>toml::from</code></a></li><li><a href=#defining-a-from_toml-member-function>Defining a <code>from_toml</code> Member Function</a></li><li><a href=#constructor-accepting-tomlvalue>Constructor Accepting <code>toml::value</code></a></li></ul></li><li><a href=#applying-functions-with-tomlvisit>Applying Functions with <code>toml::visit</code></a></li><li><a href=#constructing-tomlvalue>Constructing <code>toml::value</code></a></li><li><a href=#converting-to-tomlvalue>Converting to <code>toml::value</code></a><ul><li><a href=#defining-tomlinto>Defining <code>toml::into</code></a></li><li><a href=#defining-into_toml-member-function>Defining <code>into_toml</code> Member Function</a></li></ul></li></ul></li><li><a href=#checking-whether-a-value-has-been-accessed>Checking Whether a Value Has Been Accessed</a></li></ul></nav></div></aside></main></body></html>
|
||||
8
docs/index.html
Normal file
8
docs/index.html
Normal file
@@ -0,0 +1,8 @@
|
||||
<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="Docs"><meta property="og:locale" content="en"><meta property="og:type" content="website"><title>Docs | toml11</title><link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/ title=Docs><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" crossorigin=anonymous></script><link rel=alternate type=application/rss+xml href=https://toruniina.github.io/toml11/docs/index.xml title=toml11></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
|
||||
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
|
||||
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
|
||||
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle>
|
||||
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle>
|
||||
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
|
||||
</label><strong>Docs</strong>
|
||||
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents></nav></aside></header><article class="markdown book-article"></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents></nav></div></aside></main></body></html>
|
||||
1
docs/index.xml
Normal file
1
docs/index.xml
Normal file
@@ -0,0 +1 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Docs on toml11</title><link>https://toruniina.github.io/toml11/docs/</link><description>Recent content in Docs on toml11</description><generator>Hugo</generator><language>en</language><atom:link href="https://toruniina.github.io/toml11/docs/index.xml" rel="self" type="application/rss+xml"/></channel></rss>
|
||||
86
docs/installation/index.html
Normal file
86
docs/installation/index.html
Normal file
@@ -0,0 +1,86 @@
|
||||
<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
|
||||
Installation
|
||||
#
|
||||
|
||||
|
||||
Using single_include
|
||||
#
|
||||
|
||||
The ingle_include/toml.hpps is a single-file, header-only library that consolidates all the functionalities of toml11 into one file.
|
||||
The simplest way to use it is to copy this file to a location included in your INCLUDE_PATH and then add #include <toml.hpp> to your source code.
|
||||
The MIT license notice is included in both the comments and the toml::license_notice() function.
|
||||
If you are redistributing the software without releasing the source code, you must either copy the toml11 license file and include it with your distribution, or ensure that the toml::license_notice() function can be called."><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/installation/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="installation"><meta property="og:description" content="Installation # Using single_include # The ingle_include/toml.hpps is a single-file, header-only library that consolidates all the functionalities of toml11 into one file.
|
||||
The simplest way to use it is to copy this file to a location included in your INCLUDE_PATH and then add #include <toml.hpp> to your source code.
|
||||
The MIT license notice is included in both the comments and the toml::license_notice() function. If you are redistributing the software without releasing the source code, you must either copy the toml11 license file and include it with your distribution, or ensure that the toml::license_notice() function can be called."><meta property="og:locale" content="en"><meta property="og:type" content="website"><title>installation | toml11</title><link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/installation/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/installation/ title=installation><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" crossorigin=anonymous></script><link rel=alternate type=application/rss+xml href=https://toruniina.github.io/toml11/docs/installation/index.xml title=toml11></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
|
||||
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
|
||||
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
|
||||
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/installation/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/ class=active>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle>
|
||||
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle>
|
||||
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
|
||||
</label><strong>installation</strong>
|
||||
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#installation>Installation</a><ul><li><a href=#using-single_include>Using <code>single_include</code></a></li><li><a href=#cloning-toml11-and-using-cmake>Cloning toml11 and using cmake</a><ul><li><a href=#cmake-fetchcontent>CMake <code>FetchContent</code></a></li><li><a href=#cmake-package-manager-cpm>CMake Package Manager (CPM)</a></li></ul></li><li><a href=#installing-using-cmake>Installing using cmake</a></li><li><a href=#compiling-with-cmake-to-create-a-static-library>Compiling with cmake to Create a Static Library</a></li><li><a href=#compiling-examples>Compiling Examples</a></li><li><a href=#running-tests>Running Tests</a></li></ul></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=installation>Installation
|
||||
<a class=anchor href=#installation>#</a></h1><h2 id=using-single_include>Using <code>single_include</code>
|
||||
<a class=anchor href=#using-single_include>#</a></h2><p>The <code>ingle_include/toml.hpp</code>s is a single-file, header-only library that consolidates all the functionalities of toml11 into one file.</p><p>The simplest way to use it is to copy this file to a location included in your <code>INCLUDE_PATH</code> and then add <code>#include <toml.hpp></code> to your source code.</p><p>The MIT license notice is included in both the comments and the <code>toml::license_notice()</code> function.
|
||||
If you are redistributing the software without releasing the source code, you must either copy the toml11 license file and include it with your distribution, or ensure that the <code>toml::license_notice()</code> function can be called.</p><h2 id=cloning-toml11-and-using-cmake>Cloning toml11 and using cmake
|
||||
<a class=anchor href=#cloning-toml11-and-using-cmake>#</a></h2><p>If you place toml11 within your repository, for example by using git submodule, and you are using cmake, you can make use of it by adding <code>add_subdirectory(toml11)</code> to your <code>CMakeLists.txt</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cmake data-lang=cmake><span style=display:flex><span>add_subdirectory(<span style=color:#e6db74>toml11</span>)<span style=color:#960050;background-color:#1e0010>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#960050;background-color:#1e0010></span>add_executable(<span style=color:#e6db74>main</span> <span style=color:#e6db74>main.cpp</span>)<span style=color:#960050;background-color:#1e0010>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#960050;background-color:#1e0010></span>target_link_libraries(<span style=color:#e6db74>main</span> <span style=color:#e6db74>PUBLIC</span> <span style=color:#e6db74>toml11::toml11</span>)<span style=color:#960050;background-color:#1e0010>
|
||||
</span></span></span></code></pre></div><p>toml11 will only run tests and install when it is the root project.</p><h3 id=cmake-fetchcontent>CMake <code>FetchContent</code>
|
||||
<a class=anchor href=#cmake-fetchcontent>#</a></h3><p>Using <code>FetchContent</code>, you can automatically download toml11 to your <code>build</code> directory.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cmake data-lang=cmake><span style=display:flex><span>include(<span style=color:#e6db74>FetchContent</span>)<span style=color:#960050;background-color:#1e0010>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#960050;background-color:#1e0010></span>FetchContent_Declare(
|
||||
</span></span><span style=display:flex><span> <span style=color:#e6db74>toml11</span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#e6db74>GIT_REPOSITORY</span> <span style=color:#e6db74>https://github.com/ToruNiina/toml11.git</span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#e6db74>GIT_TAG</span> <span style=color:#e6db74>v4.4.0</span>
|
||||
</span></span><span style=display:flex><span>)<span style=color:#960050;background-color:#1e0010>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#960050;background-color:#1e0010></span>FetchContent_MakeAvailable(<span style=color:#e6db74>toml11</span>)<span style=color:#960050;background-color:#1e0010>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#960050;background-color:#1e0010>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#960050;background-color:#1e0010></span>add_executable(<span style=color:#e6db74>main</span> <span style=color:#e6db74>main.cpp</span>)<span style=color:#960050;background-color:#1e0010>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#960050;background-color:#1e0010></span>target_link_libraries(<span style=color:#e6db74>main</span> <span style=color:#e6db74>PRIVATE</span> <span style=color:#e6db74>toml11::toml11</span>)<span style=color:#960050;background-color:#1e0010>
|
||||
</span></span></span></code></pre></div><h3 id=cmake-package-manager-cpm>CMake Package Manager (CPM)
|
||||
<a class=anchor href=#cmake-package-manager-cpm>#</a></h3><p>After <a href="https://github.com/cpm-cmake/CPM.cmake?tab=readme-ov-file#adding-cpm">adding cpm to your project</a>, you can use toml11 by doing:</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cmake data-lang=cmake><span style=display:flex><span>include(<span style=color:#e6db74>cmake/CPM.cmake</span>)<span style=color:#960050;background-color:#1e0010>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#960050;background-color:#1e0010>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#960050;background-color:#1e0010></span>CPMAddPackage(<span style=color:#e6db74>"gh:ToruNiina/toml11@4.4.0"</span>)<span style=color:#960050;background-color:#1e0010>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#960050;background-color:#1e0010>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#960050;background-color:#1e0010></span><span style=color:#75715e># OR
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span><span style=color:#960050;background-color:#1e0010>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#960050;background-color:#1e0010></span>CPMAddPackage(
|
||||
</span></span><span style=display:flex><span> <span style=color:#e6db74>NAME</span> <span style=color:#e6db74>toml11</span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#e6db74>GITHUB_REPOSITORY</span> <span style=color:#e6db74>"ToruNiina/toml11"</span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#e6db74>VERSION</span> <span style=color:#e6db74>4.4.0</span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#e6db74>OPTIONS</span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#e6db74>"TOML11_PRECOMPILE ON"</span> <span style=color:#75715e># to pre-compile
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span> <span style=color:#e6db74>"TOML11_ENABLE_ACCESS_CHECK ON"</span> <span style=color:#75715e># to use value.accessed()
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span> )<span style=color:#960050;background-color:#1e0010>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#960050;background-color:#1e0010>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#960050;background-color:#1e0010></span>add_executable(<span style=color:#e6db74>main</span> <span style=color:#e6db74>main.cpp</span>)<span style=color:#960050;background-color:#1e0010>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#960050;background-color:#1e0010></span>target_link_libraries(<span style=color:#e6db74>main</span> <span style=color:#e6db74>PUBLIC</span> <span style=color:#e6db74>toml11::toml11</span>)<span style=color:#960050;background-color:#1e0010>
|
||||
</span></span></span></code></pre></div><h2 id=installing-using-cmake>Installing using cmake
|
||||
<a class=anchor href=#installing-using-cmake>#</a></h2><p>After cloning toml11, you can install it using cmake.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-console data-lang=console><span style=display:flex><span>$ cmake -B ./build/ -DTOML11_BUILD_TESTS<span style=color:#f92672>=</span>ON
|
||||
</span></span><span style=display:flex><span>$ cmake --install ./build/ --prefix<span style=color:#f92672>=</span>/opt/toml11
|
||||
</span></span></code></pre></div><p>If you want to run the test programs before installation, make sure to set <code>-DTOML11_BUILD_TESTS=ON</code> first.</p><p>Once the installation is complete, you can use it as follows:</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cmake data-lang=cmake><span style=display:flex><span>find_package(<span style=color:#e6db74>toml11</span>)<span style=color:#960050;background-color:#1e0010>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#960050;background-color:#1e0010></span>add_executable(<span style=color:#e6db74>main</span> <span style=color:#e6db74>main.cpp</span>)<span style=color:#960050;background-color:#1e0010>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#960050;background-color:#1e0010></span>target_link_libraries(<span style=color:#e6db74>main</span> <span style=color:#e6db74>PRIVATE</span> <span style=color:#e6db74>toml11::toml11</span>)<span style=color:#960050;background-color:#1e0010>
|
||||
</span></span></span></code></pre></div><h2 id=compiling-with-cmake-to-create-a-static-library>Compiling with cmake to Create a Static Library
|
||||
<a class=anchor href=#compiling-with-cmake-to-create-a-static-library>#</a></h2><p>By defining <code>-DTOML11_PRECOMPILE=ON</code> when running cmake, you can precompile some of the functions in toml11, thereby reducing the overall compile time.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-console data-lang=console><span style=display:flex><span>$ cmake -B ./build/ -DTOML11_PRECOMPILE<span style=color:#f92672>=</span>ON
|
||||
</span></span></code></pre></div><p>When linking the library, use <code>target_link_libraries</code> in CMake</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cmake data-lang=cmake><span style=display:flex><span>target_link_libraries(<span style=color:#e6db74>your_target</span> <span style=color:#e6db74>PUBLIC</span> <span style=color:#e6db74>toml11::toml11</span>)<span style=color:#960050;background-color:#1e0010>
|
||||
</span></span></span></code></pre></div><p>or pass <code>-DTOML11_COMPILE_SOURCES</code> to the compiler to suppress header-only features.</p><p>However, since toml11 supports multiple C++ versions and may switch types based on the value of <code>__cplusplus</code>,
|
||||
there is a possibility of link failures if the version used during build differs from the version used during usage.
|
||||
If you encounter issues, set the required version using <code>CMAKE_CXX_STANDARD</code> during compilation.
|
||||
If this is difficult, use it as a header-only library as usual.</p><p>The <code>find_package(toml11)</code> command defines <code>TOML11_INCLUDE_DIR</code>.
|
||||
Even if you install it as a precompiled library, you can still use it as a header-only library by adding <code>TOML11_INCLUDE_DIR</code> to <code>target_include_directories</code> and avoiding the use of <code>target_link_libraries</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cmake data-lang=cmake><span style=display:flex><span>find_package(<span style=color:#e6db74>toml11</span>)<span style=color:#960050;background-color:#1e0010>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#960050;background-color:#1e0010></span>add_executable(<span style=color:#e6db74>main</span> <span style=color:#e6db74>main.cpp</span>)<span style=color:#960050;background-color:#1e0010>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#960050;background-color:#1e0010></span><span style=color:#75715e># Include only, do not link
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>target_include_directories(<span style=color:#e6db74>main</span> <span style=color:#e6db74>PRIVATE</span> <span style=color:#f92672>${</span>TOML11_INCLUDE_DIR<span style=color:#f92672>}</span>)<span style=color:#960050;background-color:#1e0010>
|
||||
</span></span></span></code></pre></div><h2 id=compiling-examples>Compiling Examples
|
||||
<a class=anchor href=#compiling-examples>#</a></h2><p>You can compile the <code>examples/</code> directory by setting <code>-DTOML11_BUILD_EXAMPLES=ON</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-console data-lang=console><span style=display:flex><span>$ cmake -B ./build/ -DTOML11_BUILD_EXAMPLES<span style=color:#f92672>=</span>ON
|
||||
</span></span><span style=display:flex><span>$ cmake --build ./build/
|
||||
</span></span></code></pre></div><p>The executable binaries for the examples will be generated in the <code>examples/</code> directory.</p><h2 id=running-tests>Running Tests
|
||||
<a class=anchor href=#running-tests>#</a></h2><p>To build the tests, set <code>-DTOML11_BUILD_TESTS=ON</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-console data-lang=console><span style=display:flex><span>$ git submodule update --init --recursive
|
||||
</span></span><span style=display:flex><span>$ cmake -B ./build/ -DTOML11_BUILD_TESTS<span style=color:#f92672>=</span>ON
|
||||
</span></span><span style=display:flex><span>$ cmake --build ./build/
|
||||
</span></span><span style=display:flex><span>$ ctest --test-dir ./build/
|
||||
</span></span></code></pre></div><p>To run the <code>toml-lang/toml-tests</code>, set <code>-DTOML11_BUILD_TOML_TESTS=ON</code>. This will build <code>toml11_decoder</code> and <code>toml11_encoder</code> in the <code>tests/</code> directory.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-console data-lang=console><span style=display:flex><span>$ git submodule update --init --recursive
|
||||
</span></span><span style=display:flex><span>$ cmake -B ./build/ -DTOML11_BUILD_TOML_TESTS<span style=color:#f92672>=</span>ON
|
||||
</span></span><span style=display:flex><span>$ cmake --build ./build/
|
||||
</span></span><span style=display:flex><span>$ ctest --test-dir ./build/
|
||||
</span></span></code></pre></div></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#installation>Installation</a><ul><li><a href=#using-single_include>Using <code>single_include</code></a></li><li><a href=#cloning-toml11-and-using-cmake>Cloning toml11 and using cmake</a><ul><li><a href=#cmake-fetchcontent>CMake <code>FetchContent</code></a></li><li><a href=#cmake-package-manager-cpm>CMake Package Manager (CPM)</a></li></ul></li><li><a href=#installing-using-cmake>Installing using cmake</a></li><li><a href=#compiling-with-cmake-to-create-a-static-library>Compiling with cmake to Create a Static Library</a></li><li><a href=#compiling-examples>Compiling Examples</a></li><li><a href=#running-tests>Running Tests</a></li></ul></li></ul></nav></div></aside></main></body></html>
|
||||
1
docs/installation/index.xml
Normal file
1
docs/installation/index.xml
Normal file
@@ -0,0 +1 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>installation on toml11</title><link>https://toruniina.github.io/toml11/docs/installation/</link><description>Recent content in installation on toml11</description><generator>Hugo</generator><language>en</language><atom:link href="https://toruniina.github.io/toml11/docs/installation/index.xml" rel="self" type="application/rss+xml"/></channel></rss>
|
||||
110
docs/reference/color/index.html
Normal file
110
docs/reference/color/index.html
Normal file
@@ -0,0 +1,110 @@
|
||||
<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
|
||||
color.hpp
|
||||
#
|
||||
|
||||
In color.hpp, functions related to colorizing error messages are defined.
|
||||
Colors are specified using ANSI escape code.
|
||||
In terminals or other output destinations that do not support ANSI escape code, the output may become difficult to read.
|
||||
|
||||
Macros
|
||||
#
|
||||
|
||||
|
||||
TOML11_COLORIZE_ERROR_MESSAGE
|
||||
#
|
||||
|
||||
If this macro is defined during compilation (-DTOML11_COLORIZE_ERROR_MESASGE), error messages are colored by default.
|
||||
If not defined, colors are not applied by default. You need to specify them using toml::color::enable()."><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/reference/color/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="color.hpp"><meta property="og:description" content="color.hpp # In color.hpp, functions related to colorizing error messages are defined.
|
||||
Colors are specified using ANSI escape code. In terminals or other output destinations that do not support ANSI escape code, the output may become difficult to read.
|
||||
Macros # TOML11_COLORIZE_ERROR_MESSAGE # If this macro is defined during compilation (-DTOML11_COLORIZE_ERROR_MESASGE), error messages are colored by default.
|
||||
If not defined, colors are not applied by default. You need to specify them using toml::color::enable()."><meta property="og:locale" content="en"><meta property="og:type" content="article"><meta property="article:section" content="docs"><title>color.hpp | toml11</title><link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/reference/color/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/reference/color/ title=color.hpp><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" crossorigin=anonymous></script></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
|
||||
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
|
||||
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
|
||||
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/reference/color/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle>
|
||||
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle checked>
|
||||
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/ class=active>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
|
||||
</label><strong>color.hpp</strong>
|
||||
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#colorhpp>color.hpp</a><ul><li><a href=#macros>Macros</a><ul><li><a href=#toml11_colorize_error_message><code>TOML11_COLORIZE_ERROR_MESSAGE</code></a></li><li><a href=#toml11_use_thread_local_colorization><code>TOML11_USE_THREAD_LOCAL_COLORIZATION</code></a></li></ul></li><li><a href=#functions>Functions</a><ul><li><a href=#enable><code>enable()</code></a></li><li><a href=#disable><code>disable()</code></a></li><li><a href=#should_color><code>should_color()</code></a></li></ul></li><li><a href=#manipulators>Manipulators</a><ul><li></li></ul></li></ul></li><li><a href=#related>Related</a></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=colorhpp>color.hpp
|
||||
<a class=anchor href=#colorhpp>#</a></h1><p>In <code>color.hpp</code>, functions related to colorizing error messages are defined.</p><p>Colors are specified using ANSI escape code.
|
||||
In terminals or other output destinations that do not support ANSI escape code, the output may become difficult to read.</p><h2 id=macros>Macros
|
||||
<a class=anchor href=#macros>#</a></h2><h3 id=toml11_colorize_error_message><code>TOML11_COLORIZE_ERROR_MESSAGE</code>
|
||||
<a class=anchor href=#toml11_colorize_error_message>#</a></h3><p>If this macro is defined during compilation (<code>-DTOML11_COLORIZE_ERROR_MESASGE</code>), error messages are colored by default.</p><p>If not defined, colors are not applied by default. You need to specify them using <code>toml::color::enable()</code>.</p><h3 id=toml11_use_thread_local_colorization><code>TOML11_USE_THREAD_LOCAL_COLORIZATION</code>
|
||||
<a class=anchor href=#toml11_use_thread_local_colorization>#</a></h3><p>If this macro is defined during compilation (<code>-DTOML11_USE_THREAD_LOCAL_COLORIZATION</code>), the colorization flag becomes <code>thread_local</code>.
|
||||
In this case, <code>toml::color::enable()</code> or <code>toml::color::disable()</code> will only affect the colorization flag in the thread that called it.
|
||||
This means that if you want to use a different setting from the default, you will need to set it again when starting a new thread.
|
||||
This makes <code>toml::color::enable()</code> and <code>toml::color::disable()</code> thread safe.</p><p>By default, the setting is global.
|
||||
When it is global, if one thread executes <code>toml::color::enable()</code>, the error messages will be colored in all threads.
|
||||
However, if one thread executes <code>enable()</code> or <code>disable()</code> while another executes <code>enable()</code>, <code>disable()</code> or <code>should_color()</code>, the result is undefined.</p><h2 id=functions>Functions
|
||||
<a class=anchor href=#functions>#</a></h2><h3 id=enable><code>enable()</code>
|
||||
<a class=anchor href=#enable>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml {
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>namespace</span> color {
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>void</span> <span style=color:#a6e22e>enable</span>();
|
||||
</span></span><span style=display:flex><span>} <span style=color:#75715e>// color
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>} <span style=color:#75715e>// toml
|
||||
</span></span></span></code></pre></div><p>Enables colorization using ANSI escape code.</p><h4 id=example>Example
|
||||
<a class=anchor href=#example>#</a></h4><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><toml.hpp></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> toml<span style=color:#f92672>::</span>color<span style=color:#f92672>::</span>enable(); <span style=color:#75715e>// All subsequent errors will be colored.
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span> <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> input <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>parse(<span style=color:#e6db74>"input.toml"</span>);
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><h3 id=disable><code>disable()</code>
|
||||
<a class=anchor href=#disable>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml {
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>namespace</span> color {
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>void</span> <span style=color:#a6e22e>disable</span>();
|
||||
</span></span><span style=display:flex><span>} <span style=color:#75715e>// color
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>} <span style=color:#75715e>// toml
|
||||
</span></span></span></code></pre></div><p>Disables colorization using ANSI escape code.</p><h4 id=example-1>Example
|
||||
<a class=anchor href=#example-1>#</a></h4><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><toml.hpp></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> toml<span style=color:#f92672>::</span>color<span style=color:#f92672>::</span>disable(); <span style=color:#75715e>// All subsequent errors will not be colored.
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span> <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> input <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>parse(<span style=color:#e6db74>"input.toml"</span>);
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><h3 id=should_color><code>should_color()</code>
|
||||
<a class=anchor href=#should_color>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml {
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>namespace</span> color {
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>bool</span> <span style=color:#a6e22e>should_color</span>();
|
||||
</span></span><span style=display:flex><span>} <span style=color:#75715e>// color
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>} <span style=color:#75715e>// toml
|
||||
</span></span></span></code></pre></div><p>Returns <code>true</code> if colorization is enabled, <code>false</code> otherwise.</p><h4 id=example-2>Example
|
||||
<a class=anchor href=#example-2>#</a></h4><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><toml.hpp></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><iomanip></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><iostream></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>cout <span style=color:#f92672><<</span> <span style=color:#e6db74>"colorized? : "</span> <span style=color:#f92672><<</span> std<span style=color:#f92672>::</span>boolalpha <span style=color:#f92672><<</span> toml<span style=color:#f92672>::</span>color<span style=color:#f92672>::</span>should_color() <span style=color:#f92672><<</span> std<span style=color:#f92672>::</span>endl;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><h2 id=manipulators>Manipulators
|
||||
<a class=anchor href=#manipulators>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml {
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>namespace</span> color {
|
||||
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&</span> reset (std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&</span>);
|
||||
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&</span> bold (std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&</span>);
|
||||
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&</span> grey (std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&</span>);
|
||||
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&</span> gray (std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&</span>);
|
||||
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&</span> red (std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&</span>);
|
||||
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&</span> green (std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&</span>);
|
||||
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&</span> yellow (std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&</span>);
|
||||
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&</span> blue (std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&</span>);
|
||||
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&</span> magenta(std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&</span>);
|
||||
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&</span> cyan (std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&</span>);
|
||||
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&</span> white (std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&</span>);
|
||||
</span></span><span style=display:flex><span>} <span style=color:#75715e>// color
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>} <span style=color:#75715e>// toml
|
||||
</span></span></span></code></pre></div><p>Colorizes the foreground with ANSI escape code.</p><h4 id=example-3>Example
|
||||
<a class=anchor href=#example-3>#</a></h4><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><toml.hpp></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><iostream></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>cout <span style=color:#f92672><<</span> toml<span style=color:#f92672>::</span>color<span style=color:#f92672>::</span>red <span style=color:#f92672><<</span> <span style=color:#e6db74>"red!"</span> <span style=color:#f92672><<</span> toml<span style=color:#f92672>::</span>color<span style=color:#f92672>::</span>reset <span style=color:#f92672><<</span> std<span style=color:#f92672>::</span>endl;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><h1 id=related>Related
|
||||
<a class=anchor href=#related>#</a></h1><ul><li><a href=https://toruniina.github.io/toml11/docs/reference/error_info/>error_info.hpp</a></li></ul></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#colorhpp>color.hpp</a><ul><li><a href=#macros>Macros</a><ul><li><a href=#toml11_colorize_error_message><code>TOML11_COLORIZE_ERROR_MESSAGE</code></a></li><li><a href=#toml11_use_thread_local_colorization><code>TOML11_USE_THREAD_LOCAL_COLORIZATION</code></a></li></ul></li><li><a href=#functions>Functions</a><ul><li><a href=#enable><code>enable()</code></a></li><li><a href=#disable><code>disable()</code></a></li><li><a href=#should_color><code>should_color()</code></a></li></ul></li><li><a href=#manipulators>Manipulators</a><ul><li></li></ul></li></ul></li><li><a href=#related>Related</a></li></ul></nav></div></aside></main></body></html>
|
||||
319
docs/reference/comments/index.html
Normal file
319
docs/reference/comments/index.html
Normal file
File diff suppressed because one or more lines are too long
52
docs/reference/conversion/index.html
Normal file
52
docs/reference/conversion/index.html
Normal file
@@ -0,0 +1,52 @@
|
||||
<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
|
||||
conversion.hpp
|
||||
#
|
||||
|
||||
Provides macros to automatically define conversion functions for supporting user-defined types with toml::get and toml::find.
|
||||
TOML11_DEFINE_CONVERSION_NON_INTRUSIVE(NAME, ...)
|
||||
|
||||
Example
|
||||
#
|
||||
|
||||
namespace foo
|
||||
{
|
||||
struct Foo
|
||||
{
|
||||
std::string s;
|
||||
double d;
|
||||
int i;
|
||||
};
|
||||
} // foo
|
||||
|
||||
TOML11_DEFINE_CONVERSION_NON_INTRUSIVE(foo::Foo, s, d, i)
|
||||
|
||||
Related
|
||||
#
|
||||
|
||||
|
||||
from.hpp
|
||||
into.hpp
|
||||
"><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/reference/conversion/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="conversion.hpp"><meta property="og:description" content="conversion.hpp # Provides macros to automatically define conversion functions for supporting user-defined types with toml::get and toml::find.
|
||||
TOML11_DEFINE_CONVERSION_NON_INTRUSIVE(NAME, ...) Example # namespace foo { struct Foo { std::string s; double d; int i; }; } // foo TOML11_DEFINE_CONVERSION_NON_INTRUSIVE(foo::Foo, s, d, i) Related # from.hpp into.hpp"><meta property="og:locale" content="en"><meta property="og:type" content="article"><meta property="article:section" content="docs"><title>conversion.hpp | toml11</title><link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/reference/conversion/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/reference/conversion/ title=conversion.hpp><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" crossorigin=anonymous></script></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
|
||||
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
|
||||
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
|
||||
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/reference/conversion/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle>
|
||||
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle checked>
|
||||
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/ class=active>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
|
||||
</label><strong>conversion.hpp</strong>
|
||||
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#conversionhpp>conversion.hpp</a><ul><li><a href=#example>Example</a></li></ul></li><li><a href=#related>Related</a></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=conversionhpp>conversion.hpp
|
||||
<a class=anchor href=#conversionhpp>#</a></h1><p>Provides macros to automatically define conversion functions for supporting user-defined types with <code>toml::get</code> and <code>toml::find</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>TOML11_DEFINE_CONVERSION_NON_INTRUSIVE(NAME, ...)
|
||||
</span></span></code></pre></div><h2 id=example>Example
|
||||
<a class=anchor href=#example>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> foo
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>Foo</span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string s;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>double</span> d;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>int</span> i;
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span><span style=display:flex><span>} <span style=color:#75715e>// foo
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span>TOML11_DEFINE_CONVERSION_NON_INTRUSIVE(foo<span style=color:#f92672>::</span>Foo, s, d, i)
|
||||
</span></span></code></pre></div><h1 id=related>Related
|
||||
<a class=anchor href=#related>#</a></h1><ul><li><a href=https://toruniina.github.io/toml11/docs/reference/from/>from.hpp</a></li><li><a href=https://toruniina.github.io/toml11/docs/reference/into/>into.hpp</a></li></ul></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#conversionhpp>conversion.hpp</a><ul><li><a href=#example>Example</a></li></ul></li><li><a href=#related>Related</a></li></ul></nav></div></aside></main></body></html>
|
||||
396
docs/reference/datetime/index.html
Normal file
396
docs/reference/datetime/index.html
Normal file
File diff suppressed because one or more lines are too long
120
docs/reference/error_info/index.html
Normal file
120
docs/reference/error_info/index.html
Normal file
@@ -0,0 +1,120 @@
|
||||
<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content='
|
||||
error_info.hpp
|
||||
#
|
||||
|
||||
In error_info.hpp, definitions for error_info and functions to format it are provided.
|
||||
|
||||
toml::error_info
|
||||
#
|
||||
|
||||
namespace toml
|
||||
{
|
||||
struct error_info
|
||||
{
|
||||
error_info(std::string t, source_location l, std::string m, std::string s = "");
|
||||
error_info(std::string t, std::vector<std::pair<source_location, std::string>> l, std::string s = "");
|
||||
|
||||
std::string const& title() const noexcept;
|
||||
std::string & title() noexcept;
|
||||
|
||||
std::vector<std::pair<source_location, std::string>> const& locations() const noexcept;
|
||||
void add_locations(source_location loc, std::string msg) noexcept;
|
||||
|
||||
std::string const& suffix() const noexcept;
|
||||
std::string & suffix() noexcept;
|
||||
};
|
||||
|
||||
template<typename ... Ts>
|
||||
error_info make_error_info(
|
||||
std::string title, source_location loc, std::string msg, Ts&& ... tail);
|
||||
|
||||
std::string format_error(const std::string& errkind, const error_info& err);
|
||||
std::string format_error(const error_info& err);
|
||||
|
||||
template<typename ... Ts>
|
||||
std::string format_error(std::string title,
|
||||
source_location loc, std::string msg, Ts&& ... tail);
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const error_info& e);
|
||||
}
|
||||
|
||||
Member Functions
|
||||
#
|
||||
|
||||
|
||||
Constructor (title, loc, msg, suffix)
|
||||
#
|
||||
|
||||
Constructs error_info with specified title, location information loc, message msg, and optional suffix.'><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/reference/error_info/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="error_info.hpp"><meta property="og:description" content='error_info.hpp # In error_info.hpp, definitions for error_info and functions to format it are provided.
|
||||
toml::error_info # namespace toml { struct error_info { error_info(std::string t, source_location l, std::string m, std::string s = ""); error_info(std::string t, std::vector<std::pair<source_location, std::string>> l, std::string s = ""); std::string const& title() const noexcept; std::string & title() noexcept; std::vector<std::pair<source_location, std::string>> const& locations() const noexcept; void add_locations(source_location loc, std::string msg) noexcept; std::string const& suffix() const noexcept; std::string & suffix() noexcept; }; template<typename ... Ts> error_info make_error_info( std::string title, source_location loc, std::string msg, Ts&& ... tail); std::string format_error(const std::string& errkind, const error_info& err); std::string format_error(const error_info& err); template<typename ... Ts> std::string format_error(std::string title, source_location loc, std::string msg, Ts&& ... tail); std::ostream& operator<<(std::ostream& os, const error_info& e); } Member Functions # Constructor (title, loc, msg, suffix) # Constructs error_info with specified title, location information loc, message msg, and optional suffix.'><meta property="og:locale" content="en"><meta property="og:type" content="article"><meta property="article:section" content="docs"><title>error_info.hpp | toml11</title><link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/reference/error_info/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/reference/error_info/ title=error_info.hpp><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" crossorigin=anonymous></script></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
|
||||
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
|
||||
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
|
||||
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/reference/error_info/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle>
|
||||
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle checked>
|
||||
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/ class=active>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
|
||||
</label><strong>error_info.hpp</strong>
|
||||
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#error_infohpp>error_info.hpp</a></li><li><a href=#tomlerror_info><code>toml::error_info</code></a><ul><li><a href=#member-functions>Member Functions</a><ul><li><a href=#constructor-title-loc-msg-suffix>Constructor (<code>title, loc, msg, suffix</code>)</a></li><li><a href=#constructor-title-loc-msg--suffix>Constructor (<code>title, [{loc, msg}, ...], suffix</code>)</a></li><li><a href=#stdstring-title><code>std::string title()</code></a></li><li><a href=#stdvectorstdpairsource_location-stdstring-locations><code>std::vector<std::pair<source_location, std::string>> locations()</code></a></li><li><a href=#stdstring-suffix><code>std::string suffix()</code></a></li></ul></li><li><a href=#non-member-functions>Non-Member Functions</a><ul><li><a href=#make_error_info><code>make_error_info</code></a></li><li><a href=#format_error><code>format_error</code></a></li><li><a href=#stream-operator>Stream Operator</a></li></ul></li></ul></li><li><a href=#related>Related</a></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=error_infohpp>error_info.hpp
|
||||
<a class=anchor href=#error_infohpp>#</a></h1><p>In <code>error_info.hpp</code>, definitions for <code>error_info</code> and functions to format it are provided.</p><h1 id=tomlerror_info><code>toml::error_info</code>
|
||||
<a class=anchor href=#tomlerror_info>#</a></h1><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>error_info</span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> error_info(std<span style=color:#f92672>::</span>string t, source_location l, std<span style=color:#f92672>::</span>string m, std<span style=color:#f92672>::</span>string s <span style=color:#f92672>=</span> <span style=color:#e6db74>""</span>);
|
||||
</span></span><span style=display:flex><span> error_info(std<span style=color:#f92672>::</span>string t, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>pair<span style=color:#f92672><</span>source_location, std<span style=color:#f92672>::</span>string<span style=color:#f92672>>></span> l, std<span style=color:#f92672>::</span>string s <span style=color:#f92672>=</span> <span style=color:#e6db74>""</span>);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> title() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string <span style=color:#f92672>&</span> title() <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>pair<span style=color:#f92672><</span>source_location, std<span style=color:#f92672>::</span>string<span style=color:#f92672>>></span> <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> locations() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>void</span> <span style=color:#a6e22e>add_locations</span>(source_location loc, std<span style=color:#f92672>::</span>string msg) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> suffix() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string <span style=color:#f92672>&</span> suffix() <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> ... Ts<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>error_info make_error_info(
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string title, source_location loc, std<span style=color:#f92672>::</span>string msg, Ts<span style=color:#f92672>&&</span> ... tail);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>string format_error(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> errkind, <span style=color:#66d9ef>const</span> error_info<span style=color:#f92672>&</span> err);
|
||||
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>string format_error(<span style=color:#66d9ef>const</span> error_info<span style=color:#f92672>&</span> err);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> ... Ts<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>string format_error(std<span style=color:#f92672>::</span>string title,
|
||||
</span></span><span style=display:flex><span> source_location loc, std<span style=color:#f92672>::</span>string msg, Ts<span style=color:#f92672>&&</span> ... tail);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672><<</span>(std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&</span> os, <span style=color:#66d9ef>const</span> error_info<span style=color:#f92672>&</span> e);
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><h2 id=member-functions>Member Functions
|
||||
<a class=anchor href=#member-functions>#</a></h2><h3 id=constructor-title-loc-msg-suffix>Constructor (<code>title, loc, msg, suffix</code>)
|
||||
<a class=anchor href=#constructor-title-loc-msg-suffix>#</a></h3><p>Constructs <code>error_info</code> with specified <code>title</code>, location information <code>loc</code>, message <code>msg</code>, and optional <code>suffix</code>.</p><p><code>suffix</code> defaults to empty.</p><h3 id=constructor-title-loc-msg--suffix>Constructor (<code>title, [{loc, msg}, ...], suffix</code>)
|
||||
<a class=anchor href=#constructor-title-loc-msg--suffix>#</a></h3><p>Constructs <code>error_info</code> with specified <code>title</code>, an array of location-message pairs <code>[{loc, msg}, ...]</code>, and optional <code>suffix</code>.</p><p><code>suffix</code> defaults to empty.</p><h3 id=stdstring-title><code>std::string title()</code>
|
||||
<a class=anchor href=#stdstring-title>#</a></h3><p>Returns the title of the error message.</p><h3 id=stdvectorstdpairsource_location-stdstring-locations><code>std::vector<std::pair<source_location, std::string>> locations()</code>
|
||||
<a class=anchor href=#stdvectorstdpairsource_location-stdstring-locations>#</a></h3><p>Returns the list of locations where errors occurred along with their respective messages.</p><p>Multiple locations can be specified.</p><h3 id=stdstring-suffix><code>std::string suffix()</code>
|
||||
<a class=anchor href=#stdstring-suffix>#</a></h3><p>Returns the suffix message to display at the end, providing hints or additional information.</p><h2 id=non-member-functions>Non-Member Functions
|
||||
<a class=anchor href=#non-member-functions>#</a></h2><h3 id=make_error_info><code>make_error_info</code>
|
||||
<a class=anchor href=#make_error_info>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> ... Ts<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>error_info make_error_info(
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string title, source_location loc, std<span style=color:#f92672>::</span>string msg, Ts<span style=color:#f92672>&&</span> ... tail);
|
||||
</span></span></code></pre></div><p>Creates a new <code>error_info</code>.</p><p>Must be followed by a <code>msg</code> related to <code>source_location</code> or <code>basic_value</code>.</p><p>Overloads are added in <a href=https://toruniina.github.io/toml11/docs/reference/value/#tomlmake_error_info><code>value.hpp</code></a> when passing <code>toml::basic_value</code> instead of <code>source_location</code>.</p><p>Possible to pass <code>suffix</code> at the end.</p><h3 id=format_error><code>format_error</code>
|
||||
<a class=anchor href=#format_error>#</a></h3><p>Formats <code>error_info</code> as follows:</p><pre tabindex=0><code>{title}
|
||||
--> {locations().at(0).first.file_name()}
|
||||
|
|
||||
1 | {locations().at(0).first.line()}
|
||||
| ^-- {locations().at(0).second}
|
||||
|
|
||||
2 | {locations().at(1).first.line()}
|
||||
| ^-- {locations().at(1).second}
|
||||
{suffix}
|
||||
</code></pre><p>If file names differ between two <code>source_location</code>, the file name is displayed again.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>std<span style=color:#f92672>::</span>string format_error(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> errkind, <span style=color:#66d9ef>const</span> error_info<span style=color:#f92672>&</span> err);
|
||||
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>string format_error(<span style=color:#66d9ef>const</span> error_info<span style=color:#f92672>&</span> err);
|
||||
</span></span></code></pre></div><p>Formats <code>error_info</code>.</p><p>If <code>errkind</code> is not provided, a red-bold <code>[error]</code> prefix is added before <code>title</code>.</p><p>If <code>errkind</code> is provided (including an empty string), it replaces <code>[error]</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> ... Ts<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>string format_error(std<span style=color:#f92672>::</span>string title,
|
||||
</span></span><span style=display:flex><span> source_location loc, std<span style=color:#f92672>::</span>string msg, Ts<span style=color:#f92672>&&</span> ... tail);
|
||||
</span></span><span style=display:flex><span>} <span style=color:#75715e>// toml
|
||||
</span></span></span></code></pre></div><p>Returns a formatted string using <code>format_error</code> for <code>error_info</code> created with <code>make_error_info</code>.</p><p>Overloads are added in <a href=https://toruniina.github.io/toml11/docs/reference/value/#tomlformat_error><code>value.hpp</code></a> when passing <code>toml::basic_value</code> instead of <code>source_location</code>.</p><h3 id=stream-operator>Stream Operator
|
||||
<a class=anchor href=#stream-operator>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672><<</span>(std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&</span> os, <span style=color:#66d9ef>const</span> error_info<span style=color:#f92672>&</span> e);
|
||||
</span></span></code></pre></div><p>Calls <code>format_error(e)</code> and outputs it.</p><h1 id=related>Related
|
||||
<a class=anchor href=#related>#</a></h1><ul><li><a href=https://toruniina.github.io/toml11/docs/reference/color/>color.hpp</a></li><li><a href=https://toruniina.github.io/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=https://toruniina.github.io/toml11/docs/reference/source_location/>source_location.hpp</a></li></ul></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#error_infohpp>error_info.hpp</a></li><li><a href=#tomlerror_info><code>toml::error_info</code></a><ul><li><a href=#member-functions>Member Functions</a><ul><li><a href=#constructor-title-loc-msg-suffix>Constructor (<code>title, loc, msg, suffix</code>)</a></li><li><a href=#constructor-title-loc-msg--suffix>Constructor (<code>title, [{loc, msg}, ...], suffix</code>)</a></li><li><a href=#stdstring-title><code>std::string title()</code></a></li><li><a href=#stdvectorstdpairsource_location-stdstring-locations><code>std::vector<std::pair<source_location, std::string>> locations()</code></a></li><li><a href=#stdstring-suffix><code>std::string suffix()</code></a></li></ul></li><li><a href=#non-member-functions>Non-Member Functions</a><ul><li><a href=#make_error_info><code>make_error_info</code></a></li><li><a href=#format_error><code>format_error</code></a></li><li><a href=#stream-operator>Stream Operator</a></li></ul></li></ul></li><li><a href=#related>Related</a></li></ul></nav></div></aside></main></body></html>
|
||||
59
docs/reference/exception/index.html
Normal file
59
docs/reference/exception/index.html
Normal file
@@ -0,0 +1,59 @@
|
||||
<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content='
|
||||
exception.hpp
|
||||
#
|
||||
|
||||
|
||||
toml::exception
|
||||
#
|
||||
|
||||
Base class for exception types defined in toml11.
|
||||
namespace toml
|
||||
{
|
||||
struct exception : public std::exception
|
||||
{
|
||||
public:
|
||||
virtual ~exception() noexcept override = default;
|
||||
virtual const char* what() const noexcept override {return "";}
|
||||
};
|
||||
} // toml
|
||||
|
||||
Member Functions
|
||||
#
|
||||
|
||||
|
||||
Destructor
|
||||
#
|
||||
|
||||
virtual ~exception() noexcept override = default;
|
||||
Override when derived.
|
||||
|
||||
what
|
||||
#
|
||||
|
||||
virtual const char* what() const noexcept override {return "";}
|
||||
Returns the error message. Override when derived.'><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/reference/exception/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="exception.hpp"><meta property="og:description" content='exception.hpp # toml::exception # Base class for exception types defined in toml11.
|
||||
namespace toml { struct exception : public std::exception { public: virtual ~exception() noexcept override = default; virtual const char* what() const noexcept override {return "";} }; } // toml Member Functions # Destructor # virtual ~exception() noexcept override = default; Override when derived.
|
||||
what # virtual const char* what() const noexcept override {return "";} Returns the error message. Override when derived.'><meta property="og:locale" content="en"><meta property="og:type" content="article"><meta property="article:section" content="docs"><title>exception.hpp | toml11</title><link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/reference/exception/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/reference/exception/ title=exception.hpp><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" crossorigin=anonymous></script></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
|
||||
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
|
||||
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
|
||||
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/reference/exception/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle>
|
||||
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle checked>
|
||||
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/ class=active>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
|
||||
</label><strong>exception.hpp</strong>
|
||||
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#exceptionhpp>exception.hpp</a></li><li><a href=#tomlexception><code>toml::exception</code></a><ul><li><a href=#member-functions>Member Functions</a><ul><li><a href=#destructor>Destructor</a></li><li><a href=#what><code>what</code></a></li></ul></li></ul></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=exceptionhpp>exception.hpp
|
||||
<a class=anchor href=#exceptionhpp>#</a></h1><h1 id=tomlexception><code>toml::exception</code>
|
||||
<a class=anchor href=#tomlexception>#</a></h1><p>Base class for exception types defined in toml11.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>exception</span> <span style=color:#f92672>:</span> <span style=color:#66d9ef>public</span> std<span style=color:#f92672>::</span>exception
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>public</span><span style=color:#f92672>:</span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>virtual</span> <span style=color:#f92672>~</span>exception() <span style=color:#66d9ef>noexcept</span> <span style=color:#66d9ef>override</span> <span style=color:#f92672>=</span> <span style=color:#66d9ef>default</span>;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>virtual</span> <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>char</span><span style=color:#f92672>*</span> <span style=color:#a6e22e>what</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span> <span style=color:#66d9ef>override</span> {<span style=color:#66d9ef>return</span> <span style=color:#e6db74>""</span>;}
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span><span style=display:flex><span>} <span style=color:#75715e>// toml
|
||||
</span></span></span></code></pre></div><h2 id=member-functions>Member Functions
|
||||
<a class=anchor href=#member-functions>#</a></h2><h3 id=destructor>Destructor
|
||||
<a class=anchor href=#destructor>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>virtual</span> <span style=color:#f92672>~</span>exception() <span style=color:#66d9ef>noexcept</span> <span style=color:#66d9ef>override</span> <span style=color:#f92672>=</span> <span style=color:#66d9ef>default</span>;
|
||||
</span></span></code></pre></div><p>Override when derived.</p><h3 id=what><code>what</code>
|
||||
<a class=anchor href=#what>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>virtual</span> <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>char</span><span style=color:#f92672>*</span> <span style=color:#a6e22e>what</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span> <span style=color:#66d9ef>override</span> {<span style=color:#66d9ef>return</span> <span style=color:#e6db74>""</span>;}
|
||||
</span></span></code></pre></div><p>Returns the error message. Override when derived.</p></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#exceptionhpp>exception.hpp</a></li><li><a href=#tomlexception><code>toml::exception</code></a><ul><li><a href=#member-functions>Member Functions</a><ul><li><a href=#destructor>Destructor</a></li><li><a href=#what><code>what</code></a></li></ul></li></ul></li></ul></nav></div></aside></main></body></html>
|
||||
132
docs/reference/find/index.html
Normal file
132
docs/reference/find/index.html
Normal file
@@ -0,0 +1,132 @@
|
||||
<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
|
||||
find.hpp
|
||||
#
|
||||
|
||||
This function searches for a value in a toml::value and performs type conversion if necessary.
|
||||
|
||||
toml::value can change the type it stores, and toml::find accommodates these types.
|
||||
Technically, all functions use toml::basic_value<TC>.
|
||||
However, for simplicity, we refer to it as toml::value in explanations unless a distinction is necessary.
|
||||
In the documentation, if the template parameter TC changes the type, assume that types like toml::value::integer_type will also change accordingly.
|
||||
|
||||
|
||||
|
||||
toml::find
|
||||
#
|
||||
|
||||
|
||||
Overview
|
||||
#
|
||||
|
||||
toml::find uses template arguments for the type you want to retrieve and function arguments for the key of the value you want to find."><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/reference/find/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="find.hpp"><meta property="og:description" content="find.hpp # This function searches for a value in a toml::value and performs type conversion if necessary.
|
||||
toml::value can change the type it stores, and toml::find accommodates these types. Technically, all functions use toml::basic_value<TC>. However, for simplicity, we refer to it as toml::value in explanations unless a distinction is necessary. In the documentation, if the template parameter TC changes the type, assume that types like toml::value::integer_type will also change accordingly. toml::find # Overview # toml::find uses template arguments for the type you want to retrieve and function arguments for the key of the value you want to find."><meta property="og:locale" content="en"><meta property="og:type" content="article"><meta property="article:section" content="docs"><title>find.hpp | toml11</title><link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/reference/find/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/reference/find/ title=find.hpp><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" crossorigin=anonymous></script></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
|
||||
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
|
||||
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
|
||||
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/reference/find/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle>
|
||||
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle checked>
|
||||
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/ class=active>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
|
||||
</label><strong>find.hpp</strong>
|
||||
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#findhpp>find.hpp</a></li><li><a href=#tomlfind><code>toml::find</code></a><ul><li><a href=#overview>Overview</a><ul><li><a href=#note-on-recursive-search>Note on Recursive Search</a></li></ul></li><li><a href=#tomlfindvalue-key><code>toml::find(value, key)</code></a><ul><li><a href=#exceptions>Exceptions</a></li></ul></li><li><a href=#tomlfindvalue-index><code>toml::find(value, index)</code></a><ul><li><a href=#exceptions-1>Exceptions</a></li></ul></li><li><a href=#tomlfindvalue-keys><code>toml::find(value, keys...)</code></a></li></ul></li><li><a href=#tomlfind_orvalue-key-fallback><code>toml::find_or(value, key, fallback)</code></a><ul><li><a href=#when-t-is-basic_value>When <code>T</code> is <code>basic_value</code></a></li><li><a href=#when-t-is-tomlvaluesome_type>When <code>T</code> is <code>toml::value::{some_type}</code></a></li><li><a href=#when-t-is-const-char>When <code>T</code> is <code>const char*</code></a></li><li><a href=#when-t-is-any-other-type>When <code>T</code> is any other type</a></li><li><a href=#when-multiple-keys-are-provided>When multiple keys are provided</a></li></ul></li><li><a href=#related>Related</a></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=findhpp>find.hpp
|
||||
<a class=anchor href=#findhpp>#</a></h1><p>This function searches for a value in a <code>toml::value</code> and performs type conversion if necessary.</p><blockquote class="book-hint info"><code>toml::value</code> can change the type it stores, and <code>toml::find</code> accommodates these types.
|
||||
Technically, all functions use <code>toml::basic_value<TC></code>.
|
||||
However, for simplicity, we refer to it as <code>toml::value</code> in explanations unless a distinction is necessary.
|
||||
In the documentation, if the template parameter <code>TC</code> changes the type, assume that types like <code>toml::value::integer_type</code> will also change accordingly.</blockquote><h1 id=tomlfind><code>toml::find</code>
|
||||
<a class=anchor href=#tomlfind>#</a></h1><h2 id=overview>Overview
|
||||
<a class=anchor href=#overview>#</a></h2><p><code>toml::find</code> uses template arguments for the type you want to retrieve and function arguments for the key of the value you want to find.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC, <span style=color:#66d9ef>typename</span> ... Keys<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>T find(<span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v, Keys ... keys);
|
||||
</span></span></code></pre></div><p>The supported types for <code>T</code> and the behavior of the conversion are the same as for <code>toml::get</code>.</p><p>If <code>T</code> is not specified, a <code>toml::value</code> will be returned.</p><p>Keys can be of type <code>toml::value::key_type</code> or <code>std::size_t</code>.
|
||||
When multiple keys are provided, the function will search recursively through sub-tables or arrays.
|
||||
If a <code>toml::value::key_type</code> is given, <code>toml::value</code> is interpreted as a <code>toml::table</code>; if a <code>std::size_t</code> is given, <code>toml::value</code> is interpreted as a <code>toml::array</code>.</p><h3 id=note-on-recursive-search>Note on Recursive Search
|
||||
<a class=anchor href=#note-on-recursive-search>#</a></h3><p>TOML allows for bare keys as well as quoted keys (enclosed in <code>"</code> or <code>'</code>). Using a quoted key like <code>"foo.bar" = "baz"</code> means no sub-table is constructed, and the key is <code>"foo.bar"</code>. To handle such patterns, toml11 does not split keys containing <code>.</code> and searches using the full string.</p><p>Consider the following TOML file:</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-toml data-lang=toml><span style=display:flex><span>[<span style=color:#a6e22e>foo</span>]
|
||||
</span></span><span style=display:flex><span>[<span style=color:#a6e22e>foo</span>.<span style=color:#a6e22e>bar</span>]
|
||||
</span></span><span style=display:flex><span><span style=color:#a6e22e>baz</span> = <span style=color:#e6db74>"hoge"</span>
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span>[<span style=color:#e6db74>"foo.bar"</span>]
|
||||
</span></span><span style=display:flex><span><span style=color:#a6e22e>baz</span> = <span style=color:#e6db74>"fuga"</span>
|
||||
</span></span></code></pre></div><p>The corresponding usage of <code>toml::find</code> is shown below:</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> input <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>parse(<span style=color:#e6db74>"input.toml"</span>);
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> baz1 <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>find<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span>(input, <span style=color:#e6db74>"foo"</span>, <span style=color:#e6db74>"bar"</span>, <span style=color:#e6db74>"baz"</span>); <span style=color:#75715e>// hoge
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> baz2 <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>find<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span>(input, <span style=color:#e6db74>"foo.bar"</span>, <span style=color:#e6db74>"baz"</span>); <span style=color:#75715e>// fuga
|
||||
</span></span></span></code></pre></div><p>cf. <a href=https://toml.io/en/v1.0.0#keys>toml.io/en/v1.0.0#keys</a></p><h2 id=tomlfindvalue-key><code>toml::find(value, key)</code>
|
||||
<a class=anchor href=#tomlfindvalue-key>#</a></h2><p>Searches for <code>key</code> in <code>value</code> as if <code>value</code> were a <code>toml::table</code>, then converts using <code>toml::get</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e>/* Equivalent to toml::get<T>(const value&) */</span> find(
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v, <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>typename</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>::</span>key_type<span style=color:#f92672>&</span> ky);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e>/* Equivalent to toml::get<T>(value&) */</span> find(
|
||||
</span></span><span style=display:flex><span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v, <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>typename</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>::</span>key_type<span style=color:#f92672>&</span> ky);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e>/* Equivalent to toml::get<T>(value&&) */</span> find(
|
||||
</span></span><span style=display:flex><span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&&</span> v, <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>typename</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>::</span>key_type<span style=color:#f92672>&</span> ky);
|
||||
</span></span></code></pre></div><p>If <code>T</code> is not specified, the function returns a <code>toml::value</code> without conversion.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>></span> <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> find(
|
||||
</span></span><span style=display:flex><span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>></span> <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> v, <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>typename</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>::</span>key_type<span style=color:#f92672>&</span> ky);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> find(
|
||||
</span></span><span style=display:flex><span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v, <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>typename</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>::</span>key_type<span style=color:#f92672>&</span> ky);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>></span> find(
|
||||
</span></span><span style=display:flex><span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&&</span> v, <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>typename</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>::</span>key_type<span style=color:#f92672>&</span> ky);
|
||||
</span></span></code></pre></div><h3 id=exceptions>Exceptions
|
||||
<a class=anchor href=#exceptions>#</a></h3><p>If the <code>toml::value</code> does not contain a <code>table</code>, a <code>toml::type_error</code> is thrown.</p><p>If the contained <code>table</code> does not have the specified element, a <code>std::out_of_range</code> is thrown.</p><p>If the specified element cannot be converted to <code>T</code> (i.e., <code>toml::get</code> fails), a <code>toml::type_error</code> is thrown.</p><h2 id=tomlfindvalue-index><code>toml::find(value, index)</code>
|
||||
<a class=anchor href=#tomlfindvalue-index>#</a></h2><p>Accesses the <code>index</code>-th element of <code>value</code> as if <code>value</code> were a <code>toml::array</code>, then converts using <code>toml::get</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e>/* Equivalent to toml::get<T>(const value&) */</span> find(
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v, <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>size_t index);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e>/* Equivalent to toml::get<T>(value&) */</span> find(
|
||||
</span></span><span style=display:flex><span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v, <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>size_t index);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e>/* Equivalent to toml::get<T>(value&&) */</span> find(
|
||||
</span></span><span style=display:flex><span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&&</span> v, <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>size_t index);
|
||||
</span></span></code></pre></div><p>If <code>T</code> is not specified, the function returns a <code>toml::value</code> without conversion.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>></span> <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> find(basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>></span> <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> v, <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>size_t ky);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> find(basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v, <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>size_t ky);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>></span> find(basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&&</span> v, <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>size_t ky);
|
||||
</span></span></code></pre></div><h3 id=exceptions-1>Exceptions
|
||||
<a class=anchor href=#exceptions-1>#</a></h3><p>If the <code>toml::value</code> does not contain an <code>array</code>, a <code>toml::type_error</code> is thrown.</p><p>If the contained <code>array</code> does not have the specified number of elements, a <code>std::out_of_range</code> is thrown.</p><p>If the specified element cannot be converted to <code>T</code> (i.e., <code>toml::get</code> fails), a <code>toml::type_error</code> is thrown.</p><h2 id=tomlfindvalue-keys><code>toml::find(value, keys...)</code>
|
||||
<a class=anchor href=#tomlfindvalue-keys>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC, <span style=color:#66d9ef>typename</span> K1, <span style=color:#66d9ef>typename</span> K2, <span style=color:#66d9ef>typename</span> ... Ks<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e>/* Equivalent to toml::get<T>(const value&) */</span> find(
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v, <span style=color:#66d9ef>const</span> K1<span style=color:#f92672>&</span> k1, <span style=color:#66d9ef>const</span> K2<span style=color:#f92672>&</span> k2, <span style=color:#66d9ef>const</span> Ks<span style=color:#f92672>&</span> ... ks);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC, <span style=color:#66d9ef>typename</span> K1, <span style=color:#66d9ef>typename</span> K2, <span style=color:#66d9ef>typename</span> ... Ks<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e>/* Equivalent to toml::get<T>(value&) */</span> find(
|
||||
</span></span><span style=display:flex><span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v, <span style=color:#66d9ef>const</span> K1<span style=color:#f92672>&</span> k1, <span style=color:#66d9ef>const</span> K2<span style=color:#f92672>&</span> k2, <span style=color:#66d9ef>const</span> Ks<span style=color:#f92672>&</span> ... ks);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC, <span style=color:#66d9ef>typename</span> K1, <span style=color:#66d9ef>typename</span> K2, <span style=color:#66d9ef>typename</span> ... Ks<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e>/* Equivalent to toml::get<T>(value&&) */</span> find(
|
||||
</span></span><span style=display:flex><span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&&</span> v, <span style=color:#66d9ef>const</span> K1<span style=color:#f92672>&</span> k1, <span style=color:#66d9ef>const</span> K2<span style=color:#f92672>&</span> k2, <span style=color:#66d9ef>const</span> Ks<span style=color:#f92672>&</span> ... ks);
|
||||
</span></span></code></pre></div><p>This function calls <code>toml::find</code> recursively.</p><p>The failure conditions and the exceptions thrown are the same as those for <code>toml::find</code>.</p><h1 id=tomlfind_orvalue-key-fallback><code>toml::find_or(value, key, fallback)</code>
|
||||
<a class=anchor href=#tomlfind_orvalue-key-fallback>#</a></h1><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC, <span style=color:#66d9ef>typename</span> Key<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>T find_or(<span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v, <span style=color:#66d9ef>const</span> Key<span style=color:#f92672>&</span> key, T<span style=color:#f92672>&&</span> opt);
|
||||
</span></span></code></pre></div><p>The <code>find_or</code> function takes a default value to avoid throwing an exception when the search fails.</p><p>The default value must be of the same type as the return type <code>T</code>. Therefore, unlike <code>toml::find<T></code>, <code>find_or</code> infers the type <code>T</code>.</p><p>You can specify <code>T</code> explicitly with <code>find_or<T></code>, but this always returns a new value. To obtain a reference, do not specify <code>T</code>.</p><h2 id=when-t-is-basic_value>When <code>T</code> is <code>basic_value</code>
|
||||
<a class=anchor href=#when-t-is-basic_value>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC, <span style=color:#66d9ef>typename</span> K<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> find_or(basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v, <span style=color:#66d9ef>const</span> K<span style=color:#f92672>&</span> key, basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> opt) <span style=color:#66d9ef>noexcept</span>
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC, <span style=color:#66d9ef>typename</span> K<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>></span> <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> find_or(<span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v, <span style=color:#66d9ef>const</span> K<span style=color:#f92672>&</span> key, <span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> opt) <span style=color:#66d9ef>noexcept</span>
|
||||
</span></span></code></pre></div><p>Searches for the corresponding value and returns it without conversion. Because no conversion is needed, a reference can be returned.</p><p>If the value is not found, the default value is returned.</p><h2 id=when-t-is-tomlvaluesome_type>When <code>T</code> is <code>toml::value::{some_type}</code>
|
||||
<a class=anchor href=#when-t-is-tomlvaluesome_type>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC, <span style=color:#66d9ef>typename</span> K<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>T<span style=color:#f92672>&</span> find_or(basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v, <span style=color:#66d9ef>const</span> K<span style=color:#f92672>&</span> key, T<span style=color:#f92672>&</span> opt) <span style=color:#66d9ef>noexcept</span>
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC, <span style=color:#66d9ef>typename</span> K<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>T <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> find_or(<span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v, <span style=color:#66d9ef>const</span> K<span style=color:#f92672>&</span> key, <span style=color:#66d9ef>const</span> T<span style=color:#f92672>&</span> opt) <span style=color:#66d9ef>noexcept</span>
|
||||
</span></span></code></pre></div><p>Searches for the corresponding value and returns it without conversion. Because no conversion is needed, a reference can be returned.</p><p>If the value is not found or if a different type is stored, the default value is returned.</p><h2 id=when-t-is-const-char>When <code>T</code> is <code>const char*</code>
|
||||
<a class=anchor href=#when-t-is-const-char>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC, <span style=color:#66d9ef>typename</span> K<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>T find_or(<span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v, <span style=color:#66d9ef>const</span> K<span style=color:#f92672>&</span> key, T opt)
|
||||
</span></span></code></pre></div><p>Searches for the corresponding value and returns it as a <code>std::string</code>.</p><p>Since the fallback is constructed from <code>const char*</code> to <code>std::string</code>, a reference cannot be returned in case of failure.</p><h2 id=when-t-is-any-other-type>When <code>T</code> is any other type
|
||||
<a class=anchor href=#when-t-is-any-other-type>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC, <span style=color:#66d9ef>typename</span> K<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>T find_or(<span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v, <span style=color:#66d9ef>const</span> K<span style=color:#f92672>&</span> key, T opt);
|
||||
</span></span></code></pre></div><p>Searches for the corresponding value and converts it to <code>T</code> before returning it.</p><p>Because conversion is performed, a reference cannot be returned.</p><h2 id=when-multiple-keys-are-provided>When multiple keys are provided
|
||||
<a class=anchor href=#when-multiple-keys-are-provided>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> Value, <span style=color:#66d9ef>typename</span> K1, <span style=color:#66d9ef>typename</span> K2, <span style=color:#66d9ef>typename</span> K3, <span style=color:#66d9ef>typename</span> ... Ks<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>auto</span> find_or(Value<span style=color:#f92672>&&</span> v, <span style=color:#66d9ef>const</span> K1<span style=color:#f92672>&</span> k1, <span style=color:#66d9ef>const</span> K2<span style=color:#f92672>&</span> k2, K3<span style=color:#f92672>&&</span> k3, Ks<span style=color:#f92672>&&</span> ... keys) <span style=color:#66d9ef>noexcept</span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#f92672>-></span> <span style=color:#66d9ef>decltype</span>(find_or(v, k2, std<span style=color:#f92672>::</span>forward<span style=color:#f92672><</span>K3<span style=color:#f92672>></span>(k3), std<span style=color:#f92672>::</span>forward<span style=color:#f92672><</span>Ks<span style=color:#f92672>></span>(keys)...))
|
||||
</span></span></code></pre></div><p>Interprets the last element in the key sequence as the default value and applies <code>find_or</code> recursively.</p><p>If the inferred type of <code>T</code> is <code>toml::value</code> or <code>toml::value::some_type</code>, a reference can be returned.</p><p>If <code>T</code> is explicitly specified, conversion is always performed.</p><h1 id=related>Related
|
||||
<a class=anchor href=#related>#</a></h1><ul><li><a href=https://toruniina.github.io/toml11/docs/reference/get/>get.hpp</a></li><li><a href=https://toruniina.github.io/toml11/docs/reference/value/>value.hpp</a></li></ul></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#findhpp>find.hpp</a></li><li><a href=#tomlfind><code>toml::find</code></a><ul><li><a href=#overview>Overview</a><ul><li><a href=#note-on-recursive-search>Note on Recursive Search</a></li></ul></li><li><a href=#tomlfindvalue-key><code>toml::find(value, key)</code></a><ul><li><a href=#exceptions>Exceptions</a></li></ul></li><li><a href=#tomlfindvalue-index><code>toml::find(value, index)</code></a><ul><li><a href=#exceptions-1>Exceptions</a></li></ul></li><li><a href=#tomlfindvalue-keys><code>toml::find(value, keys...)</code></a></li></ul></li><li><a href=#tomlfind_orvalue-key-fallback><code>toml::find_or(value, key, fallback)</code></a><ul><li><a href=#when-t-is-basic_value>When <code>T</code> is <code>basic_value</code></a></li><li><a href=#when-t-is-tomlvaluesome_type>When <code>T</code> is <code>toml::value::{some_type}</code></a></li><li><a href=#when-t-is-const-char>When <code>T</code> is <code>const char*</code></a></li><li><a href=#when-t-is-any-other-type>When <code>T</code> is any other type</a></li><li><a href=#when-multiple-keys-are-provided>When multiple keys are provided</a></li></ul></li><li><a href=#related>Related</a></li></ul></nav></div></aside></main></body></html>
|
||||
431
docs/reference/format/index.html
Normal file
431
docs/reference/format/index.html
Normal file
File diff suppressed because one or more lines are too long
92
docs/reference/from/index.html
Normal file
92
docs/reference/from/index.html
Normal file
@@ -0,0 +1,92 @@
|
||||
<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content='
|
||||
from.hpp
|
||||
#
|
||||
|
||||
Defines a struct used for conversion from toml::value in toml::get and toml::find.
|
||||
You can achieve the same functionality by adding a from_toml member function, but for classes where you cannot add member functions, use from<T>.
|
||||
This file does not provide specific implementations. Please specialize this struct when using.
|
||||
namespace toml
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
struct from;
|
||||
|
||||
} // toml
|
||||
|
||||
Example
|
||||
#
|
||||
|
||||
namespace extlib
|
||||
{
|
||||
struct foo
|
||||
{
|
||||
int a;
|
||||
std::string b;
|
||||
};
|
||||
} // extlib
|
||||
|
||||
#include <toml11/from.hpp>
|
||||
|
||||
namespace toml
|
||||
{
|
||||
template<>
|
||||
struct from<extlib::foo>
|
||||
{
|
||||
template<typename TC>
|
||||
static extlib::foo from_toml(const toml::basic_value<TC>& v)
|
||||
{
|
||||
return extlib::foo{toml::find<int>(v, "a"), toml::find<std::string>(v, "b")};
|
||||
}
|
||||
};
|
||||
} // toml
|
||||
|
||||
Related
|
||||
#
|
||||
|
||||
|
||||
conversion.hpp
|
||||
into.hpp
|
||||
'><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/reference/from/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="from.hpp"><meta property="og:description" content='from.hpp # Defines a struct used for conversion from toml::value in toml::get and toml::find.
|
||||
You can achieve the same functionality by adding a from_toml member function, but for classes where you cannot add member functions, use from<T>.
|
||||
This file does not provide specific implementations. Please specialize this struct when using.
|
||||
namespace toml { template<typename T> struct from; } // toml Example # namespace extlib { struct foo { int a; std::string b; }; } // extlib #include <toml11/from.hpp> namespace toml { template<> struct from<extlib::foo> { template<typename TC> static extlib::foo from_toml(const toml::basic_value<TC>& v) { return extlib::foo{toml::find<int>(v, "a"), toml::find<std::string>(v, "b")}; } }; } // toml Related # conversion.hpp into.hpp'><meta property="og:locale" content="en"><meta property="og:type" content="article"><meta property="article:section" content="docs"><title>from.hpp | toml11</title><link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/reference/from/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/reference/from/ title=from.hpp><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" crossorigin=anonymous></script></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
|
||||
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
|
||||
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
|
||||
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/reference/from/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle>
|
||||
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle checked>
|
||||
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/ class=active>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
|
||||
</label><strong>from.hpp</strong>
|
||||
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#fromhpp>from.hpp</a><ul><li><a href=#example>Example</a></li></ul></li><li><a href=#related>Related</a></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=fromhpp>from.hpp
|
||||
<a class=anchor href=#fromhpp>#</a></h1><p>Defines a <code>struct</code> used for conversion from <code>toml::value</code> in <code>toml::get</code> and <code>toml::find</code>.</p><p>You can achieve the same functionality by adding a <code>from_toml</code> member function, but for classes where you cannot add member functions, use <code>from<T></code>.</p><p>This file does not provide specific implementations. Please specialize this <code>struct</code> when using.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>from</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span>} <span style=color:#75715e>// toml
|
||||
</span></span></span></code></pre></div><h2 id=example>Example
|
||||
<a class=anchor href=#example>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> extlib
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>foo</span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>int</span> a;
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string b;
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span><span style=display:flex><span>} <span style=color:#75715e>// extlib
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><toml11/from.hpp></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>from</span><span style=color:#f92672><</span>extlib<span style=color:#f92672>::</span>foo<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>static</span> extlib<span style=color:#f92672>::</span>foo from_toml(<span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v)
|
||||
</span></span><span style=display:flex><span> {
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> extlib<span style=color:#f92672>::</span>foo{toml<span style=color:#f92672>::</span>find<span style=color:#f92672><</span><span style=color:#66d9ef>int</span><span style=color:#f92672>></span>(v, <span style=color:#e6db74>"a"</span>), toml<span style=color:#f92672>::</span>find<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span>(v, <span style=color:#e6db74>"b"</span>)};
|
||||
</span></span><span style=display:flex><span> }
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span><span style=display:flex><span>} <span style=color:#75715e>// toml
|
||||
</span></span></span></code></pre></div><h1 id=related>Related
|
||||
<a class=anchor href=#related>#</a></h1><ul><li><a href=https://toruniina.github.io/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=https://toruniina.github.io/toml11/docs/reference/into/>into.hpp</a></li></ul></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#fromhpp>from.hpp</a><ul><li><a href=#example>Example</a></li></ul></li><li><a href=#related>Related</a></li></ul></nav></div></aside></main></body></html>
|
||||
141
docs/reference/get/index.html
Normal file
141
docs/reference/get/index.html
Normal file
@@ -0,0 +1,141 @@
|
||||
<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
|
||||
get.hpp
|
||||
#
|
||||
|
||||
These are functions for extracting values from toml::value and performing type conversions if necessary.
|
||||
|
||||
toml::value can change the type it stores, and toml::get accommodates these types.
|
||||
Technically, all functions use toml::basic_value<TC>.
|
||||
However, for simplicity, we refer to it as toml::value in explanations unless a distinction is necessary.
|
||||
In the documentation, if the template parameter TC changes the type, assume that types like toml::value::integer_type will also change accordingly.
|
||||
|
||||
|
||||
|
||||
toml::get<T>
|
||||
#
|
||||
|
||||
|
||||
Overview
|
||||
#
|
||||
|
||||
Generally, toml::get behaves as follows:
|
||||
You specify T as in toml::get<int>(v)."><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/reference/get/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="get.hpp"><meta property="og:description" content="get.hpp # These are functions for extracting values from toml::value and performing type conversions if necessary.
|
||||
toml::value can change the type it stores, and toml::get accommodates these types. Technically, all functions use toml::basic_value<TC>. However, for simplicity, we refer to it as toml::value in explanations unless a distinction is necessary. In the documentation, if the template parameter TC changes the type, assume that types like toml::value::integer_type will also change accordingly. toml::get<T> # Overview # Generally, toml::get behaves as follows: You specify T as in toml::get<int>(v)."><meta property="og:locale" content="en"><meta property="og:type" content="article"><meta property="article:section" content="docs"><title>get.hpp | toml11</title><link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/reference/get/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/reference/get/ title=get.hpp><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" crossorigin=anonymous></script></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
|
||||
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
|
||||
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
|
||||
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/reference/get/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle>
|
||||
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle checked>
|
||||
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/ class=active>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
|
||||
</label><strong>get.hpp</strong>
|
||||
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#gethpp>get.hpp</a></li><li><a href=#tomlgett><code>toml::get<T></code></a><ul><li><a href=#overview>Overview</a><ul><li><a href=#types-that-do-not-require-conversion>Types that Do Not Require Conversion</a></li><li><a href=#types-that-require-conversion>Types that Require Conversion</a></li><li><a href=#when-conversion-fails>When Conversion Fails</a></li></ul></li><li><a href=#when-t-is-identical-to-tomlvalue>When <code>T</code> is identical to <code>toml::value</code></a></li><li><a href=#when-t-is-one-of-tomlvaluesome_type>When <code>T</code> is one of <code>toml::value::{some_type}</code></a></li><li><a href=#when-t-is-basic_valueothertc-with-a-different-typeconfig>When <code>T</code> is <code>basic_value<OtherTC></code> with a different <code>TypeConfig</code></a></li><li><a href=#when-t-is-an-integer-type>When <code>T</code> is an integer type</a></li><li><a href=#when-t-is-a-floating-point-type>When <code>T</code> is a floating-point type</a></li><li><a href=#when-t-is-stdstring_view>When <code>T</code> is <code>std::string_view</code></a></li><li><a href=#when-t-is-stdchronoduration>When <code>T</code> is <code>std::chrono::duration</code></a></li><li><a href=#when-t-is-stdchronosystem_clocktime_point>When <code>T</code> is <code>std::chrono::system_clock::time_point</code></a></li><li><a href=#when-t-is-array-like>When <code>T</code> is array-like</a></li><li><a href=#when-t-is-stdarray>When <code>T</code> is <code>std::array</code></a></li><li><a href=#when-t-is-stdforward_list>When <code>T</code> is <code>std::forward_list</code></a></li><li><a href=#when-t-is-stdpair>When <code>T</code> is <code>std::pair</code></a></li><li><a href=#when-t-is-stdtuple>When <code>T</code> is <code>std::tuple</code></a></li><li><a href=#when-t-is-map-like>When <code>T</code> is map-like</a></li><li><a href=#when-t-is-a-user-defined-type-with-a-specialization-of-tomlfromt>When <code>T</code> is a user-defined type with a specialization of <code>toml::from<T></code></a></li><li><a href=#when-t-is-a-user-defined-type-with-a-from_toml-member-function>When <code>T</code> is a user-defined type with a <code>from_toml</code> member function</a></li><li><a href=#when-t-is-a-user-defined-type-with-a-constructor-that-takes-tomlbasic_valuetc>When <code>T</code> is a user-defined type with a constructor that takes <code>toml::basic_value<TC></code></a></li></ul></li><li><a href=#tomlget_ort><code>toml::get_or<T></code></a><ul><li><a href=#when-t-is-basic_valuetc>When <code>T</code> is <code>basic_value<TC></code></a></li><li><a href=#when-t-is-basic_valuetcsome_type>When <code>T</code> is <code>basic_value<TC>::{some_type}</code></a></li><li><a href=#when-t-is-const-char>When <code>T</code> is <code>const char*</code></a></li><li><a href=#when-t-is-something-else>When <code>T</code> is something else</a></li></ul></li><li><a href=#related>Related</a></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=gethpp>get.hpp
|
||||
<a class=anchor href=#gethpp>#</a></h1><p>These are functions for extracting values from <code>toml::value</code> and performing type conversions if necessary.</p><blockquote class="book-hint info"><code>toml::value</code> can change the type it stores, and <code>toml::get</code> accommodates these types.
|
||||
Technically, all functions use <code>toml::basic_value<TC></code>.
|
||||
However, for simplicity, we refer to it as <code>toml::value</code> in explanations unless a distinction is necessary.
|
||||
In the documentation, if the template parameter <code>TC</code> changes the type, assume that types like <code>toml::value::integer_type</code> will also change accordingly.</blockquote><h1 id=tomlgett><code>toml::get<T></code>
|
||||
<a class=anchor href=#tomlgett>#</a></h1><h2 id=overview>Overview
|
||||
<a class=anchor href=#overview>#</a></h2><p>Generally, <code>toml::get</code> behaves as follows:
|
||||
You specify <code>T</code> as in <code>toml::get<int>(v)</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>T get(<span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v);
|
||||
</span></span></code></pre></div><p>However, depending on the type of <code>T</code>, <code>toml::get</code> can exhibit different behaviors.</p><p>The types of <code>T</code> can be categorized into:</p><ol><li>Types that do not require conversion</li><li>Types that require conversion</li></ol><p>Detailed conditions and the specific types supported are discussed later.</p><h3 id=types-that-do-not-require-conversion>Types that Do Not Require Conversion
|
||||
<a class=anchor href=#types-that-do-not-require-conversion>#</a></h3><p>No conversion is needed if the provided <code>toml::value</code> is already storing the desired type. For instance, since <code>toml::value::integer_type</code> is an alias for <code>std::int64_t</code>, <code>toml::get<std::int64_t>(v)</code> requires no conversion. In this case, <code>toml::get</code> retrieves the <code>integer</code> value from <code>toml::value</code> and returns a reference to it.</p><p>If the provided <code>toml::value</code> is a mutable reference (<code>&</code>), the returned value is also a mutable reference (<code>&</code>). If it is an immutable reference (<code>const&</code>), the returned value will also be an immutable reference (<code>const&</code>). Returning a mutable reference allows you to overwrite the value stored in <code>toml::value</code> through that reference.</p><h3 id=types-that-require-conversion>Types that Require Conversion
|
||||
<a class=anchor href=#types-that-require-conversion>#</a></h3><p>Types other than the ones mentioned above require conversion. For example, since <code>toml::value::integer_type</code> is an alias for <code>std::int64_t</code>, <code>toml::get<std::size_t>(toml::value&)</code> requires conversion. In this case, <code>toml::get</code> retrieves the <code>integer</code> value from <code>toml::value</code> and casts it to return the appropriate type.</p><p>toml11 supports not only simple casts but also complex type conversions like converting from <code>toml::array</code> to <code>std::tuple<int, double, std::string></code>, <code>std::array<double, 4></code>, or from <code>toml::table</code> to <code>std::map<std::string, int></code>. For specifics, refer to the subsequent sections.</p><h3 id=when-conversion-fails>When Conversion Fails
|
||||
<a class=anchor href=#when-conversion-fails>#</a></h3><p>Sometimes, the expected type conversion cannot be performed. For example, applying <code>toml::get<int>(v)</code> to a <code>toml::value</code> that holds a <code>table</code>.</p><p>In such cases, an attempt to convert to the type most similar to the desired type (in this case, <code>int</code> using <code>as_integer</code>) fails, and a <code>toml::type_error</code> is thrown.</p><p>When parsing from a file, an error message similar to the following is output:</p><pre tabindex=0><code>terminate called after throwing an instance of 'toml::type_error'
|
||||
what(): toml::value::as_integer(): bad_cast to integer
|
||||
--> input.toml
|
||||
|
|
||||
6 | [fruit]
|
||||
| ^^^^^^^-- the actual type is table
|
||||
</code></pre><h2 id=when-t-is-identical-to-tomlvalue>When <code>T</code> is identical to <code>toml::value</code>
|
||||
<a class=anchor href=#when-t-is-identical-to-tomlvalue>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>T<span style=color:#f92672>&</span> get(basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>T <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> get(<span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>T get(basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&&</span> v);
|
||||
</span></span></code></pre></div><p>Condition:</p><ul><li><code>std::is_same<T, basic_value<TC>></code> is satisfied.</li></ul><p>Since this involves retrieving <code>toml::value</code> from <code>toml::value</code>, no conversion is performed, and the value is returned as is. This exists solely to generalize the implementation of other functions.</p><p>This does not fail.</p><h2 id=when-t-is-one-of-tomlvaluesome_type>When <code>T</code> is one of <code>toml::value::{some_type}</code>
|
||||
<a class=anchor href=#when-t-is-one-of-tomlvaluesome_type>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>T<span style=color:#f92672>&</span> get(basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>T <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> get(<span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>T get(basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&&</span> v);
|
||||
</span></span></code></pre></div><p>Condition:</p><ul><li><code>T</code> must be the same as one of the types that <code>toml::value</code> can store (e.g., <code>toml::value::boolean_type</code>).</li></ul><p>If <code>toml::value</code> is storing a type that matches the specified type in <code>toml::get<T></code>, such as <code>toml::value::integer_type</code>, no type conversion is needed, and a reference can be returned.</p><p>If a different type is stored, a <code>toml::type_error</code> is thrown.</p><h2 id=when-t-is-basic_valueothertc-with-a-different-typeconfig>When <code>T</code> is <code>basic_value<OtherTC></code> with a different <code>TypeConfig</code>
|
||||
<a class=anchor href=#when-t-is-basic_valueothertc-with-a-different-typeconfig>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>T get(basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v);
|
||||
</span></span></code></pre></div><p>Condition:</p><ul><li><code>T</code> is not <code>toml::basic_value<TC></code>.</li><li><code>T</code> is <code>toml::basic_value<OtherTC></code>.</li></ul><p>When a <code>basic_value</code> that can store different types is specified, conversion is performed.</p><p>Since type conversion occurs, the returned value is a new value and not a reference.</p><p>This does not fail (except in cases like memory exhaustion).</p><h2 id=when-t-is-an-integer-type>When <code>T</code> is an integer type
|
||||
<a class=anchor href=#when-t-is-an-integer-type>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>T get(basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v);
|
||||
</span></span></code></pre></div><p>Condition:</p><ul><li><code>std::is_integral<T></code> is satisfied</li><li><code>T</code> is not <code>bool</code></li><li><code>T</code> is not <code>toml::value::integer_type</code></li></ul><p>The function assumes that <code>toml::value</code> holds an <code>integer_type</code>, retrieves its value, converts it to <code>T</code>, and returns it.</p><p>If a type other than <code>toml::value::integer_type</code> is stored, a <code>toml::type_error</code> is thrown.</p><h2 id=when-t-is-a-floating-point-type>When <code>T</code> is a floating-point type
|
||||
<a class=anchor href=#when-t-is-a-floating-point-type>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>T get(basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v);
|
||||
</span></span></code></pre></div><p>Condition:</p><ul><li><code>std::is_floating_point<T></code> is satisfied</li><li><code>T</code> is not <code>toml::value::floating_type</code></li></ul><p>The function assumes that <code>toml::value</code> holds a <code>floating_type</code>, retrieves its value, converts it to <code>T</code>, and returns it.</p><p>If a type other than <code>toml::value::floating_type</code> is stored, a <code>toml::type_error</code> is thrown.</p><h2 id=when-t-is-stdstring_view>When <code>T</code> is <code>std::string_view</code>
|
||||
<a class=anchor href=#when-t-is-stdstring_view>#</a></h2><p>This is only available in C++17 and later.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>T get(basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v);
|
||||
</span></span></code></pre></div><p>Condition:</p><ul><li><code>std::is_same<std::string_view, T></code> is satisfied</li></ul><p>The function assumes that <code>toml::value</code> holds a <code>string_type</code>, retrieves its value, constructs a <code>std::string_view</code> from it, and returns it.</p><p>If a type other than <code>toml::value::string_type</code> is stored, a <code>toml::type_error</code> is thrown.</p><h2 id=when-t-is-stdchronoduration>When <code>T</code> is <code>std::chrono::duration</code>
|
||||
<a class=anchor href=#when-t-is-stdchronoduration>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>T get(basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v);
|
||||
</span></span></code></pre></div><p>Condition:</p><ul><li><code>T</code> is <code>std::chrono::duration<Rep, Period></code></li></ul><p>The function assumes that <code>toml::value</code> holds a <code>local_time</code>, retrieves its value, converts it to <code>std::chrono::duration</code>, and returns it.</p><p>If a type other than <code>toml::value::local_time</code> is stored, a <code>toml::type_error</code> is thrown.</p><h2 id=when-t-is-stdchronosystem_clocktime_point>When <code>T</code> is <code>std::chrono::system_clock::time_point</code>
|
||||
<a class=anchor href=#when-t-is-stdchronosystem_clocktime_point>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>T get(basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v);
|
||||
</span></span></code></pre></div><p>Condition:</p><ul><li><code>std::is_same<T, std::chrono::system_clock::time_point></code> is satisfied</li></ul><p>If the <code>toml::value</code> holds a <code>local_date</code>, <code>local_datetime</code>, or <code>offset_datetime</code>, this function retrieves the value and converts it to <code>std::chrono::system_clock::time_point</code>, returning the result.</p><p>If the value is of a type other than <code>local_date</code>, <code>local_datetime</code>, or <code>offset_datetime</code>, a <code>toml::type_error</code> is thrown.</p><h2 id=when-t-is-array-like>When <code>T</code> is array-like
|
||||
<a class=anchor href=#when-t-is-array-like>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>T get(basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v);
|
||||
</span></span></code></pre></div><p>Conditions:</p><ul><li><code>T</code> has an <code>iterator</code></li><li><code>T</code> has a <code>value_type</code></li><li><code>T</code> supports <code>push_back(x)</code></li><li><code>T</code> is not <code>toml::value::array_type</code></li><li><code>T</code> is not <code>std::string</code></li><li><code>T</code> is not <code>std::string_view</code></li><li><code>T</code> is not map-like</li><li><code>T</code> does not have <code>from_toml()</code> member function</li><li><code>toml::from<T></code> is not defined</li><li>A constructor from <code>toml::basic_value<TC></code> is not defined</li></ul><p>This includes types like <code>std::vector<int></code> and <code>std::deque<std::string></code>.</p><p>If the <code>toml::value</code> holds an <code>array</code>, this function retrieves the value and converts it to the specified container type, returning the result.</p><p>If the value is of a type other than <code>toml::value::array_type</code>, a <code>toml::type_error</code> is thrown.</p><h2 id=when-t-is-stdarray>When <code>T</code> is <code>std::array</code>
|
||||
<a class=anchor href=#when-t-is-stdarray>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>T get(basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v);
|
||||
</span></span></code></pre></div><p>Condition:</p><ul><li><code>T</code> is <code>std::array<U, N></code></li></ul><p>If the <code>toml::value</code> holds an <code>array</code>, this function retrieves the value and converts it to the specified container type, returning the result.</p><p>If the value is of a type other than <code>toml::value::array_type</code>, a <code>toml::type_error</code> is thrown.</p><p>If the <code>array</code> held by <code>toml::value</code> does not contain enough elements, a <code>std::out_of_range</code> is thrown.</p><h2 id=when-t-is-stdforward_list>When <code>T</code> is <code>std::forward_list</code>
|
||||
<a class=anchor href=#when-t-is-stdforward_list>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>T get(basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v);
|
||||
</span></span></code></pre></div><p>Condition:</p><ul><li><code>T</code> is <code>std::forward_list<U></code></li></ul><p>If the <code>toml::value</code> holds an <code>array</code>, this function retrieves the value and converts it to a <code>std::forward_list</code>, returning the result.</p><p>If the value is of a type other than <code>toml::value::array_type</code>, a <code>toml::type_error</code> is thrown.</p><h2 id=when-t-is-stdpair>When <code>T</code> is <code>std::pair</code>
|
||||
<a class=anchor href=#when-t-is-stdpair>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>T get(basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v);
|
||||
</span></span></code></pre></div><p>Condition:</p><ul><li><code>T</code> is <code>std::pair<T1, T2></code></li></ul><p>If the <code>toml::value</code> holds an <code>array</code>, this function retrieves the value and converts it to <code>std::pair<T1, T2></code>, returning the result.</p><p>The <code>first</code> and <code>second</code> elements are recursively converted.</p><p>If the value is of a type other than <code>basic_value::array_type</code>, a <code>toml::type_error</code> is thrown.</p><p>If the <code>array</code> held by <code>toml::value</code> does not contain exactly 2 elements, a <code>std::out_of_range</code> is thrown.</p><h2 id=when-t-is-stdtuple>When <code>T</code> is <code>std::tuple</code>
|
||||
<a class=anchor href=#when-t-is-stdtuple>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>T get(basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v);
|
||||
</span></span></code></pre></div><p>Condition:</p><ul><li><code>T</code> is <code>std::tuple<T1, T2, ... TN></code></li></ul><p>If the <code>toml::value</code> holds an <code>array</code>, this function retrieves the value and converts it to <code>std::tuple<T1, T2, ...TN></code>, returning the result.</p><p>Each element is recursively converted.</p><p>If the value is of a type other than <code>basic_value::array_type</code>, a <code>toml::type_error</code> is thrown.</p><p>If the <code>array</code> held by <code>toml::value</code> does not contain exactly <code>std::tuple_size<T>::value</code> elements, a <code>std::out_of_range</code> is thrown.</p><h2 id=when-t-is-map-like>When <code>T</code> is map-like
|
||||
<a class=anchor href=#when-t-is-map-like>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>T get(basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v);
|
||||
</span></span></code></pre></div><p>Conditions:</p><ul><li><code>T</code> has an <code>iterator</code></li><li><code>T</code> has a <code>key_type</code></li><li><code>T</code> has a <code>value_type</code></li><li><code>T</code> has a <code>mapped_type</code></li><li><code>T</code> is not <code>toml::value::table_type</code></li><li><code>T</code> does not have a <code>from_toml()</code> member function</li><li><code>toml::from<T></code> is not defined</li><li>A constructor from <code>toml::basic_value<TC></code> is not defined</li></ul><p>This includes types like <code>std::map<std::string, int></code> and <code>std::unordered_map<std::string, float></code>.</p><p>If the <code>toml::value</code> holds a <code>table</code>, this function retrieves the value and converts it to <code>T</code>, returning the result.</p><p>Elements are recursively converted.</p><p>If the value is of a type other than <code>basic_value::table_type</code>, a <code>toml::type_error</code> is thrown.</p><h2 id=when-t-is-a-user-defined-type-with-a-specialization-of-tomlfromt>When <code>T</code> is a user-defined type with a specialization of <code>toml::from<T></code>
|
||||
<a class=anchor href=#when-t-is-a-user-defined-type-with-a-specialization-of-tomlfromt>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>T get(basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v);
|
||||
</span></span></code></pre></div><p>Condition:</p><ul><li>A specialization of <code>toml::from<T></code> is defined</li></ul><p>If a specialization of <code>toml::from</code> for <code>T</code> is defined, it is used for type conversion.</p><p>Ensure this does not conflict with individually supported types (<code>std::array</code>, <code>std::pair</code>, <code>std::tuple</code> etc).</p><h2 id=when-t-is-a-user-defined-type-with-a-from_toml-member-function>When <code>T</code> is a user-defined type with a <code>from_toml</code> member function
|
||||
<a class=anchor href=#when-t-is-a-user-defined-type-with-a-from_toml-member-function>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>T get(basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v);
|
||||
</span></span></code></pre></div><p>Conditions:</p><ul><li><code>toml::from<T></code> is not defined</li><li><code>T</code> has <code>from_toml()</code> member function</li></ul><p>If <code>T</code> has a <code>from_toml(toml::basic_value<TC>)</code> member function, it is used for type conversion.</p><p>If <code>toml::from<T></code> is defined, it takes precedence.</p><h2 id=when-t-is-a-user-defined-type-with-a-constructor-that-takes-tomlbasic_valuetc>When <code>T</code> is a user-defined type with a constructor that takes <code>toml::basic_value<TC></code>
|
||||
<a class=anchor href=#when-t-is-a-user-defined-type-with-a-constructor-that-takes-tomlbasic_valuetc>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>T get(basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v);
|
||||
</span></span></code></pre></div><p>Conditions:</p><ul><li><code>toml::from<T></code> is not defined</li><li><code>T</code> does not have <code>from_toml()</code> member function</li><li><code>T</code> has a constructor that takes <code>toml::basic_value<TC></code></li></ul><p>If <code>T</code> has a constructor that takes <code>toml::basic_value<TC></code>, it is used for type conversion.</p><p>If <code>toml::from<T></code> or <code>T::from_toml</code> is defined, they take precedence.</p><h1 id=tomlget_ort><code>toml::get_or<T></code>
|
||||
<a class=anchor href=#tomlget_ort>#</a></h1><p><code>get_or</code> takes a default value for use when the conversion fails, avoiding exceptions.</p><p>The default value must be of the same type as the target type <code>T</code>.
|
||||
Therefore, unlike <code>toml::get<T></code>, <code>T</code> can be inferred in <code>get_or</code>.</p><h2 id=when-t-is-basic_valuetc>When <code>T</code> is <code>basic_value<TC></code>
|
||||
<a class=anchor href=#when-t-is-basic_valuetc>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>></span> <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> get_or(<span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v, <span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> opt)
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>></span> <span style=color:#f92672>&</span> get_or(basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v, basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> opt)
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>></span> get_or(basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&&</span> v, basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&&</span> opt)
|
||||
</span></span></code></pre></div><p>Since the conversion target is the same <code>toml::value</code>, this never fails.</p><p>It exists solely to generalize the implementation of other functions.</p><h2 id=when-t-is-basic_valuetcsome_type>When <code>T</code> is <code>basic_value<TC>::{some_type}</code>
|
||||
<a class=anchor href=#when-t-is-basic_valuetcsome_type>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>T <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> get_or(<span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v, <span style=color:#66d9ef>const</span> T<span style=color:#f92672>&</span> opt) <span style=color:#66d9ef>noexcept</span>
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>T <span style=color:#f92672>&</span> get_or(basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v, T<span style=color:#f92672>&</span> opt) <span style=color:#66d9ef>noexcept</span>
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>T get_or(basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&&</span> v, T<span style=color:#f92672>&&</span> opt) <span style=color:#66d9ef>noexcept</span>
|
||||
</span></span></code></pre></div><p>Performs the same conversion as <code>toml::get<T></code>. If it fails, the second argument is returned.</p><h2 id=when-t-is-const-char>When <code>T</code> is <code>const char*</code>
|
||||
<a class=anchor href=#when-t-is-const-char>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>typename</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>::</span>string_type
|
||||
</span></span><span style=display:flex><span>get_or(<span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v,
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>typename</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>::</span>string_type<span style=color:#f92672>::</span>value_type<span style=color:#f92672>*</span> opt);
|
||||
</span></span></code></pre></div><p>When <code>const char*</code> is passed, the conversion target is interpreted as <code>std::string</code>.</p><h2 id=when-t-is-something-else>When <code>T</code> is something else
|
||||
<a class=anchor href=#when-t-is-something-else>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>typename</span> std<span style=color:#f92672>::</span>remove_cv<span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> std<span style=color:#f92672>::</span>remove_reference<span style=color:#f92672><</span>T<span style=color:#f92672>>::</span>type<span style=color:#f92672>>::</span>type
|
||||
</span></span><span style=display:flex><span>get_or(<span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v, T<span style=color:#f92672>&&</span> opt);
|
||||
</span></span></code></pre></div><p>Performs the same conversion as <code>toml::get<T></code>. If it fails, the second argument is returned.</p><h1 id=related>Related
|
||||
<a class=anchor href=#related>#</a></h1><ul><li><a href=https://toruniina.github.io/toml11/docs/reference/find/>find.hpp</a></li><li><a href=https://toruniina.github.io/toml11/docs/reference/from/>from.hpp</a></li><li><a href=https://toruniina.github.io/toml11/docs/reference/value/>value.hpp</a></li></ul></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#gethpp>get.hpp</a></li><li><a href=#tomlgett><code>toml::get<T></code></a><ul><li><a href=#overview>Overview</a><ul><li><a href=#types-that-do-not-require-conversion>Types that Do Not Require Conversion</a></li><li><a href=#types-that-require-conversion>Types that Require Conversion</a></li><li><a href=#when-conversion-fails>When Conversion Fails</a></li></ul></li><li><a href=#when-t-is-identical-to-tomlvalue>When <code>T</code> is identical to <code>toml::value</code></a></li><li><a href=#when-t-is-one-of-tomlvaluesome_type>When <code>T</code> is one of <code>toml::value::{some_type}</code></a></li><li><a href=#when-t-is-basic_valueothertc-with-a-different-typeconfig>When <code>T</code> is <code>basic_value<OtherTC></code> with a different <code>TypeConfig</code></a></li><li><a href=#when-t-is-an-integer-type>When <code>T</code> is an integer type</a></li><li><a href=#when-t-is-a-floating-point-type>When <code>T</code> is a floating-point type</a></li><li><a href=#when-t-is-stdstring_view>When <code>T</code> is <code>std::string_view</code></a></li><li><a href=#when-t-is-stdchronoduration>When <code>T</code> is <code>std::chrono::duration</code></a></li><li><a href=#when-t-is-stdchronosystem_clocktime_point>When <code>T</code> is <code>std::chrono::system_clock::time_point</code></a></li><li><a href=#when-t-is-array-like>When <code>T</code> is array-like</a></li><li><a href=#when-t-is-stdarray>When <code>T</code> is <code>std::array</code></a></li><li><a href=#when-t-is-stdforward_list>When <code>T</code> is <code>std::forward_list</code></a></li><li><a href=#when-t-is-stdpair>When <code>T</code> is <code>std::pair</code></a></li><li><a href=#when-t-is-stdtuple>When <code>T</code> is <code>std::tuple</code></a></li><li><a href=#when-t-is-map-like>When <code>T</code> is map-like</a></li><li><a href=#when-t-is-a-user-defined-type-with-a-specialization-of-tomlfromt>When <code>T</code> is a user-defined type with a specialization of <code>toml::from<T></code></a></li><li><a href=#when-t-is-a-user-defined-type-with-a-from_toml-member-function>When <code>T</code> is a user-defined type with a <code>from_toml</code> member function</a></li><li><a href=#when-t-is-a-user-defined-type-with-a-constructor-that-takes-tomlbasic_valuetc>When <code>T</code> is a user-defined type with a constructor that takes <code>toml::basic_value<TC></code></a></li></ul></li><li><a href=#tomlget_ort><code>toml::get_or<T></code></a><ul><li><a href=#when-t-is-basic_valuetc>When <code>T</code> is <code>basic_value<TC></code></a></li><li><a href=#when-t-is-basic_valuetcsome_type>When <code>T</code> is <code>basic_value<TC>::{some_type}</code></a></li><li><a href=#when-t-is-const-char>When <code>T</code> is <code>const char*</code></a></li><li><a href=#when-t-is-something-else>When <code>T</code> is something else</a></li></ul></li><li><a href=#related>Related</a></li></ul></nav></div></aside></main></body></html>
|
||||
64
docs/reference/index.html
Normal file
64
docs/reference/index.html
Normal file
@@ -0,0 +1,64 @@
|
||||
<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
|
||||
Reference
|
||||
#
|
||||
|
||||
Here, we explain the effects of the classes and functions provided by toml11.
|
||||
|
||||
Directory Structure
|
||||
#
|
||||
|
||||
toml.hpp and toml_fwd.hpp reside in ${TOML11_INCLUDE_DIR}.
|
||||
Other files are located in ${TOML11_INCLUDE_DIR}/toml11.
|
||||
If you want to #include each feature’s file individually, use #include <toml11/color.hpp>.
|
||||
If you want to include all at once, use #include <toml.hpp>.
|
||||
|
||||
color.hpp
|
||||
#
|
||||
|
||||
Defines functions related to colorizing error messages.
|
||||
|
||||
comments.hpp
|
||||
#
|
||||
|
||||
Defines types preserve_comment and discard_comment for preserving comments."><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/reference/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="reference"><meta property="og:description" content="Reference # Here, we explain the effects of the classes and functions provided by toml11.
|
||||
Directory Structure # toml.hpp and toml_fwd.hpp reside in ${TOML11_INCLUDE_DIR}. Other files are located in ${TOML11_INCLUDE_DIR}/toml11.
|
||||
If you want to #include each feature’s file individually, use #include <toml11/color.hpp>. If you want to include all at once, use #include <toml.hpp>.
|
||||
color.hpp # Defines functions related to colorizing error messages.
|
||||
comments.hpp # Defines types preserve_comment and discard_comment for preserving comments."><meta property="og:locale" content="en"><meta property="og:type" content="website"><title>reference | toml11</title><link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/reference/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/reference/ title=reference><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" crossorigin=anonymous></script><link rel=alternate type=application/rss+xml href=https://toruniina.github.io/toml11/docs/reference/index.xml title=toml11></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
|
||||
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
|
||||
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
|
||||
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/reference/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle>
|
||||
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle checked>
|
||||
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/ class=active>reference</a></label><ul><li><a href=/toml11/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
|
||||
</label><strong>reference</strong>
|
||||
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#reference>Reference</a><ul><li><a href=#directory-structure>Directory Structure</a></li><li><a href=#colorhpp>color.hpp</a></li><li><a href=#commentshpp>comments.hpp</a></li><li><a href=#conversionhpp>conversion.hpp</a></li><li><a href=#datetimehpp>datetime.hpp</a></li><li><a href=#error_>error_info.hpp</a></li><li><a href=#exceptionhpp>exception.hpp</a></li><li><a href=#findhpp>find.hpp</a></li><li><a href=#formathpp>format.hpp</a></li><li><a href=#fromhpp>from.hpp</a></li><li><a href=#gethpp>get.hpp</a></li><li><a href=#intohpp>into.hpp</a></li><li><a href=#literalhpp>literal.hpp</a></li><li><a href=#ordered_>ordered_map.hpp</a></li><li><a href=#parserhpp>parser.hpp</a></li><li><a href=#resulthpp>result.hpp</a></li><li><a href=#serializerhpp>serializer.hpp</a></li><li><a href=#source_>source_location.hpp</a></li><li><a href=#spechpp>spec.hpp</a></li><li><a href=#tomlhpp>toml.hpp</a></li><li><a href=#toml_>toml_fwd.hpp</a></li><li><a href=#typeshpp>types.hpp</a></li><li><a href=#valuehpp>value.hpp</a></li><li><a href=#value_>value_t.hpp</a></li><li><a href=#versionhpp>version.hpp</a></li><li><a href=#visithpp>visit.hpp</a></li><li><a href=#notes>Notes</a></li></ul></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=reference>Reference
|
||||
<a class=anchor href=#reference>#</a></h1><p>Here, we explain the effects of the classes and functions provided by toml11.</p><h2 id=directory-structure>Directory Structure
|
||||
<a class=anchor href=#directory-structure>#</a></h2><p><code>toml.hpp</code> and <code>toml_fwd.hpp</code> reside in <code>${TOML11_INCLUDE_DIR}</code>.
|
||||
Other files are located in <code>${TOML11_INCLUDE_DIR}/toml11</code>.</p><p>If you want to <code>#include</code> each feature’s file individually, use <code>#include <toml11/color.hpp></code>.
|
||||
If you want to include all at once, use <code>#include <toml.hpp></code>.</p><h2 id=colorhpp><a href=color>color.hpp</a>
|
||||
<a class=anchor href=#colorhpp>#</a></h2><p>Defines functions related to colorizing error messages.</p><h2 id=commentshpp><a href=comments>comments.hpp</a>
|
||||
<a class=anchor href=#commentshpp>#</a></h2><p>Defines types <code>preserve_comment</code> and <code>discard_comment</code> for preserving comments.</p><h2 id=conversionhpp><a href=conversion>conversion.hpp</a>
|
||||
<a class=anchor href=#conversionhpp>#</a></h2><p>Defines macros to automatically convert <code>toml::value</code> and user-defined classes.</p><h2 id=datetimehpp><a href=datetime>datetime.hpp</a>
|
||||
<a class=anchor href=#datetimehpp>#</a></h2><p>Defines classes for datetime information.</p><h2 id=error_><a href=error_info>error_info.hpp</a>
|
||||
<a class=anchor href=#error_>#</a></h2><p>Defines a class for error information.</p><h2 id=exceptionhpp><a href=exception>exception.hpp</a>
|
||||
<a class=anchor href=#exceptionhpp>#</a></h2><p>Defines the base class for exceptions used in toml11, <code>toml::exception</code>.</p><h2 id=findhpp><a href=find>find.hpp</a>
|
||||
<a class=anchor href=#findhpp>#</a></h2><p>Defines the <code>toml::find</code> function to search for and convert values.</p><h2 id=formathpp><a href=format>format.hpp</a>
|
||||
<a class=anchor href=#formathpp>#</a></h2><p>Defines classes for formatting information of values.</p><h2 id=fromhpp><a href=from>from.hpp</a>
|
||||
<a class=anchor href=#fromhpp>#</a></h2><p>Forward declaration of the <code>from<T></code> type for converting user-defined types.</p><h2 id=gethpp><a href=get>get.hpp</a>
|
||||
<a class=anchor href=#gethpp>#</a></h2><p>Defines the <code>toml::get<T></code> function to retrieve and convert values from <code>toml::value</code>.</p><h2 id=intohpp><a href=into>into.hpp</a>
|
||||
<a class=anchor href=#intohpp>#</a></h2><p>Forward declaration of the <code>into<T></code> type for converting user-defined types.</p><h2 id=literalhpp><a href=literal>literal.hpp</a>
|
||||
<a class=anchor href=#literalhpp>#</a></h2><p>Defines the <code>operator"" _toml</code> literal.</p><h2 id=ordered_><a href=ordered_map>ordered_map.hpp</a>
|
||||
<a class=anchor href=#ordered_>#</a></h2><p>Defines <code>toml::ordered_map</code>.</p><h2 id=parserhpp><a href=parser>parser.hpp</a>
|
||||
<a class=anchor href=#parserhpp>#</a></h2><p>Defines functions to parse files or strings.</p><h2 id=resulthpp><a href=result>result.hpp</a>
|
||||
<a class=anchor href=#resulthpp>#</a></h2><p>Defines the <code>result<T, E></code> type for representing success or failure values used as return types in other functions.</p><h2 id=serializerhpp><a href=serializer>serializer.hpp</a>
|
||||
<a class=anchor href=#serializerhpp>#</a></h2><p>Defines the <code>toml::format</code> function and <code>toml::serializer</code> used for serialization.</p><h2 id=source_><a href=source_location>source_location.hpp</a>
|
||||
<a class=anchor href=#source_>#</a></h2><p>Defines the <code>source_location</code> type used for error information, pointing to a location within a file.</p><h2 id=spechpp><a href=spec>spec.hpp</a>
|
||||
<a class=anchor href=#spechpp>#</a></h2><p>Defines the <code>toml::semantic_version</code> and <code>toml::spec</code> types to control TOML language version information and feature flags.</p><h2 id=tomlhpp><a href=toml>toml.hpp</a>
|
||||
<a class=anchor href=#tomlhpp>#</a></h2><p><code>toml.hpp</code> includes all other headers, making all toml11 features available.</p><h2 id=toml_><a href=toml_fwd>toml_fwd.hpp</a>
|
||||
<a class=anchor href=#toml_>#</a></h2><p><code>toml_fwd.hpp</code> contains forward declarations of structs defined in toml11 and macro definitions.</p><h2 id=typeshpp><a href=types>types.hpp</a>
|
||||
<a class=anchor href=#typeshpp>#</a></h2><p>Defines the <code>toml::type_config</code> type for controlling the types held by <code>toml::value</code>.</p><h2 id=valuehpp><a href=value>value.hpp</a>
|
||||
<a class=anchor href=#valuehpp>#</a></h2><p>Defines the <code>toml::value</code> type.</p><h2 id=value_><a href=value_t>value_t.hpp</a>
|
||||
<a class=anchor href=#value_>#</a></h2><p>Defines the <code>toml::value_t</code> enumeration.</p><h2 id=versionhpp><a href=version>version.hpp</a>
|
||||
<a class=anchor href=#versionhpp>#</a></h2><p>Defines the version information for toml11.</p><h2 id=visithpp><a href=visit>visit.hpp</a>
|
||||
<a class=anchor href=#visithpp>#</a></h2><p>Defines the <code>toml::visit</code> function to apply functions to the values held by <code>toml::value</code>.</p><h2 id=notes>Notes
|
||||
<a class=anchor href=#notes>#</a></h2><p>Functions not explicitly mentioned here (mostly those defined under <code>namespace toml::detail</code> or <code>namespace toml::cxx</code>) are available by inspecting the source code but are not guaranteed to maintain their interface across future versions (including patch version updates).</p></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#reference>Reference</a><ul><li><a href=#directory-structure>Directory Structure</a></li><li><a href=#colorhpp>color.hpp</a></li><li><a href=#commentshpp>comments.hpp</a></li><li><a href=#conversionhpp>conversion.hpp</a></li><li><a href=#datetimehpp>datetime.hpp</a></li><li><a href=#error_>error_info.hpp</a></li><li><a href=#exceptionhpp>exception.hpp</a></li><li><a href=#findhpp>find.hpp</a></li><li><a href=#formathpp>format.hpp</a></li><li><a href=#fromhpp>from.hpp</a></li><li><a href=#gethpp>get.hpp</a></li><li><a href=#intohpp>into.hpp</a></li><li><a href=#literalhpp>literal.hpp</a></li><li><a href=#ordered_>ordered_map.hpp</a></li><li><a href=#parserhpp>parser.hpp</a></li><li><a href=#resulthpp>result.hpp</a></li><li><a href=#serializerhpp>serializer.hpp</a></li><li><a href=#source_>source_location.hpp</a></li><li><a href=#spechpp>spec.hpp</a></li><li><a href=#tomlhpp>toml.hpp</a></li><li><a href=#toml_>toml_fwd.hpp</a></li><li><a href=#typeshpp>types.hpp</a></li><li><a href=#valuehpp>value.hpp</a></li><li><a href=#value_>value_t.hpp</a></li><li><a href=#versionhpp>version.hpp</a></li><li><a href=#visithpp>visit.hpp</a></li><li><a href=#notes>Notes</a></li></ul></li></ul></nav></div></aside></main></body></html>
|
||||
768
docs/reference/index.xml
Normal file
768
docs/reference/index.xml
Normal file
@@ -0,0 +1,768 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>reference on toml11</title><link>https://toruniina.github.io/toml11/docs/reference/</link><description>Recent content in reference on toml11</description><generator>Hugo</generator><language>en</language><atom:link href="https://toruniina.github.io/toml11/docs/reference/index.xml" rel="self" type="application/rss+xml"/><item><title>color.hpp</title><link>https://toruniina.github.io/toml11/docs/reference/color/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/docs/reference/color/</guid><description><h1 id="colorhpp">
|
||||
color.hpp
|
||||
<a class="anchor" href="#colorhpp">#</a>
|
||||
</h1>
|
||||
<p>In <code>color.hpp</code>, functions related to colorizing error messages are defined.</p>
|
||||
<p>Colors are specified using ANSI escape code.
|
||||
In terminals or other output destinations that do not support ANSI escape code, the output may become difficult to read.</p>
|
||||
<h2 id="macros">
|
||||
Macros
|
||||
<a class="anchor" href="#macros">#</a>
|
||||
</h2>
|
||||
<h3 id="toml11_colorize_error_message">
|
||||
<code>TOML11_COLORIZE_ERROR_MESSAGE</code>
|
||||
<a class="anchor" href="#toml11_colorize_error_message">#</a>
|
||||
</h3>
|
||||
<p>If this macro is defined during compilation (<code>-DTOML11_COLORIZE_ERROR_MESASGE</code>), error messages are colored by default.</p>
|
||||
<p>If not defined, colors are not applied by default. You need to specify them using <code>toml::color::enable()</code>.</p></description></item><item><title>comments.hpp</title><link>https://toruniina.github.io/toml11/docs/reference/comments/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/docs/reference/comments/</guid><description><h1 id="commentshpp">
|
||||
comments.hpp
|
||||
<a class="anchor" href="#commentshpp">#</a>
|
||||
</h1>
|
||||
<p>In <code>comments.hpp</code>, comment containers are provided.</p>
|
||||
<h1 id="tomlpreserve_comments">
|
||||
<code>toml::preserve_comments</code>
|
||||
<a class="anchor" href="#tomlpreserve_comments">#</a>
|
||||
</h1>
|
||||
<p><code>preserve_comments</code> is a container that preserves comments.</p>
|
||||
<p>It has all the member functions of <code>std::vector&lt;std::string&gt;</code>.</p>
|
||||
<p>Comments are preserved as <code>std::string</code>.
|
||||
If the comment does not start with <code>#</code>, it will be prefixed with <code>#</code> during output.
|
||||
However, this prefixing is not done when adding comments to the container.</p>
|
||||
<p>Spaces are not automatically added, so if you want a space immediately after <code>#</code>,
|
||||
either start the comment with a space or pass the comment with <code>#</code>.</p></description></item><item><title>conversion.hpp</title><link>https://toruniina.github.io/toml11/docs/reference/conversion/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/docs/reference/conversion/</guid><description><h1 id="conversionhpp">
|
||||
conversion.hpp
|
||||
<a class="anchor" href="#conversionhpp">#</a>
|
||||
</h1>
|
||||
<p>Provides macros to automatically define conversion functions for supporting user-defined types with <code>toml::get</code> and <code>toml::find</code>.</p>
|
||||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span>TOML11_DEFINE_CONVERSION_NON_INTRUSIVE(NAME, ...)
|
||||
</span></span></code></pre></div><h2 id="example">
|
||||
Example
|
||||
<a class="anchor" href="#example">#</a>
|
||||
</h2>
|
||||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">namespace</span> foo
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">struct</span> <span style="color:#a6e22e">Foo</span>
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>string s;
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">double</span> d;
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">int</span> i;
|
||||
</span></span><span style="display:flex;"><span>};
|
||||
</span></span><span style="display:flex;"><span>} <span style="color:#75715e">// foo
|
||||
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
|
||||
</span></span><span style="display:flex;"><span>TOML11_DEFINE_CONVERSION_NON_INTRUSIVE(foo<span style="color:#f92672">::</span>Foo, s, d, i)
|
||||
</span></span></code></pre></div><h1 id="related">
|
||||
Related
|
||||
<a class="anchor" href="#related">#</a>
|
||||
</h1>
|
||||
<ul>
|
||||
<li><a href="https://toruniina.github.io/toml11/docs/reference/from/">from.hpp</a></li>
|
||||
<li><a href="https://toruniina.github.io/toml11/docs/reference/into/">into.hpp</a></li>
|
||||
</ul></description></item><item><title>datetime.hpp</title><link>https://toruniina.github.io/toml11/docs/reference/datetime/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/docs/reference/datetime/</guid><description><h1 id="datetimehpp">
|
||||
datetime.hpp
|
||||
<a class="anchor" href="#datetimehpp">#</a>
|
||||
</h1>
|
||||
<p>Defines a class that stores date and time information used in TOML&rsquo;s <code>datetime</code>.</p>
|
||||
<h1 id="enum-class-month_t">
|
||||
<code>enum class month_t</code>
|
||||
<a class="anchor" href="#enum-class-month_t">#</a>
|
||||
</h1>
|
||||
<p>Enum class to specify months.</p>
|
||||
<p>Due to its relationship with <code>std::tm</code>, <code>local_date</code> treats January as <code>0</code>.
|
||||
To avoid confusion, <code>month_t</code> allows specification of months by their names.</p>
|
||||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">namespace</span> toml
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">enum</span> <span style="color:#66d9ef">class</span> <span style="color:#a6e22e">month_t</span> <span style="color:#f92672">:</span> std<span style="color:#f92672">::</span><span style="color:#66d9ef">uint8_t</span>
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span> Jan <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>,
|
||||
</span></span><span style="display:flex;"><span> Feb <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>,
|
||||
</span></span><span style="display:flex;"><span> Mar <span style="color:#f92672">=</span> <span style="color:#ae81ff">2</span>,
|
||||
</span></span><span style="display:flex;"><span> Apr <span style="color:#f92672">=</span> <span style="color:#ae81ff">3</span>,
|
||||
</span></span><span style="display:flex;"><span> May <span style="color:#f92672">=</span> <span style="color:#ae81ff">4</span>,
|
||||
</span></span><span style="display:flex;"><span> Jun <span style="color:#f92672">=</span> <span style="color:#ae81ff">5</span>,
|
||||
</span></span><span style="display:flex;"><span> Jul <span style="color:#f92672">=</span> <span style="color:#ae81ff">6</span>,
|
||||
</span></span><span style="display:flex;"><span> Aug <span style="color:#f92672">=</span> <span style="color:#ae81ff">7</span>,
|
||||
</span></span><span style="display:flex;"><span> Sep <span style="color:#f92672">=</span> <span style="color:#ae81ff">8</span>,
|
||||
</span></span><span style="display:flex;"><span> Oct <span style="color:#f92672">=</span> <span style="color:#ae81ff">9</span>,
|
||||
</span></span><span style="display:flex;"><span> Nov <span style="color:#f92672">=</span> <span style="color:#ae81ff">10</span>,
|
||||
</span></span><span style="display:flex;"><span> Dec <span style="color:#f92672">=</span> <span style="color:#ae81ff">11</span>
|
||||
</span></span><span style="display:flex;"><span>};
|
||||
</span></span><span style="display:flex;"><span>}
|
||||
</span></span></code></pre></div><h1 id="local_date">
|
||||
<code>local_date</code>
|
||||
<a class="anchor" href="#local_date">#</a>
|
||||
</h1>
|
||||
<p><code>local_date</code> holds a date.</p></description></item><item><title>error_info.hpp</title><link>https://toruniina.github.io/toml11/docs/reference/error_info/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/docs/reference/error_info/</guid><description><h1 id="error_infohpp">
|
||||
error_info.hpp
|
||||
<a class="anchor" href="#error_infohpp">#</a>
|
||||
</h1>
|
||||
<p>In <code>error_info.hpp</code>, definitions for <code>error_info</code> and functions to format it are provided.</p>
|
||||
<h1 id="tomlerror_info">
|
||||
<code>toml::error_info</code>
|
||||
<a class="anchor" href="#tomlerror_info">#</a>
|
||||
</h1>
|
||||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">namespace</span> toml
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">struct</span> <span style="color:#a6e22e">error_info</span>
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span> error_info(std<span style="color:#f92672">::</span>string t, source_location l, std<span style="color:#f92672">::</span>string m, std<span style="color:#f92672">::</span>string s <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;&#34;</span>);
|
||||
</span></span><span style="display:flex;"><span> error_info(std<span style="color:#f92672">::</span>string t, std<span style="color:#f92672">::</span>vector<span style="color:#f92672">&lt;</span>std<span style="color:#f92672">::</span>pair<span style="color:#f92672">&lt;</span>source_location, std<span style="color:#f92672">::</span>string<span style="color:#f92672">&gt;&gt;</span> l, std<span style="color:#f92672">::</span>string s <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;&#34;</span>);
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>string <span style="color:#66d9ef">const</span><span style="color:#f92672">&amp;</span> title() <span style="color:#66d9ef">const</span> <span style="color:#66d9ef">noexcept</span>;
|
||||
</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>string <span style="color:#f92672">&amp;</span> title() <span style="color:#66d9ef">noexcept</span>;
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>vector<span style="color:#f92672">&lt;</span>std<span style="color:#f92672">::</span>pair<span style="color:#f92672">&lt;</span>source_location, std<span style="color:#f92672">::</span>string<span style="color:#f92672">&gt;&gt;</span> <span style="color:#66d9ef">const</span><span style="color:#f92672">&amp;</span> locations() <span style="color:#66d9ef">const</span> <span style="color:#66d9ef">noexcept</span>;
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">void</span> <span style="color:#a6e22e">add_locations</span>(source_location loc, std<span style="color:#f92672">::</span>string msg) <span style="color:#66d9ef">noexcept</span>;
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>string <span style="color:#66d9ef">const</span><span style="color:#f92672">&amp;</span> suffix() <span style="color:#66d9ef">const</span> <span style="color:#66d9ef">noexcept</span>;
|
||||
</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>string <span style="color:#f92672">&amp;</span> suffix() <span style="color:#66d9ef">noexcept</span>;
|
||||
</span></span><span style="display:flex;"><span>};
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">template</span><span style="color:#f92672">&lt;</span><span style="color:#66d9ef">typename</span> ... Ts<span style="color:#f92672">&gt;</span>
|
||||
</span></span><span style="display:flex;"><span>error_info make_error_info(
|
||||
</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>string title, source_location loc, std<span style="color:#f92672">::</span>string msg, Ts<span style="color:#f92672">&amp;&amp;</span> ... tail);
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span>std<span style="color:#f92672">::</span>string format_error(<span style="color:#66d9ef">const</span> std<span style="color:#f92672">::</span>string<span style="color:#f92672">&amp;</span> errkind, <span style="color:#66d9ef">const</span> error_info<span style="color:#f92672">&amp;</span> err);
|
||||
</span></span><span style="display:flex;"><span>std<span style="color:#f92672">::</span>string format_error(<span style="color:#66d9ef">const</span> error_info<span style="color:#f92672">&amp;</span> err);
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">template</span><span style="color:#f92672">&lt;</span><span style="color:#66d9ef">typename</span> ... Ts<span style="color:#f92672">&gt;</span>
|
||||
</span></span><span style="display:flex;"><span>std<span style="color:#f92672">::</span>string format_error(std<span style="color:#f92672">::</span>string title,
|
||||
</span></span><span style="display:flex;"><span> source_location loc, std<span style="color:#f92672">::</span>string msg, Ts<span style="color:#f92672">&amp;&amp;</span> ... tail);
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span>std<span style="color:#f92672">::</span>ostream<span style="color:#f92672">&amp;</span> <span style="color:#66d9ef">operator</span><span style="color:#f92672">&lt;&lt;</span>(std<span style="color:#f92672">::</span>ostream<span style="color:#f92672">&amp;</span> os, <span style="color:#66d9ef">const</span> error_info<span style="color:#f92672">&amp;</span> e);
|
||||
</span></span><span style="display:flex;"><span>}
|
||||
</span></span></code></pre></div><h2 id="member-functions">
|
||||
Member Functions
|
||||
<a class="anchor" href="#member-functions">#</a>
|
||||
</h2>
|
||||
<h3 id="constructor-title-loc-msg-suffix">
|
||||
Constructor (<code>title, loc, msg, suffix</code>)
|
||||
<a class="anchor" href="#constructor-title-loc-msg-suffix">#</a>
|
||||
</h3>
|
||||
<p>Constructs <code>error_info</code> with specified <code>title</code>, location information <code>loc</code>, message <code>msg</code>, and optional <code>suffix</code>.</p></description></item><item><title>exception.hpp</title><link>https://toruniina.github.io/toml11/docs/reference/exception/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/docs/reference/exception/</guid><description><h1 id="exceptionhpp">
|
||||
exception.hpp
|
||||
<a class="anchor" href="#exceptionhpp">#</a>
|
||||
</h1>
|
||||
<h1 id="tomlexception">
|
||||
<code>toml::exception</code>
|
||||
<a class="anchor" href="#tomlexception">#</a>
|
||||
</h1>
|
||||
<p>Base class for exception types defined in toml11.</p>
|
||||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">namespace</span> toml
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">struct</span> <span style="color:#a6e22e">exception</span> <span style="color:#f92672">:</span> <span style="color:#66d9ef">public</span> std<span style="color:#f92672">::</span>exception
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">public</span><span style="color:#f92672">:</span>
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">virtual</span> <span style="color:#f92672">~</span>exception() <span style="color:#66d9ef">noexcept</span> <span style="color:#66d9ef">override</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">default</span>;
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">virtual</span> <span style="color:#66d9ef">const</span> <span style="color:#66d9ef">char</span><span style="color:#f92672">*</span> <span style="color:#a6e22e">what</span>() <span style="color:#66d9ef">const</span> <span style="color:#66d9ef">noexcept</span> <span style="color:#66d9ef">override</span> {<span style="color:#66d9ef">return</span> <span style="color:#e6db74">&#34;&#34;</span>;}
|
||||
</span></span><span style="display:flex;"><span>};
|
||||
</span></span><span style="display:flex;"><span>} <span style="color:#75715e">// toml
|
||||
</span></span></span></code></pre></div><h2 id="member-functions">
|
||||
Member Functions
|
||||
<a class="anchor" href="#member-functions">#</a>
|
||||
</h2>
|
||||
<h3 id="destructor">
|
||||
Destructor
|
||||
<a class="anchor" href="#destructor">#</a>
|
||||
</h3>
|
||||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">virtual</span> <span style="color:#f92672">~</span>exception() <span style="color:#66d9ef">noexcept</span> <span style="color:#66d9ef">override</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">default</span>;
|
||||
</span></span></code></pre></div><p>Override when derived.</p>
|
||||
<h3 id="what">
|
||||
<code>what</code>
|
||||
<a class="anchor" href="#what">#</a>
|
||||
</h3>
|
||||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">virtual</span> <span style="color:#66d9ef">const</span> <span style="color:#66d9ef">char</span><span style="color:#f92672">*</span> <span style="color:#a6e22e">what</span>() <span style="color:#66d9ef">const</span> <span style="color:#66d9ef">noexcept</span> <span style="color:#66d9ef">override</span> {<span style="color:#66d9ef">return</span> <span style="color:#e6db74">&#34;&#34;</span>;}
|
||||
</span></span></code></pre></div><p>Returns the error message. Override when derived.</p></description></item><item><title>find.hpp</title><link>https://toruniina.github.io/toml11/docs/reference/find/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/docs/reference/find/</guid><description><h1 id="findhpp">
|
||||
find.hpp
|
||||
<a class="anchor" href="#findhpp">#</a>
|
||||
</h1>
|
||||
<p>This function searches for a value in a <code>toml::value</code> and performs type conversion if necessary.</p>
|
||||
<blockquote class="book-hint info">
|
||||
<code>toml::value</code> can change the type it stores, and <code>toml::find</code> accommodates these types.
|
||||
Technically, all functions use <code>toml::basic_value&lt;TC&gt;</code>.
|
||||
However, for simplicity, we refer to it as <code>toml::value</code> in explanations unless a distinction is necessary.
|
||||
In the documentation, if the template parameter <code>TC</code> changes the type, assume that types like <code>toml::value::integer_type</code> will also change accordingly.
|
||||
</blockquote>
|
||||
|
||||
<h1 id="tomlfind">
|
||||
<code>toml::find</code>
|
||||
<a class="anchor" href="#tomlfind">#</a>
|
||||
</h1>
|
||||
<h2 id="overview">
|
||||
Overview
|
||||
<a class="anchor" href="#overview">#</a>
|
||||
</h2>
|
||||
<p><code>toml::find</code> uses template arguments for the type you want to retrieve and function arguments for the key of the value you want to find.</p></description></item><item><title>format.hpp</title><link>https://toruniina.github.io/toml11/docs/reference/format/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/docs/reference/format/</guid><description><h1 id="formathpp">
|
||||
format.hpp
|
||||
<a class="anchor" href="#formathpp">#</a>
|
||||
</h1>
|
||||
<p>Defines structures and enumerations related to formatting information for <code>toml::value</code>.</p>
|
||||
<h1 id="indent_char">
|
||||
<code>indent_char</code>
|
||||
<a class="anchor" href="#indent_char">#</a>
|
||||
</h1>
|
||||
<p>An enumeration representing the indentation character choice.</p>
|
||||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">enum</span> <span style="color:#66d9ef">class</span> <span style="color:#a6e22e">indent_char</span> <span style="color:#f92672">:</span> std<span style="color:#f92672">::</span><span style="color:#66d9ef">uint8_t</span>
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span> space, <span style="color:#75715e">// use space
|
||||
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> tab, <span style="color:#75715e">// use tab
|
||||
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> none <span style="color:#75715e">// no indent
|
||||
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>};
|
||||
</span></span><span style="display:flex;"><span>std<span style="color:#f92672">::</span>ostream<span style="color:#f92672">&amp;</span> <span style="color:#66d9ef">operator</span><span style="color:#f92672">&lt;&lt;</span>(std<span style="color:#f92672">::</span>ostream<span style="color:#f92672">&amp;</span> os, <span style="color:#66d9ef">const</span> indent_char<span style="color:#f92672">&amp;</span> c);
|
||||
</span></span><span style="display:flex;"><span>std<span style="color:#f92672">::</span>string to_string(<span style="color:#66d9ef">const</span> indent_char);
|
||||
</span></span></code></pre></div><p>Choosing <code>none</code> means no indentation is used, regardless of the value in super tables.</p>
|
||||
<p>If both <code>space</code> and <code>tab</code> are specified within the serializable value, the behavior is unspecified; typically, the unspecified indentation character appears.</p></description></item><item><title>from.hpp</title><link>https://toruniina.github.io/toml11/docs/reference/from/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/docs/reference/from/</guid><description><h1 id="fromhpp">
|
||||
from.hpp
|
||||
<a class="anchor" href="#fromhpp">#</a>
|
||||
</h1>
|
||||
<p>Defines a <code>struct</code> used for conversion from <code>toml::value</code> in <code>toml::get</code> and <code>toml::find</code>.</p>
|
||||
<p>You can achieve the same functionality by adding a <code>from_toml</code> member function, but for classes where you cannot add member functions, use <code>from&lt;T&gt;</code>.</p>
|
||||
<p>This file does not provide specific implementations. Please specialize this <code>struct</code> when using.</p>
|
||||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">namespace</span> toml
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">template</span><span style="color:#f92672">&lt;</span><span style="color:#66d9ef">typename</span> T<span style="color:#f92672">&gt;</span>
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">struct</span> <span style="color:#a6e22e">from</span>;
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span>} <span style="color:#75715e">// toml
|
||||
</span></span></span></code></pre></div><h2 id="example">
|
||||
Example
|
||||
<a class="anchor" href="#example">#</a>
|
||||
</h2>
|
||||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">namespace</span> extlib
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">struct</span> <span style="color:#a6e22e">foo</span>
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">int</span> a;
|
||||
</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>string b;
|
||||
</span></span><span style="display:flex;"><span>};
|
||||
</span></span><span style="display:flex;"><span>} <span style="color:#75715e">// extlib
|
||||
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
|
||||
</span></span><span style="display:flex;"><span><span style="color:#75715e">#include</span> <span style="color:#75715e">&lt;toml11/from.hpp&gt;</span><span style="color:#75715e">
|
||||
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">namespace</span> toml
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">template</span><span style="color:#f92672">&lt;&gt;</span>
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">struct</span> <span style="color:#a6e22e">from</span><span style="color:#f92672">&lt;</span>extlib<span style="color:#f92672">::</span>foo<span style="color:#f92672">&gt;</span>
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">template</span><span style="color:#f92672">&lt;</span><span style="color:#66d9ef">typename</span> TC<span style="color:#f92672">&gt;</span>
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">static</span> extlib<span style="color:#f92672">::</span>foo from_toml(<span style="color:#66d9ef">const</span> toml<span style="color:#f92672">::</span>basic_value<span style="color:#f92672">&lt;</span>TC<span style="color:#f92672">&gt;&amp;</span> v)
|
||||
</span></span><span style="display:flex;"><span> {
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> extlib<span style="color:#f92672">::</span>foo{toml<span style="color:#f92672">::</span>find<span style="color:#f92672">&lt;</span><span style="color:#66d9ef">int</span><span style="color:#f92672">&gt;</span>(v, <span style="color:#e6db74">&#34;a&#34;</span>), toml<span style="color:#f92672">::</span>find<span style="color:#f92672">&lt;</span>std<span style="color:#f92672">::</span>string<span style="color:#f92672">&gt;</span>(v, <span style="color:#e6db74">&#34;b&#34;</span>)};
|
||||
</span></span><span style="display:flex;"><span> }
|
||||
</span></span><span style="display:flex;"><span>};
|
||||
</span></span><span style="display:flex;"><span>} <span style="color:#75715e">// toml
|
||||
</span></span></span></code></pre></div><h1 id="related">
|
||||
Related
|
||||
<a class="anchor" href="#related">#</a>
|
||||
</h1>
|
||||
<ul>
|
||||
<li><a href="https://toruniina.github.io/toml11/docs/reference/conversion/">conversion.hpp</a></li>
|
||||
<li><a href="https://toruniina.github.io/toml11/docs/reference/into/">into.hpp</a></li>
|
||||
</ul></description></item><item><title>get.hpp</title><link>https://toruniina.github.io/toml11/docs/reference/get/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/docs/reference/get/</guid><description><h1 id="gethpp">
|
||||
get.hpp
|
||||
<a class="anchor" href="#gethpp">#</a>
|
||||
</h1>
|
||||
<p>These are functions for extracting values from <code>toml::value</code> and performing type conversions if necessary.</p>
|
||||
<blockquote class="book-hint info">
|
||||
<code>toml::value</code> can change the type it stores, and <code>toml::get</code> accommodates these types.
|
||||
Technically, all functions use <code>toml::basic_value&lt;TC&gt;</code>.
|
||||
However, for simplicity, we refer to it as <code>toml::value</code> in explanations unless a distinction is necessary.
|
||||
In the documentation, if the template parameter <code>TC</code> changes the type, assume that types like <code>toml::value::integer_type</code> will also change accordingly.
|
||||
</blockquote>
|
||||
|
||||
<h1 id="tomlgett">
|
||||
<code>toml::get&lt;T&gt;</code>
|
||||
<a class="anchor" href="#tomlgett">#</a>
|
||||
</h1>
|
||||
<h2 id="overview">
|
||||
Overview
|
||||
<a class="anchor" href="#overview">#</a>
|
||||
</h2>
|
||||
<p>Generally, <code>toml::get</code> behaves as follows:
|
||||
You specify <code>T</code> as in <code>toml::get&lt;int&gt;(v)</code>.</p></description></item><item><title>into.hpp</title><link>https://toruniina.github.io/toml11/docs/reference/into/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/docs/reference/into/</guid><description><h1 id="intohpp">
|
||||
into.hpp
|
||||
<a class="anchor" href="#intohpp">#</a>
|
||||
</h1>
|
||||
<p>Defines a <code>struct</code> used for conversion from user-defined types into <code>toml::value</code> constructors.</p>
|
||||
<p>You can achieve the same functionality by adding an <code>into_toml</code> member function, but for classes where you cannot add member functions, use <code>into&lt;T&gt;</code>.</p>
|
||||
<p>This file does not provide specific implementations. Please specialize this <code>struct</code> when using.</p>
|
||||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">namespace</span> toml
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">template</span><span style="color:#f92672">&lt;</span><span style="color:#66d9ef">typename</span> T<span style="color:#f92672">&gt;</span>
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">struct</span> <span style="color:#a6e22e">into</span>;
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span>} <span style="color:#75715e">// toml
|
||||
</span></span></span></code></pre></div><h2 id="example">
|
||||
Example
|
||||
<a class="anchor" href="#example">#</a>
|
||||
</h2>
|
||||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">namespace</span> extlib
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">struct</span> <span style="color:#a6e22e">foo</span>
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">int</span> a;
|
||||
</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>string b;
|
||||
</span></span><span style="display:flex;"><span>};
|
||||
</span></span><span style="display:flex;"><span>} <span style="color:#75715e">// extlib
|
||||
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
|
||||
</span></span><span style="display:flex;"><span><span style="color:#75715e">#include</span> <span style="color:#75715e">&lt;toml11/into.hpp&gt;</span><span style="color:#75715e">
|
||||
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">namespace</span> toml
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">template</span><span style="color:#f92672">&lt;&gt;</span>
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">struct</span> <span style="color:#a6e22e">into</span><span style="color:#f92672">&lt;</span>extlib<span style="color:#f92672">::</span>foo<span style="color:#f92672">&gt;</span>
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">template</span><span style="color:#f92672">&lt;</span><span style="color:#66d9ef">typename</span> TC<span style="color:#f92672">&gt;</span>
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">static</span> toml<span style="color:#f92672">::</span>basic_value<span style="color:#f92672">&lt;</span>TC<span style="color:#f92672">&gt;</span> into_toml(<span style="color:#66d9ef">const</span> extlib<span style="color:#f92672">::</span>foo<span style="color:#f92672">&amp;</span> f)
|
||||
</span></span><span style="display:flex;"><span> {
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">using</span> value_type <span style="color:#f92672">=</span> toml<span style="color:#f92672">::</span>basic_value<span style="color:#f92672">&lt;</span>TC<span style="color:#f92672">&gt;</span>;
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">using</span> table_type <span style="color:#f92672">=</span> <span style="color:#66d9ef">typename</span> value_type<span style="color:#f92672">::</span>table_type;
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> <span style="color:#a6e22e">value_type</span>(table_type{{<span style="color:#e6db74">&#34;a&#34;</span>, f.a}, {<span style="color:#e6db74">&#34;b&#34;</span>, f.b}});
|
||||
</span></span><span style="display:flex;"><span> }
|
||||
</span></span><span style="display:flex;"><span>};
|
||||
</span></span><span style="display:flex;"><span>} <span style="color:#75715e">// toml
|
||||
</span></span></span></code></pre></div><h1 id="related">
|
||||
Related
|
||||
<a class="anchor" href="#related">#</a>
|
||||
</h1>
|
||||
<ul>
|
||||
<li><a href="https://toruniina.github.io/toml11/docs/reference/conversion/">conversion.hpp</a></li>
|
||||
<li><a href="https://toruniina.github.io/toml11/docs/reference/from/">from.hpp</a></li>
|
||||
</ul></description></item><item><title>literal.hpp</title><link>https://toruniina.github.io/toml11/docs/reference/literal/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/docs/reference/literal/</guid><description><h1 id="literalhpp">
|
||||
literal.hpp
|
||||
<a class="anchor" href="#literalhpp">#</a>
|
||||
</h1>
|
||||
<p>In <code>literal.hpp</code>, the <code>_toml</code> literal is defined.</p>
|
||||
<p>The <code>_toml</code> literal parses string literals into <code>toml::value</code>.</p>
|
||||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">namespace</span> toml
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">inline</span> <span style="color:#66d9ef">namespace</span> literals
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">inline</span> <span style="color:#66d9ef">namespace</span> toml_literals
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span>toml<span style="color:#f92672">::</span>value <span style="color:#66d9ef">operator</span><span style="color:#e6db74">&#34;&#34;</span> _toml(<span style="color:#66d9ef">const</span> <span style="color:#66d9ef">char</span><span style="color:#f92672">*</span> str, std<span style="color:#f92672">::</span>size_t len);
|
||||
</span></span><span style="display:flex;"><span>toml<span style="color:#f92672">::</span>value <span style="color:#66d9ef">operator</span><span style="color:#e6db74">&#34;&#34;</span> _toml(<span style="color:#66d9ef">const</span> <span style="color:#66d9ef">char8_t</span><span style="color:#f92672">*</span> str, std<span style="color:#f92672">::</span>size_t len); <span style="color:#75715e">// Available in C++20 and later
|
||||
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>} <span style="color:#75715e">// toml_literals
|
||||
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>} <span style="color:#75715e">// literals
|
||||
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>} <span style="color:#75715e">// toml
|
||||
</span></span></span></code></pre></div><h2 id="free-functions">
|
||||
Free Functions
|
||||
<a class="anchor" href="#free-functions">#</a>
|
||||
</h2>
|
||||
<h3 id="operator-_tomlconst-char">
|
||||
<code>operator&quot;&quot; _toml(const char*)</code>
|
||||
<a class="anchor" href="#operator-_tomlconst-char">#</a>
|
||||
</h3>
|
||||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span>toml<span style="color:#f92672">::</span>value <span style="color:#66d9ef">operator</span><span style="color:#e6db74">&#34;&#34;</span> _toml(<span style="color:#66d9ef">const</span> <span style="color:#66d9ef">char</span><span style="color:#f92672">*</span> str, std<span style="color:#f92672">::</span>size_t len);
|
||||
</span></span></code></pre></div><p>Converts a string literal into a <code>toml::value</code> by parsing it.</p></description></item><item><title>ordered_map.hpp</title><link>https://toruniina.github.io/toml11/docs/reference/ordered_map/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/docs/reference/ordered_map/</guid><description><h1 id="ordered_maphpp">
|
||||
ordered_map.hpp
|
||||
<a class="anchor" href="#ordered_maphpp">#</a>
|
||||
</h1>
|
||||
<p>Defines <code>toml::ordered_map</code>, which is used to maintain the order of values in a file.</p>
|
||||
<h1 id="class-ordered_map">
|
||||
<code>class ordered_map</code>
|
||||
<a class="anchor" href="#class-ordered_map">#</a>
|
||||
</h1>
|
||||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">namespace</span> toml
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">template</span><span style="color:#f92672">&lt;</span><span style="color:#66d9ef">typename</span> Key, <span style="color:#66d9ef">typename</span> Val, <span style="color:#66d9ef">typename</span> Cmp <span style="color:#f92672">=</span> std<span style="color:#f92672">::</span>equal_to<span style="color:#f92672">&lt;</span>Key<span style="color:#f92672">&gt;</span>,
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">typename</span> Allocator <span style="color:#f92672">=</span> std<span style="color:#f92672">::</span>allocator<span style="color:#f92672">&lt;</span>std<span style="color:#f92672">::</span>pair<span style="color:#f92672">&lt;</span>Key, Val<span style="color:#f92672">&gt;&gt;&gt;</span>
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">ordered_map</span>;
|
||||
</span></span><span style="display:flex;"><span>}
|
||||
</span></span></code></pre></div><p>The <code>ordered_map</code> is a <code>map</code> type that preserves the insertion order of values, allowing iteration in that order.</p>
|
||||
<p>As a linear container, searches require <code>O(n)</code> time relative to the number of elements.
|
||||
Use this when search operations are infrequent and maintaining the order of values is important.</p></description></item><item><title>parser.hpp</title><link>https://toruniina.github.io/toml11/docs/reference/parser/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/docs/reference/parser/</guid><description><h1 id="parserhpp">
|
||||
parser.hpp
|
||||
<a class="anchor" href="#parserhpp">#</a>
|
||||
</h1>
|
||||
<p>Defines functions for parsing files or strings and the exceptions they use.</p>
|
||||
<p>While <code>parse</code> throws an exception on failure, <code>try_parse</code> returns error information.</p>
|
||||
<h1 id="parse">
|
||||
<code>parse</code>
|
||||
<a class="anchor" href="#parse">#</a>
|
||||
</h1>
|
||||
<p>Parses the content of a given file and returns a <code>toml::basic_value</code>.</p>
|
||||
<p>In case of failure, <code>toml::syntax_error</code> is thrown.</p>
|
||||
<p>The type information of <code>basic_value</code> is provided by a <code>template</code>, and the TOML language version is specified by <code>toml::spec</code>.</p>
|
||||
<h3 id="parsestdstring-filename-tomlspec">
|
||||
<code>parse(std::string filename, toml::spec)</code>
|
||||
<a class="anchor" href="#parsestdstring-filename-tomlspec">#</a>
|
||||
</h3>
|
||||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">namespace</span> toml
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">template</span><span style="color:#f92672">&lt;</span><span style="color:#66d9ef">typename</span> TC <span style="color:#f92672">=</span> type_config<span style="color:#f92672">&gt;</span>
|
||||
</span></span><span style="display:flex;"><span>basic_value<span style="color:#f92672">&lt;</span>TC<span style="color:#f92672">&gt;</span>
|
||||
</span></span><span style="display:flex;"><span>parse(std<span style="color:#f92672">::</span>string fname,
|
||||
</span></span><span style="display:flex;"><span> spec s <span style="color:#f92672">=</span> spec<span style="color:#f92672">::</span>default_version());
|
||||
</span></span><span style="display:flex;"><span>}
|
||||
</span></span></code></pre></div><p>Parses the content of the given filename.</p></description></item><item><title>result.hpp</title><link>https://toruniina.github.io/toml11/docs/reference/result/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/docs/reference/result/</guid><description><h1 id="resulthpp">
|
||||
result.hpp
|
||||
<a class="anchor" href="#resulthpp">#</a>
|
||||
</h1>
|
||||
<p><code>result.hpp</code> defines the <code>result</code> type, which can hold either a success value or a failure value.</p>
|
||||
<p>This is used as the return type for <code>toml::try_parse</code>, which does not throw exceptions.</p>
|
||||
<h1 id="success">
|
||||
success
|
||||
<a class="anchor" href="#success">#</a>
|
||||
</h1>
|
||||
<p>A type that holds a success value.</p>
|
||||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">namespace</span> toml
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">template</span><span style="color:#f92672">&lt;</span><span style="color:#66d9ef">typename</span> T<span style="color:#f92672">&gt;</span>
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">struct</span> <span style="color:#a6e22e">success</span>
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">using</span> value_type <span style="color:#f92672">=</span> T;
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">explicit</span> <span style="color:#a6e22e">success</span>(value_type v);
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#f92672">~</span>success() <span style="color:#f92672">=</span> <span style="color:#66d9ef">default</span>;
|
||||
</span></span><span style="display:flex;"><span> success(<span style="color:#66d9ef">const</span> success<span style="color:#f92672">&amp;</span>) <span style="color:#f92672">=</span> <span style="color:#66d9ef">default</span>;
|
||||
</span></span><span style="display:flex;"><span> success(success<span style="color:#f92672">&amp;&amp;</span>) <span style="color:#f92672">=</span> <span style="color:#66d9ef">default</span>;
|
||||
</span></span><span style="display:flex;"><span> success<span style="color:#f92672">&amp;</span> <span style="color:#66d9ef">operator</span><span style="color:#f92672">=</span>(<span style="color:#66d9ef">const</span> success<span style="color:#f92672">&amp;</span>) <span style="color:#f92672">=</span> <span style="color:#66d9ef">default</span>;
|
||||
</span></span><span style="display:flex;"><span> success<span style="color:#f92672">&amp;</span> <span style="color:#66d9ef">operator</span><span style="color:#f92672">=</span>(success<span style="color:#f92672">&amp;&amp;</span>) <span style="color:#f92672">=</span> <span style="color:#66d9ef">default</span>;
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">template</span><span style="color:#f92672">&lt;</span><span style="color:#66d9ef">typename</span> U<span style="color:#f92672">&gt;</span>
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">explicit</span> success(U<span style="color:#f92672">&amp;&amp;</span> v);
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">template</span><span style="color:#f92672">&lt;</span><span style="color:#66d9ef">typename</span> U<span style="color:#f92672">&gt;</span>
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">explicit</span> success(success<span style="color:#f92672">&lt;</span>U<span style="color:#f92672">&gt;</span> v);
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span> value_type<span style="color:#f92672">&amp;</span> get() <span style="color:#66d9ef">noexcept</span>;
|
||||
</span></span><span style="display:flex;"><span> value_type <span style="color:#66d9ef">const</span><span style="color:#f92672">&amp;</span> get() <span style="color:#66d9ef">const</span> <span style="color:#66d9ef">noexcept</span>;
|
||||
</span></span><span style="display:flex;"><span>};
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">template</span><span style="color:#f92672">&lt;</span><span style="color:#66d9ef">typename</span> T<span style="color:#f92672">&gt;</span>
|
||||
</span></span><span style="display:flex;"><span>success<span style="color:#f92672">&lt;</span><span style="color:#66d9ef">typename</span> std<span style="color:#f92672">::</span>decay<span style="color:#f92672">&lt;</span>T<span style="color:#f92672">&gt;::</span>type<span style="color:#f92672">&gt;</span> ok(T<span style="color:#f92672">&amp;&amp;</span> v);
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">template</span><span style="color:#f92672">&lt;</span>std<span style="color:#f92672">::</span>size_t N<span style="color:#f92672">&gt;</span>
|
||||
</span></span><span style="display:flex;"><span>success<span style="color:#f92672">&lt;</span>std<span style="color:#f92672">::</span>string<span style="color:#f92672">&gt;</span> ok(<span style="color:#66d9ef">const</span> <span style="color:#66d9ef">char</span> (<span style="color:#f92672">&amp;</span>literal)[N])
|
||||
</span></span><span style="display:flex;"><span>}
|
||||
</span></span></code></pre></div><h2 id="member-types">
|
||||
Member Types
|
||||
<a class="anchor" href="#member-types">#</a>
|
||||
</h2>
|
||||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">using</span> value_type <span style="color:#f92672">=</span> T;
|
||||
</span></span></code></pre></div><p>The type of the success value.</p></description></item><item><title>serializer.hpp</title><link>https://toruniina.github.io/toml11/docs/reference/serializer/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/docs/reference/serializer/</guid><description><h1 id="serializerhpp">
|
||||
serializer.hpp
|
||||
<a class="anchor" href="#serializerhpp">#</a>
|
||||
</h1>
|
||||
<h2 id="format">
|
||||
<code>format</code>
|
||||
<a class="anchor" href="#format">#</a>
|
||||
</h2>
|
||||
<p>Serializes the data.</p>
|
||||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">namespace</span> toml
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">template</span><span style="color:#f92672">&lt;</span><span style="color:#66d9ef">typename</span> TC<span style="color:#f92672">&gt;</span>
|
||||
</span></span><span style="display:flex;"><span>std<span style="color:#f92672">::</span>string format(<span style="color:#66d9ef">const</span> basic_value<span style="color:#f92672">&lt;</span>TC<span style="color:#f92672">&gt;&amp;</span> v,
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">const</span> spec s <span style="color:#f92672">=</span> spec<span style="color:#f92672">::</span>default_version());
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">template</span><span style="color:#f92672">&lt;</span><span style="color:#66d9ef">typename</span> TC<span style="color:#f92672">&gt;</span>
|
||||
</span></span><span style="display:flex;"><span>std<span style="color:#f92672">::</span>string format(<span style="color:#66d9ef">const</span> <span style="color:#66d9ef">typename</span> basic_value<span style="color:#f92672">&lt;</span>TC<span style="color:#f92672">&gt;::</span>key_type<span style="color:#f92672">&amp;</span> k,
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">const</span> basic_value<span style="color:#f92672">&lt;</span>TC<span style="color:#f92672">&gt;&amp;</span> v,
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">const</span> spec s <span style="color:#f92672">=</span> spec<span style="color:#f92672">::</span>default_version());
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">template</span><span style="color:#f92672">&lt;</span><span style="color:#66d9ef">typename</span> TC<span style="color:#f92672">&gt;</span>
|
||||
</span></span><span style="display:flex;"><span>std<span style="color:#f92672">::</span>string format(<span style="color:#66d9ef">const</span> std<span style="color:#f92672">::</span>vector<span style="color:#f92672">&lt;</span><span style="color:#66d9ef">typename</span> basic_value<span style="color:#f92672">&lt;</span>TC<span style="color:#f92672">&gt;::</span>key_type<span style="color:#f92672">&gt;&amp;</span> ks,
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">const</span> basic_value<span style="color:#f92672">&lt;</span>TC<span style="color:#f92672">&gt;&amp;</span> v,
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">const</span> spec s <span style="color:#f92672">=</span> spec<span style="color:#f92672">::</span>default_version());
|
||||
</span></span><span style="display:flex;"><span>}
|
||||
</span></span></code></pre></div><p>If there&rsquo;s a conflict between the format information and the <code>spec</code>, for example, when using <code>v1.0.0</code> with <code>table_format::multiline_oneline</code>, the <code>spec</code> takes precedence.</p></description></item><item><title>source_location.hpp</title><link>https://toruniina.github.io/toml11/docs/reference/source_location/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/docs/reference/source_location/</guid><description><h1 id="source_locationhpp">
|
||||
source_location.hpp
|
||||
<a class="anchor" href="#source_locationhpp">#</a>
|
||||
</h1>
|
||||
<p><code>source_location.hpp</code> defines a class representing a specific area within a TOML file.</p>
|
||||
<p>This class is used to represent problematic areas in error messages.</p>
|
||||
<h1 id="tomlsource_location">
|
||||
<code>toml::source_location</code>
|
||||
<a class="anchor" href="#tomlsource_location">#</a>
|
||||
</h1>
|
||||
<p><code>source_location</code> is a class representing a specific area within a TOML file.</p>
|
||||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">namespace</span> toml
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">struct</span> <span style="color:#a6e22e">source_location</span>
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">public</span><span style="color:#f92672">:</span>
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">explicit</span> source_location(<span style="color:#75715e">/* implementation-defined */</span>);
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#f92672">~</span>source_location() <span style="color:#f92672">=</span> <span style="color:#66d9ef">default</span>;
|
||||
</span></span><span style="display:flex;"><span> source_location(source_location <span style="color:#66d9ef">const</span><span style="color:#f92672">&amp;</span>) <span style="color:#f92672">=</span> <span style="color:#66d9ef">default</span>;
|
||||
</span></span><span style="display:flex;"><span> source_location(source_location <span style="color:#f92672">&amp;&amp;</span>) <span style="color:#f92672">=</span> <span style="color:#66d9ef">default</span>;
|
||||
</span></span><span style="display:flex;"><span> source_location<span style="color:#f92672">&amp;</span> <span style="color:#66d9ef">operator</span><span style="color:#f92672">=</span>(source_location <span style="color:#66d9ef">const</span><span style="color:#f92672">&amp;</span>) <span style="color:#f92672">=</span> <span style="color:#66d9ef">default</span>;
|
||||
</span></span><span style="display:flex;"><span> source_location<span style="color:#f92672">&amp;</span> <span style="color:#66d9ef">operator</span><span style="color:#f92672">=</span>(source_location <span style="color:#f92672">&amp;&amp;</span>) <span style="color:#f92672">=</span> <span style="color:#66d9ef">default</span>;
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">bool</span> <span style="color:#a6e22e">is_ok</span>() <span style="color:#66d9ef">const</span> <span style="color:#66d9ef">noexcept</span>;
|
||||
</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>size_t length() <span style="color:#66d9ef">const</span> <span style="color:#66d9ef">noexcept</span>;
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>size_t first_line_number() <span style="color:#66d9ef">const</span> <span style="color:#66d9ef">noexcept</span>;
|
||||
</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>size_t first_column_number() <span style="color:#66d9ef">const</span> <span style="color:#66d9ef">noexcept</span>;
|
||||
</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>size_t last_line_number() <span style="color:#66d9ef">const</span> <span style="color:#66d9ef">noexcept</span>;
|
||||
</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>size_t last_column_number() <span style="color:#66d9ef">const</span> <span style="color:#66d9ef">noexcept</span>;
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>string <span style="color:#66d9ef">const</span><span style="color:#f92672">&amp;</span> file_name() <span style="color:#66d9ef">const</span> <span style="color:#66d9ef">noexcept</span>;
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>size_t num_lines() <span style="color:#66d9ef">const</span> <span style="color:#66d9ef">noexcept</span>;
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>string <span style="color:#66d9ef">const</span><span style="color:#f92672">&amp;</span> first_line() <span style="color:#66d9ef">const</span>;
|
||||
</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>string <span style="color:#66d9ef">const</span><span style="color:#f92672">&amp;</span> last_line() <span style="color:#66d9ef">const</span>;
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>vector<span style="color:#f92672">&lt;</span>std<span style="color:#f92672">::</span>string<span style="color:#f92672">&gt;</span> <span style="color:#66d9ef">const</span><span style="color:#f92672">&amp;</span> lines() <span style="color:#66d9ef">const</span> <span style="color:#66d9ef">noexcept</span>;
|
||||
</span></span><span style="display:flex;"><span>};
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">template</span><span style="color:#f92672">&lt;</span><span style="color:#66d9ef">typename</span> ... Ts<span style="color:#f92672">&gt;</span>
|
||||
</span></span><span style="display:flex;"><span>std<span style="color:#f92672">::</span>string format_location(<span style="color:#66d9ef">const</span> source_location<span style="color:#f92672">&amp;</span> loc, <span style="color:#66d9ef">const</span> std<span style="color:#f92672">::</span>string<span style="color:#f92672">&amp;</span> msg, <span style="color:#66d9ef">const</span> Ts<span style="color:#f92672">&amp;</span> ... locs_and_msgs);
|
||||
</span></span><span style="display:flex;"><span>} <span style="color:#75715e">//toml
|
||||
</span></span></span></code></pre></div><h2 id="member-functions">
|
||||
Member Functions
|
||||
<a class="anchor" href="#member-functions">#</a>
|
||||
</h2>
|
||||
<h3 id="constructor">
|
||||
Constructor
|
||||
<a class="anchor" href="#constructor">#</a>
|
||||
</h3>
|
||||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">explicit</span> <span style="color:#a6e22e">source_location</span>(<span style="color:#75715e">/* implementation-defined */</span>);
|
||||
</span></span></code></pre></div><p><code>toml::source_location</code> can only be constructed via <code>toml::parse</code> or the <code>_toml</code> literal.</p></description></item><item><title>spec.hpp</title><link>https://toruniina.github.io/toml11/docs/reference/spec/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/docs/reference/spec/</guid><description><h1 id="spechpp">
|
||||
spec.hpp
|
||||
<a class="anchor" href="#spechpp">#</a>
|
||||
</h1>
|
||||
<p><code>spec.hpp</code> defines classes for specifying the version of TOML.</p>
|
||||
<h1 id="tomlsemantic_version">
|
||||
<code>toml::semantic_version</code>
|
||||
<a class="anchor" href="#tomlsemantic_version">#</a>
|
||||
</h1>
|
||||
<p><code>semantic_version</code> is a class that stores version information.</p>
|
||||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">namespace</span> toml
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">struct</span> <span style="color:#a6e22e">semantic_version</span>
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">constexpr</span> <span style="color:#a6e22e">semantic_version</span>(std<span style="color:#f92672">::</span><span style="color:#66d9ef">uint32_t</span> mjr, std<span style="color:#f92672">::</span><span style="color:#66d9ef">uint32_t</span> mnr, std<span style="color:#f92672">::</span><span style="color:#66d9ef">uint32_t</span> p) <span style="color:#66d9ef">noexcept</span>;
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span><span style="color:#66d9ef">uint32_t</span> major;
|
||||
</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span><span style="color:#66d9ef">uint32_t</span> minor;
|
||||
</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span><span style="color:#66d9ef">uint32_t</span> patch;
|
||||
</span></span><span style="display:flex;"><span>};
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">constexpr</span> semantic_version
|
||||
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">make_semver</span>(std<span style="color:#f92672">::</span><span style="color:#66d9ef">uint32_t</span> major, std<span style="color:#f92672">::</span><span style="color:#66d9ef">uint32_t</span> minor, std<span style="color:#f92672">::</span><span style="color:#66d9ef">uint32_t</span> patch) <span style="color:#66d9ef">noexcept</span>;
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">constexpr</span> <span style="color:#66d9ef">bool</span> <span style="color:#66d9ef">operator</span><span style="color:#f92672">==</span>(<span style="color:#66d9ef">const</span> semantic_version<span style="color:#f92672">&amp;</span>, <span style="color:#66d9ef">const</span> semantic_version<span style="color:#f92672">&amp;</span>) <span style="color:#66d9ef">noexcept</span>;
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">constexpr</span> <span style="color:#66d9ef">bool</span> <span style="color:#66d9ef">operator</span><span style="color:#f92672">!=</span>(<span style="color:#66d9ef">const</span> semantic_version<span style="color:#f92672">&amp;</span>, <span style="color:#66d9ef">const</span> semantic_version<span style="color:#f92672">&amp;</span>) <span style="color:#66d9ef">noexcept</span>;
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">constexpr</span> <span style="color:#66d9ef">bool</span> <span style="color:#66d9ef">operator</span><span style="color:#f92672">&lt;</span> (<span style="color:#66d9ef">const</span> semantic_version<span style="color:#f92672">&amp;</span>, <span style="color:#66d9ef">const</span> semantic_version<span style="color:#f92672">&amp;</span>) <span style="color:#66d9ef">noexcept</span>;
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">constexpr</span> <span style="color:#66d9ef">bool</span> <span style="color:#66d9ef">operator</span><span style="color:#f92672">&lt;=</span>(<span style="color:#66d9ef">const</span> semantic_version<span style="color:#f92672">&amp;</span>, <span style="color:#66d9ef">const</span> semantic_version<span style="color:#f92672">&amp;</span>) <span style="color:#66d9ef">noexcept</span>;
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">constexpr</span> <span style="color:#66d9ef">bool</span> <span style="color:#66d9ef">operator</span><span style="color:#f92672">&gt;</span> (<span style="color:#66d9ef">const</span> semantic_version<span style="color:#f92672">&amp;</span>, <span style="color:#66d9ef">const</span> semantic_version<span style="color:#f92672">&amp;</span>) <span style="color:#66d9ef">noexcept</span>;
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">constexpr</span> <span style="color:#66d9ef">bool</span> <span style="color:#66d9ef">operator</span><span style="color:#f92672">&gt;=</span>(<span style="color:#66d9ef">const</span> semantic_version<span style="color:#f92672">&amp;</span>, <span style="color:#66d9ef">const</span> semantic_version<span style="color:#f92672">&amp;</span>) <span style="color:#66d9ef">noexcept</span>;
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span>std<span style="color:#f92672">::</span>ostream<span style="color:#f92672">&amp;</span> <span style="color:#66d9ef">operator</span><span style="color:#f92672">&lt;&lt;</span>(std<span style="color:#f92672">::</span>ostream<span style="color:#f92672">&amp;</span> os, <span style="color:#66d9ef">const</span> semantic_version<span style="color:#f92672">&amp;</span> ver);
|
||||
</span></span><span style="display:flex;"><span>} <span style="color:#75715e">//toml
|
||||
</span></span></span></code></pre></div><h2 id="member-functions">
|
||||
Member Functions
|
||||
<a class="anchor" href="#member-functions">#</a>
|
||||
</h2>
|
||||
<h3 id="constructor">
|
||||
Constructor
|
||||
<a class="anchor" href="#constructor">#</a>
|
||||
</h3>
|
||||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">constexpr</span> <span style="color:#a6e22e">semantic_version</span>(std<span style="color:#f92672">::</span><span style="color:#66d9ef">uint32_t</span> mjr, std<span style="color:#f92672">::</span><span style="color:#66d9ef">uint32_t</span> mnr, std<span style="color:#f92672">::</span><span style="color:#66d9ef">uint32_t</span> p) <span style="color:#66d9ef">noexcept</span>;
|
||||
</span></span></code></pre></div><p>Constructs a <code>semantic_version</code> instance with the specified <code>major</code>, <code>minor</code>, and <code>patch</code> version numbers.</p></description></item><item><title>toml_fwd.hpp</title><link>https://toruniina.github.io/toml11/docs/reference/toml_fwd/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/docs/reference/toml_fwd/</guid><description><h1 id="toml_fwdhpp">
|
||||
toml_fwd.hpp
|
||||
<a class="anchor" href="#toml_fwdhpp">#</a>
|
||||
</h1>
|
||||
<p><code>toml_fwd.hpp</code> contains forward declarations of structures defined in toml11 and macro definitions.</p>
|
||||
<p>When only forward declarations of toml11 structures are needed and implementation is not required, including <code>toml_fwd.hpp</code> instead of <code>toml.hpp</code> can reduce compilation time.</p>
|
||||
<blockquote class="book-hint warning">
|
||||
Since this file only contains forward declarations, you cannot use <code>toml::table</code>, defined as <code>toml::basic_value&lt;toml::type_config&gt;::table_type</code>, and similarly defined <code>toml::array</code>. This is because they require the implementation of <code>basic_value</code>.
|
||||
</blockquote>
|
||||
|
||||
<p>This header file and <code>toml.hpp</code> are located under <code>${TOML11_INCLUDE_DIR}/</code>, while other header files are located under <code>${TOML11_INCLUDE_DIR}/toml11/</code>.</p></description></item><item><title>toml.hpp</title><link>https://toruniina.github.io/toml11/docs/reference/toml/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/docs/reference/toml/</guid><description><h1 id="tomlhpp">
|
||||
toml.hpp
|
||||
<a class="anchor" href="#tomlhpp">#</a>
|
||||
</h1>
|
||||
<p><code>toml.hpp</code> includes all other headers.</p>
|
||||
<p>This allows access to all features of toml11.</p>
|
||||
<p>This header file and <code>toml_fwd.hpp</code> are located under <code>${TOML11_INCLUDE_DIR}/</code>,
|
||||
while other header files are located under <code>${toml11_include_dir}/toml11/</code>.</p></description></item><item><title>types.hpp</title><link>https://toruniina.github.io/toml11/docs/reference/types/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/docs/reference/types/</guid><description><h1 id="typeshpp">
|
||||
types.hpp
|
||||
<a class="anchor" href="#typeshpp">#</a>
|
||||
</h1>
|
||||
<p>This document defines classes that specifies type information.</p>
|
||||
<h1 id="type_config">
|
||||
<code>type_config</code>
|
||||
<a class="anchor" href="#type_config">#</a>
|
||||
</h1>
|
||||
<p><code>type_config</code> is a type that encapsulates parameters given to <code>toml::basic_value</code>.</p>
|
||||
<p>When using different types within <code>toml::basic_value&lt;T&gt;</code>, you need to define and pass this type separately.
|
||||
All elements listed are required.</p>
|
||||
<p>If you use numerical types that cannot use standard stream operators, define and replace the equivalents for <code>read_int</code> and <code>read_float</code>.</p>
|
||||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">namespace</span> toml
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">struct</span> <span style="color:#a6e22e">type_config</span>
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">using</span> comment_type <span style="color:#f92672">=</span> preserve_comments;
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">using</span> boolean_type <span style="color:#f92672">=</span> <span style="color:#66d9ef">bool</span>;
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">using</span> integer_type <span style="color:#f92672">=</span> std<span style="color:#f92672">::</span><span style="color:#66d9ef">int64_t</span>;
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">using</span> floating_type <span style="color:#f92672">=</span> <span style="color:#66d9ef">double</span>;
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">using</span> string_type <span style="color:#f92672">=</span> std<span style="color:#f92672">::</span>string;
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">template</span><span style="color:#f92672">&lt;</span><span style="color:#66d9ef">typename</span> T<span style="color:#f92672">&gt;</span>
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">using</span> array_type <span style="color:#f92672">=</span> std<span style="color:#f92672">::</span>vector<span style="color:#f92672">&lt;</span>T<span style="color:#f92672">&gt;</span>;
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">template</span><span style="color:#f92672">&lt;</span><span style="color:#66d9ef">typename</span> K, <span style="color:#66d9ef">typename</span> T<span style="color:#f92672">&gt;</span>
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">using</span> table_type <span style="color:#f92672">=</span> std<span style="color:#f92672">::</span>unordered_map<span style="color:#f92672">&lt;</span>K, T<span style="color:#f92672">&gt;</span>;
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">static</span> result<span style="color:#f92672">&lt;</span>integer_type, error_info<span style="color:#f92672">&gt;</span>
|
||||
</span></span><span style="display:flex;"><span> parse_int(<span style="color:#66d9ef">const</span> std<span style="color:#f92672">::</span>string<span style="color:#f92672">&amp;</span> str, <span style="color:#66d9ef">const</span> source_location src, <span style="color:#66d9ef">const</span> std<span style="color:#f92672">::</span><span style="color:#66d9ef">uint8_t</span> base);
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">static</span> result<span style="color:#f92672">&lt;</span>floating_type, error_info<span style="color:#f92672">&gt;</span>
|
||||
</span></span><span style="display:flex;"><span> parse_float(<span style="color:#66d9ef">const</span> std<span style="color:#f92672">::</span>string<span style="color:#f92672">&amp;</span> str, <span style="color:#66d9ef">const</span> source_location src, <span style="color:#66d9ef">const</span> <span style="color:#66d9ef">bool</span> is_hex);
|
||||
</span></span><span style="display:flex;"><span>};
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">using</span> value <span style="color:#f92672">=</span> basic_value<span style="color:#f92672">&lt;</span>type_config<span style="color:#f92672">&gt;</span>;
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">using</span> table <span style="color:#f92672">=</span> <span style="color:#66d9ef">typename</span> value<span style="color:#f92672">::</span>table_type;
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">using</span> array <span style="color:#f92672">=</span> <span style="color:#66d9ef">typename</span> value<span style="color:#f92672">::</span>array_type;
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span>} <span style="color:#75715e">// toml
|
||||
</span></span></span></code></pre></div><h2 id="static-member-functions">
|
||||
<code>static</code> Member Functions
|
||||
<a class="anchor" href="#static-member-functions">#</a>
|
||||
</h2>
|
||||
<h3 id="parse_intstr-src-base">
|
||||
<code>parse_int(str, src, base)</code>
|
||||
<a class="anchor" href="#parse_intstr-src-base">#</a>
|
||||
</h3>
|
||||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">static</span> result<span style="color:#f92672">&lt;</span>integer_type, error_info<span style="color:#f92672">&gt;</span>
|
||||
</span></span><span style="display:flex;"><span>parse_int(<span style="color:#66d9ef">const</span> std<span style="color:#f92672">::</span>string<span style="color:#f92672">&amp;</span> str, <span style="color:#66d9ef">const</span> source_location src, <span style="color:#66d9ef">const</span> std<span style="color:#f92672">::</span><span style="color:#66d9ef">uint8_t</span> base);
|
||||
</span></span></code></pre></div><p>If you use a type as <code>integer_type</code> that cannot utilize standard stream operators, implement this function.
|
||||
Otherwise, use <code>read_int</code> described later.</p></description></item><item><title>value_t.hpp</title><link>https://toruniina.github.io/toml11/docs/reference/value_t/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/docs/reference/value_t/</guid><description><h1 id="value_thpp">
|
||||
value_t.hpp
|
||||
<a class="anchor" href="#value_thpp">#</a>
|
||||
</h1>
|
||||
<h1 id="value_t">
|
||||
<code>value_t</code>
|
||||
<a class="anchor" href="#value_t">#</a>
|
||||
</h1>
|
||||
<p><code>value_t</code> is used to handle the type information of <code>toml::value</code>.</p>
|
||||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">namespace</span> toml
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">enum</span> <span style="color:#66d9ef">class</span> <span style="color:#a6e22e">value_t</span> <span style="color:#f92672">:</span> std<span style="color:#f92672">::</span><span style="color:#66d9ef">uint8_t</span>
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span> empty <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>,
|
||||
</span></span><span style="display:flex;"><span> boolean <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>,
|
||||
</span></span><span style="display:flex;"><span> integer <span style="color:#f92672">=</span> <span style="color:#ae81ff">2</span>,
|
||||
</span></span><span style="display:flex;"><span> floating <span style="color:#f92672">=</span> <span style="color:#ae81ff">3</span>,
|
||||
</span></span><span style="display:flex;"><span> string <span style="color:#f92672">=</span> <span style="color:#ae81ff">4</span>,
|
||||
</span></span><span style="display:flex;"><span> offset_datetime <span style="color:#f92672">=</span> <span style="color:#ae81ff">5</span>,
|
||||
</span></span><span style="display:flex;"><span> local_datetime <span style="color:#f92672">=</span> <span style="color:#ae81ff">6</span>,
|
||||
</span></span><span style="display:flex;"><span> local_date <span style="color:#f92672">=</span> <span style="color:#ae81ff">7</span>,
|
||||
</span></span><span style="display:flex;"><span> local_time <span style="color:#f92672">=</span> <span style="color:#ae81ff">8</span>,
|
||||
</span></span><span style="display:flex;"><span> array <span style="color:#f92672">=</span> <span style="color:#ae81ff">9</span>,
|
||||
</span></span><span style="display:flex;"><span> table <span style="color:#f92672">=</span> <span style="color:#ae81ff">10</span>
|
||||
</span></span><span style="display:flex;"><span>};
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span>std<span style="color:#f92672">::</span>ostream<span style="color:#f92672">&amp;</span> <span style="color:#66d9ef">operator</span><span style="color:#f92672">&lt;&lt;</span>(std<span style="color:#f92672">::</span>ostream<span style="color:#f92672">&amp;</span> os, value_t t);
|
||||
</span></span><span style="display:flex;"><span>std<span style="color:#f92672">::</span>string to_string(value_t t);
|
||||
</span></span><span style="display:flex;"><span>} <span style="color:#75715e">// toml
|
||||
</span></span></span></code></pre></div><h2 id="non-member-functions">
|
||||
Non-member Functions
|
||||
<a class="anchor" href="#non-member-functions">#</a>
|
||||
</h2>
|
||||
<h3 id="stream-operator">
|
||||
Stream Operator
|
||||
<a class="anchor" href="#stream-operator">#</a>
|
||||
</h3>
|
||||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span>std<span style="color:#f92672">::</span>ostream<span style="color:#f92672">&amp;</span> <span style="color:#66d9ef">operator</span><span style="color:#f92672">&lt;&lt;</span>(std<span style="color:#f92672">::</span>ostream<span style="color:#f92672">&amp;</span> os, value_t t);
|
||||
</span></span></code></pre></div><p>Outputs the string representation of the <code>value_t</code> to the stream.</p></description></item><item><title>value.hpp</title><link>https://toruniina.github.io/toml11/docs/reference/value/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/docs/reference/value/</guid><description><h1 id="valuehpp">
|
||||
value.hpp
|
||||
<a class="anchor" href="#valuehpp">#</a>
|
||||
</h1>
|
||||
<p><code>value.hpp</code> defines <code>basic_value</code>.</p>
|
||||
<h1 id="tomlbasic_value">
|
||||
<code>toml::basic_value</code>
|
||||
<a class="anchor" href="#tomlbasic_value">#</a>
|
||||
</h1>
|
||||
<p><code>basic_value</code> is a class that stores TOML values.</p>
|
||||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">namespace</span> toml
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">template</span> <span style="color:#f92672">&lt;</span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">TypeConfig</span><span style="color:#f92672">&gt;</span>
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">basic_value</span>;
|
||||
</span></span><span style="display:flex;"><span>
|
||||
</span></span><span style="display:flex;"><span><span style="color:#75715e">// Defined in types.hpp
|
||||
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// using value = basic_value&lt;type_config&gt;;
|
||||
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// using table = typename basic_value&lt;type_config&gt;::table_type;
|
||||
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// using array = typename basic_value&lt;type_config&gt;::array_type;
|
||||
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">template</span><span style="color:#f92672">&lt;</span><span style="color:#66d9ef">typename</span> TC<span style="color:#f92672">&gt;</span>
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">bool</span> <span style="color:#66d9ef">operator</span><span style="color:#f92672">==</span>(<span style="color:#66d9ef">const</span> basic_value<span style="color:#f92672">&lt;</span>TC<span style="color:#f92672">&gt;&amp;</span>, <span style="color:#66d9ef">const</span> basic_value<span style="color:#f92672">&lt;</span>TC<span style="color:#f92672">&gt;&amp;</span>);
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">template</span><span style="color:#f92672">&lt;</span><span style="color:#66d9ef">typename</span> TC<span style="color:#f92672">&gt;</span>
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">bool</span> <span style="color:#66d9ef">operator</span><span style="color:#f92672">!=</span>(<span style="color:#66d9ef">const</span> basic_value<span style="color:#f92672">&lt;</span>TC<span style="color:#f92672">&gt;&amp;</span>, <span style="color:#66d9ef">const</span> basic_value<span style="color:#f92672">&lt;</span>TC<span style="color:#f92672">&gt;&amp;</span>);
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">template</span><span style="color:#f92672">&lt;</span><span style="color:#66d9ef">typename</span> TC<span style="color:#f92672">&gt;</span>
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">bool</span> <span style="color:#66d9ef">operator</span><span style="color:#f92672">&lt;</span> (<span style="color:#66d9ef">const</span> basic_value<span style="color:#f92672">&lt;</span>TC<span style="color:#f92672">&gt;&amp;</span>, <span style="color:#66d9ef">const</span> basic_value<span style="color:#f92672">&lt;</span>TC<span style="color:#f92672">&gt;&amp;</span>);
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">template</span><span style="color:#f92672">&lt;</span><span style="color:#66d9ef">typename</span> TC<span style="color:#f92672">&gt;</span>
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">bool</span> <span style="color:#66d9ef">operator</span><span style="color:#f92672">&lt;=</span>(<span style="color:#66d9ef">const</span> basic_value<span style="color:#f92672">&lt;</span>TC<span style="color:#f92672">&gt;&amp;</span>, <span style="color:#66d9ef">const</span> basic_value<span style="color:#f92672">&lt;</span>TC<span style="color:#f92672">&gt;&amp;</span>);
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">template</span><span style="color:#f92672">&lt;</span><span style="color:#66d9ef">typename</span> TC<span style="color:#f92672">&gt;</span>
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">bool</span> <span style="color:#66d9ef">operator</span><span style="color:#f92672">&gt;</span> (<span style="color:#66d9ef">const</span> basic_value<span style="color:#f92672">&lt;</span>TC<span style="color:#f92672">&gt;&amp;</span>, <span style="color:#66d9ef">const</span> basic_value<span style="color:#f92672">&lt;</span>TC<span style="color:#f92672">&gt;&amp;</span>);
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">template</span><span style="color:#f92672">&lt;</span><span style="color:#66d9ef">typename</span> TC<span style="color:#f92672">&gt;</span>
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">bool</span> <span style="color:#66d9ef">operator</span><span style="color:#f92672">&gt;=</span>(<span style="color:#66d9ef">const</span> basic_value<span style="color:#f92672">&lt;</span>TC<span style="color:#f92672">&gt;&amp;</span>, <span style="color:#66d9ef">const</span> basic_value<span style="color:#f92672">&lt;</span>TC<span style="color:#f92672">&gt;&amp;</span>);
|
||||
</span></span><span style="display:flex;"><span>} <span style="color:#75715e">//toml
|
||||
</span></span></span></code></pre></div><h2 id="member-types">
|
||||
Member Types
|
||||
<a class="anchor" href="#member-types">#</a>
|
||||
</h2>
|
||||
<p>The following member types are defined.</p></description></item><item><title>version.hpp</title><link>https://toruniina.github.io/toml11/docs/reference/version/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/docs/reference/version/</guid><description><h1 id="versionhpp">
|
||||
version.hpp
|
||||
<a class="anchor" href="#versionhpp">#</a>
|
||||
</h1>
|
||||
<p>In <code>version.hpp</code>, macros related to the version information of toml11 are defined.</p>
|
||||
<h2 id="macros">
|
||||
Macros
|
||||
<a class="anchor" href="#macros">#</a>
|
||||
</h2>
|
||||
<h3 id="toml11_version_major">
|
||||
<code>TOML11_VERSION_MAJOR</code>
|
||||
<a class="anchor" href="#toml11_version_major">#</a>
|
||||
</h3>
|
||||
<p>The major version of toml11.</p>
|
||||
<h3 id="toml11_version_minor">
|
||||
<code>TOML11_VERSION_MINOR</code>
|
||||
<a class="anchor" href="#toml11_version_minor">#</a>
|
||||
</h3>
|
||||
<p>The minor version of toml11.</p>
|
||||
<h3 id="toml11_version_patch">
|
||||
<code>TOML11_VERSION_PATCH</code>
|
||||
<a class="anchor" href="#toml11_version_patch">#</a>
|
||||
</h3>
|
||||
<p>The patch version of toml11.</p>
|
||||
<h2 id="function">
|
||||
Function
|
||||
<a class="anchor" href="#function">#</a>
|
||||
</h2>
|
||||
<h3 id="license_notice">
|
||||
<code>license_notice</code>
|
||||
<a class="anchor" href="#license_notice">#</a>
|
||||
</h3>
|
||||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">namespace</span> toml
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">const</span> <span style="color:#66d9ef">char</span><span style="color:#f92672">*</span> <span style="color:#a6e22e">license_notice</span>() <span style="color:#66d9ef">noexcept</span>;
|
||||
</span></span><span style="display:flex;"><span>}
|
||||
</span></span></code></pre></div><p>Returns the license notice.</p>
|
||||
<p>Provided for convenience when redistributing without source code.</p></description></item><item><title>visit.hpp</title><link>https://toruniina.github.io/toml11/docs/reference/visit/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/docs/reference/visit/</guid><description><h1 id="visithpp">
|
||||
visit.hpp
|
||||
<a class="anchor" href="#visithpp">#</a>
|
||||
</h1>
|
||||
<p>In <code>visit.hpp</code>, <code>toml::visit</code> is defined.</p>
|
||||
<h1 id="tomlvisit">
|
||||
<code>toml::visit</code>
|
||||
<a class="anchor" href="#tomlvisit">#</a>
|
||||
</h1>
|
||||
<h2 id="functions">
|
||||
Functions
|
||||
<a class="anchor" href="#functions">#</a>
|
||||
</h2>
|
||||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">namespace</span> toml
|
||||
</span></span><span style="display:flex;"><span>{
|
||||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">template</span><span style="color:#f92672">&lt;</span><span style="color:#66d9ef">typename</span> Visitor, <span style="color:#66d9ef">typename</span> ... Args<span style="color:#f92672">&gt;</span>
|
||||
</span></span><span style="display:flex;"><span><span style="color:#75715e">/* Return value when Visitor is called with a value of basic_value&lt;TC&gt; */</span>
|
||||
</span></span><span style="display:flex;"><span>visit(Visitor<span style="color:#f92672">&amp;&amp;</span> visitor, Args<span style="color:#f92672">&amp;&amp;</span> ... args);
|
||||
</span></span><span style="display:flex;"><span>}
|
||||
</span></span></code></pre></div><p><code>toml::visit</code> calls the overload of <code>Visitor</code> corresponding to the type held by <code>basic_value&lt;TC&gt;</code>, and returns the result.</p>
|
||||
<h4 id="requirements">
|
||||
Requirements
|
||||
<a class="anchor" href="#requirements">#</a>
|
||||
</h4>
|
||||
<p><code>Visitor</code> must be a function or function object callable with any type held by <code>basic_value&lt;TC&gt;</code>.</p></description></item></channel></rss>
|
||||
96
docs/reference/into/index.html
Normal file
96
docs/reference/into/index.html
Normal file
@@ -0,0 +1,96 @@
|
||||
<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content='
|
||||
into.hpp
|
||||
#
|
||||
|
||||
Defines a struct used for conversion from user-defined types into toml::value constructors.
|
||||
You can achieve the same functionality by adding an into_toml member function, but for classes where you cannot add member functions, use into<T>.
|
||||
This file does not provide specific implementations. Please specialize this struct when using.
|
||||
namespace toml
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
struct into;
|
||||
|
||||
} // toml
|
||||
|
||||
Example
|
||||
#
|
||||
|
||||
namespace extlib
|
||||
{
|
||||
struct foo
|
||||
{
|
||||
int a;
|
||||
std::string b;
|
||||
};
|
||||
} // extlib
|
||||
|
||||
#include <toml11/into.hpp>
|
||||
|
||||
namespace toml
|
||||
{
|
||||
template<>
|
||||
struct into<extlib::foo>
|
||||
{
|
||||
template<typename TC>
|
||||
static toml::basic_value<TC> into_toml(const extlib::foo& f)
|
||||
{
|
||||
using value_type = toml::basic_value<TC>;
|
||||
using table_type = typename value_type::table_type;
|
||||
return value_type(table_type{{"a", f.a}, {"b", f.b}});
|
||||
}
|
||||
};
|
||||
} // toml
|
||||
|
||||
Related
|
||||
#
|
||||
|
||||
|
||||
conversion.hpp
|
||||
from.hpp
|
||||
'><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/reference/into/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="into.hpp"><meta property="og:description" content='into.hpp # Defines a struct used for conversion from user-defined types into toml::value constructors.
|
||||
You can achieve the same functionality by adding an into_toml member function, but for classes where you cannot add member functions, use into<T>.
|
||||
This file does not provide specific implementations. Please specialize this struct when using.
|
||||
namespace toml { template<typename T> struct into; } // toml Example # namespace extlib { struct foo { int a; std::string b; }; } // extlib #include <toml11/into.hpp> namespace toml { template<> struct into<extlib::foo> { template<typename TC> static toml::basic_value<TC> into_toml(const extlib::foo& f) { using value_type = toml::basic_value<TC>; using table_type = typename value_type::table_type; return value_type(table_type{{"a", f.a}, {"b", f.b}}); } }; } // toml Related # conversion.hpp from.hpp'><meta property="og:locale" content="en"><meta property="og:type" content="article"><meta property="article:section" content="docs"><title>into.hpp | toml11</title><link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/reference/into/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/reference/into/ title=into.hpp><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" crossorigin=anonymous></script></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
|
||||
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
|
||||
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
|
||||
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/reference/into/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle>
|
||||
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle checked>
|
||||
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/ class=active>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
|
||||
</label><strong>into.hpp</strong>
|
||||
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#intohpp>into.hpp</a><ul><li><a href=#example>Example</a></li></ul></li><li><a href=#related>Related</a></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=intohpp>into.hpp
|
||||
<a class=anchor href=#intohpp>#</a></h1><p>Defines a <code>struct</code> used for conversion from user-defined types into <code>toml::value</code> constructors.</p><p>You can achieve the same functionality by adding an <code>into_toml</code> member function, but for classes where you cannot add member functions, use <code>into<T></code>.</p><p>This file does not provide specific implementations. Please specialize this <code>struct</code> when using.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>into</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span>} <span style=color:#75715e>// toml
|
||||
</span></span></span></code></pre></div><h2 id=example>Example
|
||||
<a class=anchor href=#example>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> extlib
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>foo</span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>int</span> a;
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string b;
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span><span style=display:flex><span>} <span style=color:#75715e>// extlib
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><toml11/into.hpp></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>into</span><span style=color:#f92672><</span>extlib<span style=color:#f92672>::</span>foo<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>static</span> toml<span style=color:#f92672>::</span>basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>></span> into_toml(<span style=color:#66d9ef>const</span> extlib<span style=color:#f92672>::</span>foo<span style=color:#f92672>&</span> f)
|
||||
</span></span><span style=display:flex><span> {
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> value_type <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>></span>;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> table_type <span style=color:#f92672>=</span> <span style=color:#66d9ef>typename</span> value_type<span style=color:#f92672>::</span>table_type;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#a6e22e>value_type</span>(table_type{{<span style=color:#e6db74>"a"</span>, f.a}, {<span style=color:#e6db74>"b"</span>, f.b}});
|
||||
</span></span><span style=display:flex><span> }
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span><span style=display:flex><span>} <span style=color:#75715e>// toml
|
||||
</span></span></span></code></pre></div><h1 id=related>Related
|
||||
<a class=anchor href=#related>#</a></h1><ul><li><a href=https://toruniina.github.io/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=https://toruniina.github.io/toml11/docs/reference/from/>from.hpp</a></li></ul></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#intohpp>into.hpp</a><ul><li><a href=#example>Example</a></li></ul></li><li><a href=#related>Related</a></li></ul></nav></div></aside></main></body></html>
|
||||
69
docs/reference/literal/index.html
Normal file
69
docs/reference/literal/index.html
Normal file
@@ -0,0 +1,69 @@
|
||||
<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content='
|
||||
literal.hpp
|
||||
#
|
||||
|
||||
In literal.hpp, the _toml literal is defined.
|
||||
The _toml literal parses string literals into toml::value.
|
||||
namespace toml
|
||||
{
|
||||
inline namespace literals
|
||||
{
|
||||
inline namespace toml_literals
|
||||
{
|
||||
toml::value operator"" _toml(const char* str, std::size_t len);
|
||||
toml::value operator"" _toml(const char8_t* str, std::size_t len); // Available in C++20 and later
|
||||
} // toml_literals
|
||||
} // literals
|
||||
} // toml
|
||||
|
||||
Free Functions
|
||||
#
|
||||
|
||||
|
||||
operator"" _toml(const char*)
|
||||
#
|
||||
|
||||
toml::value operator"" _toml(const char* str, std::size_t len);
|
||||
Converts a string literal into a toml::value by parsing it.'><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/reference/literal/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="literal.hpp"><meta property="og:description" content='literal.hpp # In literal.hpp, the _toml literal is defined.
|
||||
The _toml literal parses string literals into toml::value.
|
||||
namespace toml { inline namespace literals { inline namespace toml_literals { toml::value operator"" _toml(const char* str, std::size_t len); toml::value operator"" _toml(const char8_t* str, std::size_t len); // Available in C++20 and later } // toml_literals } // literals } // toml Free Functions # operator"" _toml(const char*) # toml::value operator"" _toml(const char* str, std::size_t len); Converts a string literal into a toml::value by parsing it.'><meta property="og:locale" content="en"><meta property="og:type" content="article"><meta property="article:section" content="docs"><title>literal.hpp | toml11</title><link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/reference/literal/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/reference/literal/ title=literal.hpp><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" crossorigin=anonymous></script></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
|
||||
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
|
||||
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
|
||||
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/reference/literal/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle>
|
||||
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle checked>
|
||||
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/ class=active>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
|
||||
</label><strong>literal.hpp</strong>
|
||||
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#literalhpp>literal.hpp</a><ul><li><a href=#free-functions>Free Functions</a><ul><li><a href=#operator-_tomlconst-char><code>operator"" _toml(const char*)</code></a></li><li><a href=#operator-_tomlconst-char8_t><code>operator"" _toml(const char8_t*)</code></a></li></ul></li></ul></li><li><a href=#example>Example</a></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=literalhpp>literal.hpp
|
||||
<a class=anchor href=#literalhpp>#</a></h1><p>In <code>literal.hpp</code>, the <code>_toml</code> literal is defined.</p><p>The <code>_toml</code> literal parses string literals into <code>toml::value</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>inline</span> <span style=color:#66d9ef>namespace</span> literals
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>inline</span> <span style=color:#66d9ef>namespace</span> toml_literals
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span>toml<span style=color:#f92672>::</span>value <span style=color:#66d9ef>operator</span><span style=color:#e6db74>""</span> _toml(<span style=color:#66d9ef>const</span> <span style=color:#66d9ef>char</span><span style=color:#f92672>*</span> str, std<span style=color:#f92672>::</span>size_t len);
|
||||
</span></span><span style=display:flex><span>toml<span style=color:#f92672>::</span>value <span style=color:#66d9ef>operator</span><span style=color:#e6db74>""</span> _toml(<span style=color:#66d9ef>const</span> <span style=color:#66d9ef>char8_t</span><span style=color:#f92672>*</span> str, std<span style=color:#f92672>::</span>size_t len); <span style=color:#75715e>// Available in C++20 and later
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>} <span style=color:#75715e>// toml_literals
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>} <span style=color:#75715e>// literals
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>} <span style=color:#75715e>// toml
|
||||
</span></span></span></code></pre></div><h2 id=free-functions>Free Functions
|
||||
<a class=anchor href=#free-functions>#</a></h2><h3 id=operator-_tomlconst-char><code>operator"" _toml(const char*)</code>
|
||||
<a class=anchor href=#operator-_tomlconst-char>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>toml<span style=color:#f92672>::</span>value <span style=color:#66d9ef>operator</span><span style=color:#e6db74>""</span> _toml(<span style=color:#66d9ef>const</span> <span style=color:#66d9ef>char</span><span style=color:#f92672>*</span> str, std<span style=color:#f92672>::</span>size_t len);
|
||||
</span></span></code></pre></div><p>Converts a string literal into a <code>toml::value</code> by parsing it.</p><p>For typical TOML files, this performs equivalent parsing to <code>toml::parse</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> v1 <span style=color:#f92672>=</span> <span style=color:#e6db74>"a = 'foo'"</span>_toml; <span style=color:#75715e>// v1: {a = 'foo'}
|
||||
</span></span></span></code></pre></div><p>When dealing with multiline content, raw string literal is convenient.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> v1 <span style=color:#f92672>=</span> R<span style=color:#e6db74>"(</span>
|
||||
</span></span><span style=display:flex><span> a <span style=color:#f92672>=</span> <span style=color:#ae81ff>42</span>
|
||||
</span></span><span style=display:flex><span> b <span style=color:#f92672>=</span> <span style=color:#e6db74>"foo"</span>
|
||||
</span></span><span style=display:flex><span>)<span style=color:#e6db74>"_toml;</span>
|
||||
</span></span></code></pre></div><p>If the value is a standalone entity, it represents that value.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> v2 <span style=color:#f92672>=</span> <span style=color:#e6db74>"'foo'"</span>_toml; <span style=color:#75715e>// v2: 'foo'
|
||||
</span></span></span></code></pre></div><p>TOML allows keys consisting solely of numbers. When distinguishing between table definitions and arrays is ambiguous (e.g., <code>[1]</code>), table definitions take precedence.</p><p>To interpret as an array, use a trailing comma.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> v3 <span style=color:#f92672>=</span> <span style=color:#e6db74>"[1]"</span>_toml; <span style=color:#75715e>// v3: {1 = {}}
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> v4 <span style=color:#f92672>=</span> <span style=color:#e6db74>"[1,]"</span>_toml; <span style=color:#75715e>// v4: [1,]
|
||||
</span></span></span></code></pre></div><h3 id=operator-_tomlconst-char8_t><code>operator"" _toml(const char8_t*)</code>
|
||||
<a class=anchor href=#operator-_tomlconst-char8_t>#</a></h3><p>Defined when <code>char8_t</code> is available. Otherwise identical in functionality, differing only in argument type.</p><h1 id=example>Example
|
||||
<a class=anchor href=#example>#</a></h1><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><toml.hpp></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> <span style=color:#66d9ef>namespace</span> toml<span style=color:#f92672>::</span>literals<span style=color:#f92672>::</span>toml_literals;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> v <span style=color:#f92672>=</span> <span style=color:#e6db74>"a = </span><span style=color:#ae81ff>\"</span><span style=color:#e6db74>foo</span><span style=color:#ae81ff>\"</span><span style=color:#e6db74>"</span>_toml;
|
||||
</span></span><span style=display:flex><span> assert(v.at(<span style=color:#e6db74>"a"</span>).as_string() <span style=color:#f92672>==</span> <span style=color:#e6db74>"foo"</span>);
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#literalhpp>literal.hpp</a><ul><li><a href=#free-functions>Free Functions</a><ul><li><a href=#operator-_tomlconst-char><code>operator"" _toml(const char*)</code></a></li><li><a href=#operator-_tomlconst-char8_t><code>operator"" _toml(const char8_t*)</code></a></li></ul></li></ul></li><li><a href=#example>Example</a></li></ul></nav></div></aside></main></body></html>
|
||||
158
docs/reference/ordered_map/index.html
Normal file
158
docs/reference/ordered_map/index.html
Normal file
@@ -0,0 +1,158 @@
|
||||
<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
|
||||
ordered_map.hpp
|
||||
#
|
||||
|
||||
Defines toml::ordered_map, which is used to maintain the order of values in a file.
|
||||
|
||||
class ordered_map
|
||||
#
|
||||
|
||||
namespace toml
|
||||
{
|
||||
template<typename Key, typename Val, typename Cmp = std::equal_to<Key>,
|
||||
typename Allocator = std::allocator<std::pair<Key, Val>>>
|
||||
class ordered_map;
|
||||
}
|
||||
The ordered_map is a map type that preserves the insertion order of values, allowing iteration in that order.
|
||||
As a linear container, searches require O(n) time relative to the number of elements.
|
||||
Use this when search operations are infrequent and maintaining the order of values is important."><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/reference/ordered_map/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="ordered_map.hpp"><meta property="og:description" content="ordered_map.hpp # Defines toml::ordered_map, which is used to maintain the order of values in a file.
|
||||
class ordered_map # namespace toml { template<typename Key, typename Val, typename Cmp = std::equal_to<Key>, typename Allocator = std::allocator<std::pair<Key, Val>>> class ordered_map; } The ordered_map is a map type that preserves the insertion order of values, allowing iteration in that order.
|
||||
As a linear container, searches require O(n) time relative to the number of elements. Use this when search operations are infrequent and maintaining the order of values is important."><meta property="og:locale" content="en"><meta property="og:type" content="article"><meta property="article:section" content="docs"><title>ordered_map.hpp | toml11</title><link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/reference/ordered_map/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/reference/ordered_map/ title=ordered_map.hpp><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" crossorigin=anonymous></script></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
|
||||
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
|
||||
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
|
||||
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/reference/ordered_map/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle>
|
||||
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle checked>
|
||||
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/ class=active>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
|
||||
</label><strong>ordered_map.hpp</strong>
|
||||
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#ordered_maphpp>ordered_map.hpp</a></li><li><a href=#class-ordered_map><code>class ordered_map</code></a><ul><li><a href=#non-member-types>Non-Member Types</a></li><li><a href=#member-types>Member Types</a></li><li><a href=#member-functions>Member Functions</a><ul><li><a href=#constructors>Constructors</a></li><li><a href=#constructors-comparator-allocator>Constructors (Comparator, Allocator)</a></li><li><a href=#copy-and-move-constructors>Copy and Move Constructors</a></li><li><a href=#constructors-iterator>Constructors (Iterator)</a></li><li><a href=#constructors-stdinitializer_list>Constructors (std::initializer_list)</a></li><li><a href=#copy-and-move-assignment-operators>Copy and Move Assignment Operators</a></li><li><a href=#assignment-operator-stdinitializer_list>Assignment Operator (std::initializer_list)</a></li><li><a href=#destructor>Destructor</a></li><li><a href=#begin-end><code>begin()</code>, <code>end()</code></a></li><li><a href=#empty><code>empty()</code></a></li><li><a href=#size><code>size()</code></a></li><li><a href=#max_size><code>max_size()</code></a></li><li><a href=#clear><code>clear()</code></a></li><li><a href=#push_backkv><code>push_back(kv)</code></a></li><li><a href=#emplace_backk-v><code>emplace_back(k, v)</code></a></li><li><a href=#pop_back><code>pop_back()</code></a></li><li><a href=#insertkv><code>insert(kv)</code></a></li><li><a href=#emplacek-v><code>emplace(k, v)</code></a></li><li><a href=#countk><code>count(k)</code></a></li><li><a href=#containsk><code>contains(k)</code></a></li><li><a href=#findk><code>find(k)</code></a></li><li><a href=#atk><code>at(k)</code></a></li><li><a href=#operatork><code>operator[](k)</code></a></li><li><a href=#erase><code>erase(...)</code></a></li><li><a href=#key_comp><code>key_comp()</code></a></li></ul></li><li><a href=#notes>Notes</a><ul><li><a href=#key-modification>Key Modification</a></li><li><a href=#order-preservation-details>Order Preservation Details</a></li></ul></li><li><a href=#related>Related</a></li></ul></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=ordered_maphpp>ordered_map.hpp
|
||||
<a class=anchor href=#ordered_maphpp>#</a></h1><p>Defines <code>toml::ordered_map</code>, which is used to maintain the order of values in a file.</p><h1 id=class-ordered_map><code>class ordered_map</code>
|
||||
<a class=anchor href=#class-ordered_map>#</a></h1><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> Key, <span style=color:#66d9ef>typename</span> Val, <span style=color:#66d9ef>typename</span> Cmp <span style=color:#f92672>=</span> std<span style=color:#f92672>::</span>equal_to<span style=color:#f92672><</span>Key<span style=color:#f92672>></span>,
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>typename</span> Allocator <span style=color:#f92672>=</span> std<span style=color:#f92672>::</span>allocator<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>pair<span style=color:#f92672><</span>Key, Val<span style=color:#f92672>>>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>class</span> <span style=color:#a6e22e>ordered_map</span>;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>The <code>ordered_map</code> is a <code>map</code> type that preserves the insertion order of values, allowing iteration in that order.</p><p>As a linear container, searches require <code>O(n)</code> time relative to the number of elements.
|
||||
Use this when search operations are infrequent and maintaining the order of values is important.</p><h2 id=non-member-types>Non-Member Types
|
||||
<a class=anchor href=#non-member-types>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>ordered_type_config</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>using</span> ordered_value <span style=color:#f92672>=</span> basic_value<span style=color:#f92672><</span>ordered_type_config<span style=color:#f92672>></span>;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>using</span> ordered_table <span style=color:#f92672>=</span> <span style=color:#66d9ef>typename</span> ordered_value<span style=color:#f92672>::</span>table_type;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>using</span> ordered_array <span style=color:#f92672>=</span> <span style=color:#66d9ef>typename</span> ordered_value<span style=color:#f92672>::</span>array_type;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>Use these in place of <code>toml::type_config</code> and <code>toml::value</code>.</p><blockquote class="book-hint info"><p>Since <code>toml::parse</code> defaults to using <code>type_config</code>, specify</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> input <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>parse<span style=color:#f92672><</span>toml<span style=color:#f92672>::</span>ordered_type_config<span style=color:#f92672>></span>(<span style=color:#e6db74>"input.toml"</span>);
|
||||
</span></span></code></pre></div><p>when parsing.</p></blockquote><h2 id=member-types>Member Types
|
||||
<a class=anchor href=#member-types>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>using</span> key_type <span style=color:#f92672>=</span> Key;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>using</span> mapped_type <span style=color:#f92672>=</span> Val;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>using</span> value_type <span style=color:#f92672>=</span> std<span style=color:#f92672>::</span>pair<span style=color:#f92672><</span>Key, Val<span style=color:#f92672>></span>;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>using</span> key_compare <span style=color:#f92672>=</span> Cmp;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>using</span> allocator_type <span style=color:#f92672>=</span> Allocator;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>using</span> container_type <span style=color:#f92672>=</span> std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>value_type, Allocator<span style=color:#f92672>></span>;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>using</span> reference <span style=color:#f92672>=</span> <span style=color:#66d9ef>typename</span> container_type<span style=color:#f92672>::</span>reference;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>using</span> pointer <span style=color:#f92672>=</span> <span style=color:#66d9ef>typename</span> container_type<span style=color:#f92672>::</span>pointer;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>using</span> const_reference <span style=color:#f92672>=</span> <span style=color:#66d9ef>typename</span> container_type<span style=color:#f92672>::</span>const_reference;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>using</span> const_pointer <span style=color:#f92672>=</span> <span style=color:#66d9ef>typename</span> container_type<span style=color:#f92672>::</span>const_pointer;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>using</span> iterator <span style=color:#f92672>=</span> <span style=color:#66d9ef>typename</span> container_type<span style=color:#f92672>::</span>iterator;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>using</span> const_iterator <span style=color:#f92672>=</span> <span style=color:#66d9ef>typename</span> container_type<span style=color:#f92672>::</span>const_iterator;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>using</span> size_type <span style=color:#f92672>=</span> <span style=color:#66d9ef>typename</span> container_type<span style=color:#f92672>::</span>size_type;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>using</span> difference_type <span style=color:#f92672>=</span> <span style=color:#66d9ef>typename</span> container_type<span style=color:#f92672>::</span>difference_type;
|
||||
</span></span></code></pre></div><h2 id=member-functions>Member Functions
|
||||
<a class=anchor href=#member-functions>#</a></h2><h3 id=constructors>Constructors
|
||||
<a class=anchor href=#constructors>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>ordered_map() <span style=color:#f92672>=</span> <span style=color:#66d9ef>default</span>;
|
||||
</span></span></code></pre></div><p>Constructs an empty <code>ordered_map</code>.</p><h3 id=constructors-comparator-allocator>Constructors (Comparator, Allocator)
|
||||
<a class=anchor href=#constructors-comparator-allocator>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>explicit</span> <span style=color:#a6e22e>ordered_map</span>(<span style=color:#66d9ef>const</span> Cmp<span style=color:#f92672>&</span> cmp, <span style=color:#66d9ef>const</span> Allocator<span style=color:#f92672>&</span> alloc <span style=color:#f92672>=</span> Allocator());
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>explicit</span> <span style=color:#a6e22e>ordered_map</span>(<span style=color:#66d9ef>const</span> Allocator<span style=color:#f92672>&</span> alloc);
|
||||
</span></span></code></pre></div><p>Constructs an <code>ordered_map</code> with a specified comparator for key comparison and an allocator for memory management.</p><h3 id=copy-and-move-constructors>Copy and Move Constructors
|
||||
<a class=anchor href=#copy-and-move-constructors>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>ordered_map(<span style=color:#66d9ef>const</span> ordered_map<span style=color:#f92672>&</span>) <span style=color:#f92672>=</span> <span style=color:#66d9ef>default</span>;
|
||||
</span></span><span style=display:flex><span>ordered_map(ordered_map<span style=color:#f92672>&&</span>) <span style=color:#f92672>=</span> <span style=color:#66d9ef>default</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span>ordered_map(<span style=color:#66d9ef>const</span> ordered_map<span style=color:#f92672>&</span> other, <span style=color:#66d9ef>const</span> Allocator<span style=color:#f92672>&</span> alloc);
|
||||
</span></span><span style=display:flex><span>ordered_map(ordered_map<span style=color:#f92672>&&</span> other, <span style=color:#66d9ef>const</span> Allocator<span style=color:#f92672>&</span> alloc);
|
||||
</span></span></code></pre></div><p>Constructs an <code>ordered_map</code> by copying or moving the contents from another <code>ordered_map</code>.
|
||||
An allocator can also be specified for memory management.</p><h3 id=constructors-iterator>Constructors (Iterator)
|
||||
<a class=anchor href=#constructors-iterator>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> InputIterator<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>ordered_map(InputIterator first, InputIterator last, <span style=color:#66d9ef>const</span> Cmp<span style=color:#f92672>&</span> cmp <span style=color:#f92672>=</span> Cmp(), <span style=color:#66d9ef>const</span> Allocator<span style=color:#f92672>&</span> alloc <span style=color:#f92672>=</span> Allocator());
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> InputIterator<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>ordered_map(InputIterator first, InputIterator last, <span style=color:#66d9ef>const</span> Allocator<span style=color:#f92672>&</span> alloc <span style=color:#f92672>=</span> Allocator());
|
||||
</span></span></code></pre></div><p>Constructs an <code>ordered_map</code> with a range represented by iterators.
|
||||
The order of the elements follows the order of the iterators.</p><h3 id=constructors-stdinitializer_list>Constructors (std::initializer_list)
|
||||
<a class=anchor href=#constructors-stdinitializer_list>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>ordered_map(std<span style=color:#f92672>::</span>initializer_list<span style=color:#f92672><</span>value_type<span style=color:#f92672>></span> v, <span style=color:#66d9ef>const</span> Cmp<span style=color:#f92672>&</span> cmp <span style=color:#f92672>=</span> Cmp(), <span style=color:#66d9ef>const</span> Allocator<span style=color:#f92672>&</span> alloc <span style=color:#f92672>=</span> Allocator());
|
||||
</span></span><span style=display:flex><span>ordered_map(std<span style=color:#f92672>::</span>initializer_list<span style=color:#f92672><</span>value_type<span style=color:#f92672>></span> v, <span style=color:#66d9ef>const</span> Allocator<span style=color:#f92672>&</span> alloc);
|
||||
</span></span></code></pre></div><p>Initializes the <code>ordered_map</code> using an initializer list.</p><h3 id=copy-and-move-assignment-operators>Copy and Move Assignment Operators
|
||||
<a class=anchor href=#copy-and-move-assignment-operators>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>ordered_map<span style=color:#f92672>&</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>=</span>(<span style=color:#66d9ef>const</span> ordered_map<span style=color:#f92672>&</span>) <span style=color:#f92672>=</span> <span style=color:#66d9ef>default</span>;
|
||||
</span></span><span style=display:flex><span>ordered_map<span style=color:#f92672>&</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>=</span>(ordered_map<span style=color:#f92672>&&</span>) <span style=color:#f92672>=</span> <span style=color:#66d9ef>default</span>;
|
||||
</span></span></code></pre></div><p>Assigns the contents of another <code>ordered_map</code> to this one, using copy or move semantics.</p><h3 id=assignment-operator-stdinitializer_list>Assignment Operator (std::initializer_list)
|
||||
<a class=anchor href=#assignment-operator-stdinitializer_list>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>ordered_map<span style=color:#f92672>&</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>=</span>(std<span style=color:#f92672>::</span>initializer_list<span style=color:#f92672><</span>value_type<span style=color:#f92672>></span> v);
|
||||
</span></span></code></pre></div><p>Assigns the contents of an initializer list to the <code>ordered_map</code>.</p><h3 id=destructor>Destructor
|
||||
<a class=anchor href=#destructor>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#f92672>~</span>ordered_map() <span style=color:#f92672>=</span> <span style=color:#66d9ef>default</span>;
|
||||
</span></span></code></pre></div><p>Destroys the <code>ordered_map</code>.</p><h3 id=begin-end><code>begin()</code>, <code>end()</code>
|
||||
<a class=anchor href=#begin-end>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>iterator <span style=color:#a6e22e>begin</span>() <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>iterator <span style=color:#a6e22e>end</span>() <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>const_iterator <span style=color:#a6e22e>begin</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>const_iterator <span style=color:#a6e22e>end</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>const_iterator <span style=color:#a6e22e>cbegin</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>const_iterator <span style=color:#a6e22e>cend</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><p>Returns iterators to the beginning and end of the container, allowing iteration over its contents in order.</p><h3 id=empty><code>empty()</code>
|
||||
<a class=anchor href=#empty>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>bool</span> <span style=color:#a6e22e>empty</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><p>Returns <code>true</code> if the <code>ordered_map</code> is empty, <code>false</code> otherwise.</p><h3 id=size><code>size()</code>
|
||||
<a class=anchor href=#size>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>std<span style=color:#f92672>::</span>size_t size() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><p>Returns the number of elements in the <code>ordered_map</code>.</p><h3 id=max_size><code>max_size()</code>
|
||||
<a class=anchor href=#max_size>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>std<span style=color:#f92672>::</span>size_t max_size() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><p>Returns the maximum number of elements the <code>ordered_map</code> can hold.</p><h3 id=clear><code>clear()</code>
|
||||
<a class=anchor href=#clear>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>void</span> <span style=color:#a6e22e>clear</span>();
|
||||
</span></span></code></pre></div><p>Clears all elements from the <code>ordered_map</code>.</p><h3 id=push_backkv><code>push_back(kv)</code>
|
||||
<a class=anchor href=#push_backkv>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>void</span> <span style=color:#a6e22e>push_back</span>(<span style=color:#66d9ef>const</span> value_type<span style=color:#f92672>&</span>);
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>void</span> <span style=color:#a6e22e>push_back</span>(value_type<span style=color:#f92672>&&</span>);
|
||||
</span></span></code></pre></div><p>Appends a key-value pair to the end of the <code>ordered_map</code>.</p><h3 id=emplace_backk-v><code>emplace_back(k, v)</code>
|
||||
<a class=anchor href=#emplace_backk-v>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>void</span> <span style=color:#a6e22e>emplace_back</span>(key_type, mapped_type);
|
||||
</span></span></code></pre></div><p>Appends a key-value pair to the end of the <code>ordered_map</code> by constructing it in place.</p><h3 id=pop_back><code>pop_back()</code>
|
||||
<a class=anchor href=#pop_back>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>void</span> <span style=color:#a6e22e>pop_back</span>();
|
||||
</span></span></code></pre></div><p>Removes the last element from the <code>ordered_map</code>.</p><h3 id=insertkv><code>insert(kv)</code>
|
||||
<a class=anchor href=#insertkv>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>void</span> <span style=color:#a6e22e>insert</span>(value_type);
|
||||
</span></span></code></pre></div><p>Inserts a key-value pair at the end of the <code>ordered_map</code>.</p><h3 id=emplacek-v><code>emplace(k, v)</code>
|
||||
<a class=anchor href=#emplacek-v>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>void</span> <span style=color:#a6e22e>emplace</span>(key_type, mapped_type);
|
||||
</span></span></code></pre></div><p>Inserts a key-value pair at the end of the <code>ordered_map</code> by constructing it in place.</p><h3 id=countk><code>count(k)</code>
|
||||
<a class=anchor href=#countk>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>std<span style=color:#f92672>::</span>size_t count(<span style=color:#66d9ef>const</span> key_type<span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><p>Returns the number of elements with the specified key.
|
||||
Since duplicate keys are not allowed, this will return either <code>1</code> if the key exists or <code>0</code> if it does not.</p><h3 id=containsk><code>contains(k)</code>
|
||||
<a class=anchor href=#containsk>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>bool</span> <span style=color:#a6e22e>contains</span>(<span style=color:#66d9ef>const</span> key_type<span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><p>Returns <code>true</code> if the <code>ordered_map</code> contains an element with the specified key, <code>false</code> otherwise.</p><h3 id=findk><code>find(k)</code>
|
||||
<a class=anchor href=#findk>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>iterator <span style=color:#a6e22e>find</span>(<span style=color:#66d9ef>const</span> key_type<span style=color:#f92672>&</span> key) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>const_iterator <span style=color:#a6e22e>find</span>(<span style=color:#66d9ef>const</span> key_type<span style=color:#f92672>&</span> key) <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><p>Finds an element with the specified key and returns an iterator to it. If the key is not found, returns <code>end()</code>.</p><h3 id=atk><code>at(k)</code>
|
||||
<a class=anchor href=#atk>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>mapped_type<span style=color:#f92672>&</span> at(<span style=color:#66d9ef>const</span> key_type<span style=color:#f92672>&</span> k);
|
||||
</span></span><span style=display:flex><span>mapped_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> at(<span style=color:#66d9ef>const</span> key_type<span style=color:#f92672>&</span> k) <span style=color:#66d9ef>const</span>;
|
||||
</span></span></code></pre></div><p>Finds an element with the specified key and returns a reference to its value. Throws <code>std::out_of_range</code> if the key is not found.</p><h3 id=operatork><code>operator[](k)</code>
|
||||
<a class=anchor href=#operatork>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>mapped_type<span style=color:#f92672>&</span> <span style=color:#66d9ef>operator</span>[](<span style=color:#66d9ef>const</span> key_type<span style=color:#f92672>&</span> k);
|
||||
</span></span><span style=display:flex><span>mapped_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> <span style=color:#66d9ef>operator</span>[](<span style=color:#66d9ef>const</span> key_type<span style=color:#f92672>&</span> k) <span style=color:#66d9ef>const</span>;
|
||||
</span></span></code></pre></div><p>Finds an element with the specified key and returns a reference to its value.
|
||||
If the key is not found, a new value is constructed and returned.
|
||||
If the <code>ordered_map</code> is <code>const</code>, throws <code>std::out_of_range</code> instead.</p><h3 id=erase><code>erase(...)</code>
|
||||
<a class=anchor href=#erase>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>iterator <span style=color:#a6e22e>erase</span>(iterator pos);
|
||||
</span></span><span style=display:flex><span>iterator <span style=color:#a6e22e>erase</span>(const_iterator pos);
|
||||
</span></span><span style=display:flex><span>iterator <span style=color:#a6e22e>erase</span>(const_iterator first, const_iterator last);
|
||||
</span></span><span style=display:flex><span>size_type <span style=color:#a6e22e>erase</span>(<span style=color:#66d9ef>const</span> key_type<span style=color:#f92672>&</span> key);
|
||||
</span></span></code></pre></div><p>Removes values pointed by an iterator or a value corresponding to a key.</p><h3 id=key_comp><code>key_comp()</code>
|
||||
<a class=anchor href=#key_comp>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>key_compare <span style=color:#a6e22e>key_comp</span>() <span style=color:#66d9ef>const</span>;
|
||||
</span></span></code></pre></div><p>Returns the comparator used for key comparison.</p><h2 id=notes>Notes
|
||||
<a class=anchor href=#notes>#</a></h2><h3 id=key-modification>Key Modification
|
||||
<a class=anchor href=#key-modification>#</a></h3><blockquote class="book-hint warning"><p>Since <code>ordered_map</code> uses <code>std::pair<Key, Val></code> for <code>value_type</code>, it is possible to modify the key through an iterator. However, this practice is not recommended.</p><p>If you modify a key this way and it conflicts with an existing key, one of the conflicting keys will become unsearchable.</p><p>When using <code>operator[]</code>, <code>push_back</code>, or <code>insert</code>, collisions with existing keys are detected.</p></blockquote><h3 id=order-preservation-details>Order Preservation Details
|
||||
<a class=anchor href=#order-preservation-details>#</a></h3><blockquote class="book-hint warning"><p><code>ordered_map</code> maintains the order of keys, but this order preservation applies only to keys defined within the same table. Order across different tables is not maintained.</p><p>For example, the order in the following file will be preserved:</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>apple.type <span style=color:#f92672>=</span> <span style=color:#e6db74>"fruit"</span>
|
||||
</span></span><span style=display:flex><span>apple.skin <span style=color:#f92672>=</span> <span style=color:#e6db74>"thin"</span>
|
||||
</span></span><span style=display:flex><span>apple.color <span style=color:#f92672>=</span> <span style=color:#e6db74>"red"</span>
|
||||
</span></span><span style=display:flex><span>orange.type <span style=color:#f92672>=</span> <span style=color:#e6db74>"fruit"</span>
|
||||
</span></span><span style=display:flex><span>orange.skin <span style=color:#f92672>=</span> <span style=color:#e6db74>"thick"</span>
|
||||
</span></span><span style=display:flex><span>orange.color <span style=color:#f92672>=</span> <span style=color:#e6db74>"orange"</span>
|
||||
</span></span></code></pre></div><p>In contrast, the order in the following file will not be preserved:</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>apple.type <span style=color:#f92672>=</span> <span style=color:#e6db74>"fruit"</span>
|
||||
</span></span><span style=display:flex><span>orange.type <span style=color:#f92672>=</span> <span style=color:#e6db74>"fruit"</span>
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span>apple.skin <span style=color:#f92672>=</span> <span style=color:#e6db74>"thin"</span>
|
||||
</span></span><span style=display:flex><span>orange.skin <span style=color:#f92672>=</span> <span style=color:#e6db74>"thick"</span>
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span>apple.color <span style=color:#f92672>=</span> <span style=color:#e6db74>"red"</span>
|
||||
</span></span><span style=display:flex><span>orange.color <span style=color:#f92672>=</span> <span style=color:#e6db74>"orange"</span>
|
||||
</span></span></code></pre></div><p><code>ordered_map</code> preserves the order of the <code>apple</code> and <code>orange</code> definitions at the root table level, and the order of <code>type</code>, <code>skin</code>, <code>color</code> within each <code>apple</code> and <code>orange</code> table.</p></blockquote><h2 id=related>Related
|
||||
<a class=anchor href=#related>#</a></h2><ul><li><a href=https://toruniina.github.io/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=https://toruniina.github.io/toml11/docs/reference/types/>types.hpp</a></li><li><a href=https://toruniina.github.io/toml11/docs/reference/value/>value.hpp</a></li></ul></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#ordered_maphpp>ordered_map.hpp</a></li><li><a href=#class-ordered_map><code>class ordered_map</code></a><ul><li><a href=#non-member-types>Non-Member Types</a></li><li><a href=#member-types>Member Types</a></li><li><a href=#member-functions>Member Functions</a><ul><li><a href=#constructors>Constructors</a></li><li><a href=#constructors-comparator-allocator>Constructors (Comparator, Allocator)</a></li><li><a href=#copy-and-move-constructors>Copy and Move Constructors</a></li><li><a href=#constructors-iterator>Constructors (Iterator)</a></li><li><a href=#constructors-stdinitializer_list>Constructors (std::initializer_list)</a></li><li><a href=#copy-and-move-assignment-operators>Copy and Move Assignment Operators</a></li><li><a href=#assignment-operator-stdinitializer_list>Assignment Operator (std::initializer_list)</a></li><li><a href=#destructor>Destructor</a></li><li><a href=#begin-end><code>begin()</code>, <code>end()</code></a></li><li><a href=#empty><code>empty()</code></a></li><li><a href=#size><code>size()</code></a></li><li><a href=#max_size><code>max_size()</code></a></li><li><a href=#clear><code>clear()</code></a></li><li><a href=#push_backkv><code>push_back(kv)</code></a></li><li><a href=#emplace_backk-v><code>emplace_back(k, v)</code></a></li><li><a href=#pop_back><code>pop_back()</code></a></li><li><a href=#insertkv><code>insert(kv)</code></a></li><li><a href=#emplacek-v><code>emplace(k, v)</code></a></li><li><a href=#countk><code>count(k)</code></a></li><li><a href=#containsk><code>contains(k)</code></a></li><li><a href=#findk><code>find(k)</code></a></li><li><a href=#atk><code>at(k)</code></a></li><li><a href=#operatork><code>operator[](k)</code></a></li><li><a href=#erase><code>erase(...)</code></a></li><li><a href=#key_comp><code>key_comp()</code></a></li></ul></li><li><a href=#notes>Notes</a><ul><li><a href=#key-modification>Key Modification</a></li><li><a href=#order-preservation-details>Order Preservation Details</a></li></ul></li><li><a href=#related>Related</a></li></ul></li></ul></nav></div></aside></main></body></html>
|
||||
197
docs/reference/parser/index.html
Normal file
197
docs/reference/parser/index.html
Normal file
@@ -0,0 +1,197 @@
|
||||
<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
|
||||
parser.hpp
|
||||
#
|
||||
|
||||
Defines functions for parsing files or strings and the exceptions they use.
|
||||
While parse throws an exception on failure, try_parse returns error information.
|
||||
|
||||
parse
|
||||
#
|
||||
|
||||
Parses the content of a given file and returns a toml::basic_value.
|
||||
In case of failure, toml::syntax_error is thrown.
|
||||
The type information of basic_value is provided by a template, and the TOML language version is specified by toml::spec.
|
||||
|
||||
parse(std::string filename, toml::spec)
|
||||
#
|
||||
|
||||
namespace toml
|
||||
{
|
||||
template<typename TC = type_config>
|
||||
basic_value<TC>
|
||||
parse(std::string fname,
|
||||
spec s = spec::default_version());
|
||||
}
|
||||
Parses the content of the given filename."><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/reference/parser/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="parser.hpp"><meta property="og:description" content="parser.hpp # Defines functions for parsing files or strings and the exceptions they use.
|
||||
While parse throws an exception on failure, try_parse returns error information.
|
||||
parse # Parses the content of a given file and returns a toml::basic_value.
|
||||
In case of failure, toml::syntax_error is thrown.
|
||||
The type information of basic_value is provided by a template, and the TOML language version is specified by toml::spec.
|
||||
parse(std::string filename, toml::spec) # namespace toml { template<typename TC = type_config> basic_value<TC> parse(std::string fname, spec s = spec::default_version()); } Parses the content of the given filename."><meta property="og:locale" content="en"><meta property="og:type" content="article"><meta property="article:section" content="docs"><title>parser.hpp | toml11</title><link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/reference/parser/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/reference/parser/ title=parser.hpp><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" crossorigin=anonymous></script></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
|
||||
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
|
||||
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
|
||||
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/reference/parser/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle>
|
||||
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle checked>
|
||||
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/ class=active>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
|
||||
</label><strong>parser.hpp</strong>
|
||||
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#parserhpp>parser.hpp</a></li><li><a href=#parse><code>parse</code></a><ul><li><ul><li><a href=#parsestdstring-filename-tomlspec><code>parse(std::string filename, toml::spec)</code></a></li><li><a href=#parseconst-char-n-filename-tomlspec><code>parse(const char (&)[N] filename, toml::spec)</code></a></li><li><a href=#parsestdfilesystempath-tomlspec><code>parse(std::filesystem::path, toml::spec)</code></a></li><li><a href=#parsestdistream-stdstring-filename-tomlspec><code>parse(std::istream&, std::string filename, toml::spec)</code></a></li><li><a href=#parsefile-stdstring-filename-tomlspec><code>parse(FILE*, std::string filename, toml::spec)</code></a></li><li><a href=#parsestdvectorunsigned-char-stdstring-filename-tomlspec><code>parse(std::vector<unsigned char>, std::string filename, toml::spec)</code></a></li></ul></li></ul></li><li><a href=#parse_str><code>parse_str</code></a><ul><li><ul><li><a href=#parse_strstdstring-tomlspec><code>parse_str(std::string, toml::spec)</code></a></li></ul></li></ul></li><li><a href=#try_parse><code>try_parse</code></a><ul><li><ul><li><a href=#try_parsestdstring-filename-tomlspec><code>try_parse(std::string filename, toml::spec)</code></a></li><li><a href=#try_parseconst-char-n-filename-tomlspec><code>try_parse(const char (&)[N] filename, toml::spec)</code></a></li><li><a href=#try_parsestdfilesystempath-tomlspec><code>try_parse(std::filesystem::path, toml::spec)</code></a></li><li><a href=#try_parsestdistream-stdstring-filename-tomlspec><code>try_parse(std::istream&, std::string filename, toml::spec)</code></a></li><li><a href=#try_parsefile-stdstring-filename-tomlspec><code>try_parse(FILE*, std::string filename, toml::spec)</code></a></li><li><a href=#try_parsestdvectorunsigned-char-stdstring-filename-tomlspec><code>try_parse(std::vector<unsigned char>, std::string filename, toml::spec)</code></a></li></ul></li></ul></li><li><a href=#try_parse_str><code>try_parse_str</code></a><ul><li><ul><li><a href=#try_parse_strstdstring-tomlspec><code>try_parse_str(std::string, toml::spec)</code></a></li></ul></li></ul></li><li><a href=#syntax_error><code>syntax_error</code></a></li><li><a href=#file_io_error><code>file_io_error</code></a><ul><li><ul><li><a href=#has_errno><code>has_errno</code></a></li><li><a href=#get_errno><code>get_errno</code></a></li></ul></li></ul></li><li><a href=#related>Related</a></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=parserhpp>parser.hpp
|
||||
<a class=anchor href=#parserhpp>#</a></h1><p>Defines functions for parsing files or strings and the exceptions they use.</p><p>While <code>parse</code> throws an exception on failure, <code>try_parse</code> returns error information.</p><h1 id=parse><code>parse</code>
|
||||
<a class=anchor href=#parse>#</a></h1><p>Parses the content of a given file and returns a <code>toml::basic_value</code>.</p><p>In case of failure, <code>toml::syntax_error</code> is thrown.</p><p>The type information of <code>basic_value</code> is provided by a <code>template</code>, and the TOML language version is specified by <code>toml::spec</code>.</p><h3 id=parsestdstring-filename-tomlspec><code>parse(std::string filename, toml::spec)</code>
|
||||
<a class=anchor href=#parsestdstring-filename-tomlspec>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC <span style=color:#f92672>=</span> type_config<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>parse(std<span style=color:#f92672>::</span>string fname,
|
||||
</span></span><span style=display:flex><span> spec s <span style=color:#f92672>=</span> spec<span style=color:#f92672>::</span>default_version());
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>Parses the content of the given filename.</p><p>If reading the file fails, <code>toml::file_io_error</code> is thrown.</p><p>If parsing fails, <code>toml::syntax_error</code> is thrown.</p><h3 id=parseconst-char-n-filename-tomlspec><code>parse(const char (&)[N] filename, toml::spec)</code>
|
||||
<a class=anchor href=#parseconst-char-n-filename-tomlspec>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC <span style=color:#f92672>=</span> type_config, std<span style=color:#f92672>::</span>size_t N<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>parse(<span style=color:#66d9ef>const</span> <span style=color:#66d9ef>char</span> (<span style=color:#f92672>&</span>fname)[N],
|
||||
</span></span><span style=display:flex><span> spec s <span style=color:#f92672>=</span> spec<span style=color:#f92672>::</span>default_version());
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>Parses the content of the given filename from a string literal.</p><p>If reading the file fails, <code>toml::file_io_error</code> is thrown.</p><p>If parsing fails, <code>toml::syntax_error</code> is thrown.</p><h3 id=parsestdfilesystempath-tomlspec><code>parse(std::filesystem::path, toml::spec)</code>
|
||||
<a class=anchor href=#parsestdfilesystempath-tomlspec>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC <span style=color:#f92672>=</span> type_config<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>parse(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>filesystem<span style=color:#f92672>::</span>path<span style=color:#f92672>&</span> fpath,
|
||||
</span></span><span style=display:flex><span> spec s <span style=color:#f92672>=</span> spec<span style=color:#f92672>::</span>default_version());
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>This is defined only if <code><filesystem></code> is available.</p><p>Parses the content of the file at the given file path.</p><p>If reading the file fails, <code>toml::file_io_error</code> is thrown.</p><p>If parsing fails, <code>toml::syntax_error</code> is thrown.</p><h3 id=parsestdistream-stdstring-filename-tomlspec><code>parse(std::istream&, std::string filename, toml::spec)</code>
|
||||
<a class=anchor href=#parsestdistream-stdstring-filename-tomlspec>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC <span style=color:#f92672>=</span> type_config<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>parse(std<span style=color:#f92672>::</span>istream<span style=color:#f92672>&</span> is,
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string fname <span style=color:#f92672>=</span> <span style=color:#e6db74>"unknown file"</span>,
|
||||
</span></span><span style=display:flex><span> spec s <span style=color:#f92672>=</span> spec<span style=color:#f92672>::</span>default_version());
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>Parses the content of the given <code>std::istream&</code>.</p><p>Open a stream in binary mode by passing <code>std::ios::binary</code> to avoid inconsistency between the file size and the number of characters due to automatic conversion of newline characters by the standard library.</p><p>The filename information is taken as the second argument. If the filename is not provided, it defaults to <code>"unknown file"</code>.</p><h3 id=parsefile-stdstring-filename-tomlspec><code>parse(FILE*, std::string filename, toml::spec)</code>
|
||||
<a class=anchor href=#parsefile-stdstring-filename-tomlspec>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC <span style=color:#f92672>=</span> type_config<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>result<span style=color:#f92672><</span>basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>></span>, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>error_info<span style=color:#f92672>>></span>
|
||||
</span></span><span style=display:flex><span>parse(FILE<span style=color:#f92672>*</span> fp,
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string filename,
|
||||
</span></span><span style=display:flex><span> spec s <span style=color:#f92672>=</span> spec<span style=color:#f92672>::</span>default_version());
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>Parses the content of the file pointed to by <code>FILE*</code>.</p><p>Open a stream in binary mode by passing <code>"rb"</code> to avoid inconsistency between the file size and the number of characters due to automatic conversion of newline characters by the standard library.</p><p>If reading the file fails, <code>file_io_error</code> containing <code>errno</code> is thrown.</p><p>If parsing fails, <code>syntax_error</code> is thrown.</p><h3 id=parsestdvectorunsigned-char-stdstring-filename-tomlspec><code>parse(std::vector<unsigned char>, std::string filename, toml::spec)</code>
|
||||
<a class=anchor href=#parsestdvectorunsigned-char-stdstring-filename-tomlspec>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC <span style=color:#f92672>=</span> type_config<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>parse(std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span><span style=color:#66d9ef>unsigned</span> <span style=color:#66d9ef>char</span><span style=color:#f92672>></span> content,
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string filename,
|
||||
</span></span><span style=display:flex><span> spec s <span style=color:#f92672>=</span> spec<span style=color:#f92672>::</span>default_version());
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>Parses the byte sequence as a TOML file.</p><p>If parsing fails, <code>toml::syntax_error</code> is thrown.</p><h1 id=parse_str><code>parse_str</code>
|
||||
<a class=anchor href=#parse_str>#</a></h1><h3 id=parse_strstdstring-tomlspec><code>parse_str(std::string, toml::spec)</code>
|
||||
<a class=anchor href=#parse_strstdstring-tomlspec>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC <span style=color:#f92672>=</span> type_config<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>parse_str(std<span style=color:#f92672>::</span>string content,
|
||||
</span></span><span style=display:flex><span> spec s <span style=color:#f92672>=</span> spec<span style=color:#f92672>::</span>default_version(),
|
||||
</span></span><span style=display:flex><span> cxx<span style=color:#f92672>::</span>source_location loc <span style=color:#f92672>=</span> cxx<span style=color:#f92672>::</span>source_location<span style=color:#f92672>::</span>current());
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>Parses a string as a TOML file.</p><p>In case of failure, <code>toml::syntax_error</code> is thrown.</p><p>The type information of <code>basic_value</code> is provided by a <code>template</code>, and the TOML language version is specified by <code>toml::spec</code>.</p><p>You generally don’t need to manually set the third argument, <code>cxx::source_location</code>.
|
||||
If <code>std::source_location</code>, <code>std::experimental::source_location</code>, or <code>__builtin_FILE</code> is available,
|
||||
the location information where <code>parse_str</code> was called will be stored.</p><h1 id=try_parse><code>try_parse</code>
|
||||
<a class=anchor href=#try_parse>#</a></h1><p>Parses the contents of the given file and returns a <code>toml::basic_value</code> if successful, or a <code>std::vector<toml::error_info></code> if it fails.</p><p>The type information of <code>basic_value</code> is specified by <code>template</code>, and the version of the TOML language is specified by <code>toml::spec</code>.</p><blockquote class="book-hint warning"><p>Unlike <code>parse</code>, <code>try_parse</code> does not throw exceptions defined in toml11 such as <code>syntax_error</code>.
|
||||
However, please note that exceptions thrown by the standard library will still propagate.</p><p>For instance, errors occurring internally within <code>std::ifstream</code> or memory exhaustion in <code>std::vector</code> will throw exceptions.</p></blockquote><h3 id=try_parsestdstring-filename-tomlspec><code>try_parse(std::string filename, toml::spec)</code>
|
||||
<a class=anchor href=#try_parsestdstring-filename-tomlspec>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC <span style=color:#f92672>=</span> type_config<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>result<span style=color:#f92672><</span>basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>></span>, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>error_info<span style=color:#f92672>>></span>
|
||||
</span></span><span style=display:flex><span>try_parse(std<span style=color:#f92672>::</span>string fname,
|
||||
</span></span><span style=display:flex><span> spec s <span style=color:#f92672>=</span> spec<span style=color:#f92672>::</span>default_version());
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>Takes a file name and parses its content.</p><p>If parsing fails, a <code>result</code> holding the error type <code>std::vector<error_info></code> is returned.</p><p>If successful, a <code>result</code> holding a <code>basic_value</code> is returned.</p><h3 id=try_parseconst-char-n-filename-tomlspec><code>try_parse(const char (&)[N] filename, toml::spec)</code>
|
||||
<a class=anchor href=#try_parseconst-char-n-filename-tomlspec>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC <span style=color:#f92672>=</span> type_config, std<span style=color:#f92672>::</span>size_t N<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>result<span style=color:#f92672><</span>basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>></span>, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>error_info<span style=color:#f92672>>></span>
|
||||
</span></span><span style=display:flex><span>try_parse(<span style=color:#66d9ef>const</span> <span style=color:#66d9ef>char</span> (<span style=color:#f92672>&</span>fname)[N],
|
||||
</span></span><span style=display:flex><span> spec s <span style=color:#f92672>=</span> spec<span style=color:#f92672>::</span>default_version());
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>Takes a string literal as a file name and parses its content.</p><p>If parsing fails, a <code>result</code> holding the error type <code>std::vector<error_info></code> is returned.</p><p>If successful, a <code>result</code> holding a <code>basic_value</code> is returned.</p><h3 id=try_parsestdfilesystempath-tomlspec><code>try_parse(std::filesystem::path, toml::spec)</code>
|
||||
<a class=anchor href=#try_parsestdfilesystempath-tomlspec>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC <span style=color:#f92672>=</span> type_config<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>result<span style=color:#f92672><</span>basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>></span>, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>error_info<span style=color:#f92672>>></span>
|
||||
</span></span><span style=display:flex><span>try_parse(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>filesystem<span style=color:#f92672>::</span>path<span style=color:#f92672>&</span> fpath,
|
||||
</span></span><span style=display:flex><span> spec s <span style=color:#f92672>=</span> spec<span style=color:#f92672>::</span>default_version());
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>Takes a file path and parses its content.</p><p>If parsing fails, a <code>result</code> holding the error type <code>std::vector<error_info></code> is returned.</p><p>If successful, a <code>result</code> holding a <code>basic_value</code> is returned.</p><h3 id=try_parsestdistream-stdstring-filename-tomlspec><code>try_parse(std::istream&, std::string filename, toml::spec)</code>
|
||||
<a class=anchor href=#try_parsestdistream-stdstring-filename-tomlspec>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC <span style=color:#f92672>=</span> type_config<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>result<span style=color:#f92672><</span>basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>></span>, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>error_info<span style=color:#f92672>>></span>
|
||||
</span></span><span style=display:flex><span>try_parse(std<span style=color:#f92672>::</span>istream<span style=color:#f92672>&</span> is,
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string fname <span style=color:#f92672>=</span> <span style=color:#e6db74>"unknown file"</span>,
|
||||
</span></span><span style=display:flex><span> spec s <span style=color:#f92672>=</span> spec<span style=color:#f92672>::</span>default_version());
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>Takes a <code>std::istream&</code> and parses its content.</p><p>Open a stream in binary mode by passing <code>std::ios::binary</code> to avoid inconsistency between the file size and the number of characters due to automatic conversion of newline characters by the standard library.</p><p>The file name information is taken as the second argument. If a file name is not provided, it defaults to <code>"unknown file"</code>.</p><p>If parsing fails, a <code>result</code> holding the error type <code>std::vector<error_info></code> is returned.</p><p>If successful, a <code>result</code> holding a <code>basic_value</code> is returned.</p><h3 id=try_parsefile-stdstring-filename-tomlspec><code>try_parse(FILE*, std::string filename, toml::spec)</code>
|
||||
<a class=anchor href=#try_parsefile-stdstring-filename-tomlspec>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC <span style=color:#f92672>=</span> type_config<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>result<span style=color:#f92672><</span>basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>></span>, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>error_info<span style=color:#f92672>>></span>
|
||||
</span></span><span style=display:flex><span>try_parse(FILE<span style=color:#f92672>*</span> fp,
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string filename,
|
||||
</span></span><span style=display:flex><span> spec s <span style=color:#f92672>=</span> spec<span style=color:#f92672>::</span>default_version());
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>Takes a <code>FILE*</code> and parses its content.</p><p>Open a stream in binary mode by passing <code>"rb"</code> to avoid inconsistency between the file size and the number of characters due to automatic conversion of newline characters by the standard library.</p><p>If parsing fails, a <code>result</code> holding the error type <code>std::vector<error_info></code> is returned.</p><p>If successful, a <code>result</code> holding a <code>basic_value</code> is returned.</p><h3 id=try_parsestdvectorunsigned-char-stdstring-filename-tomlspec><code>try_parse(std::vector<unsigned char>, std::string filename, toml::spec)</code>
|
||||
<a class=anchor href=#try_parsestdvectorunsigned-char-stdstring-filename-tomlspec>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC <span style=color:#f92672>=</span> type_config<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>result<span style=color:#f92672><</span>basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>></span>, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>error_info<span style=color:#f92672>>></span>
|
||||
</span></span><span style=display:flex><span>try_parse(std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span><span style=color:#66d9ef>unsigned</span> <span style=color:#66d9ef>char</span><span style=color:#f92672>></span> content,
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string filename,
|
||||
</span></span><span style=display:flex><span> spec s <span style=color:#f92672>=</span> spec<span style=color:#f92672>::</span>default_version());
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>Takes a byte array and parses its content as a TOML file.</p><p>If parsing fails, a <code>result</code> holding the error type <code>std::vector<error_info></code> is returned.</p><p>If successful, a <code>result</code> holding a <code>basic_value</code> is returned.</p><h1 id=try_parse_str><code>try_parse_str</code>
|
||||
<a class=anchor href=#try_parse_str>#</a></h1><h3 id=try_parse_strstdstring-tomlspec><code>try_parse_str(std::string, toml::spec)</code>
|
||||
<a class=anchor href=#try_parse_strstdstring-tomlspec>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC <span style=color:#f92672>=</span> type_config<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>result<span style=color:#f92672><</span>basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>></span>, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>error_info<span style=color:#f92672>>></span>
|
||||
</span></span><span style=display:flex><span>try_parse_str(std<span style=color:#f92672>::</span>string content,
|
||||
</span></span><span style=display:flex><span> spec s <span style=color:#f92672>=</span> spec<span style=color:#f92672>::</span>default_version(),
|
||||
</span></span><span style=display:flex><span> cxx<span style=color:#f92672>::</span>source_location loc <span style=color:#f92672>=</span> cxx<span style=color:#f92672>::</span>source_location<span style=color:#f92672>::</span>current());
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>Parses a string as a TOML file, returning a <code>toml::basic_value</code> if successful, or a <code>std::vector<toml::error_info></code> if it fails.</p><p>Unlike <code>parse_str</code>, it does not throw <code>syntax_error</code>, but instead returns error information as the failure type of the <code>result</code>.</p><p>If <code>std::source_location</code>, <code>std::experimental::source_location</code>, or <code>__builtin_FILE</code> is available, it will record the location information.</p><p>Typically, you do not need to manually set the third argument <code>cxx::source_location</code>. If any of <code>std::source_location</code>, <code>std::experimental::source_location</code>, or <code>__builtin_FILE</code> are available, the information of the location where <code>parse_str</code> was called will be saved as the location information.</p><blockquote class="book-hint warning"><p>Unlike <code>parse</code>, <code>try_parse</code> does not throw exceptions defined in toml11 such as <code>syntax_error</code>. However, please note that exceptions thrown by the standard library will still propagate.</p><p>For instance, errors occurring internally within <code>std::ifstream</code> or memory exhaustion in <code>std::vector</code> will throw exceptions.</p></blockquote><h1 id=syntax_error><code>syntax_error</code>
|
||||
<a class=anchor href=#syntax_error>#</a></h1><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>syntax_error</span> <span style=color:#66d9ef>final</span> <span style=color:#f92672>:</span> <span style=color:#66d9ef>public</span> <span style=color:#f92672>::</span>toml<span style=color:#f92672>::</span>exception
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>public</span><span style=color:#f92672>:</span>
|
||||
</span></span><span style=display:flex><span> syntax_error(std<span style=color:#f92672>::</span>string what_arg, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>error_info<span style=color:#f92672>></span> err);
|
||||
</span></span><span style=display:flex><span> <span style=color:#f92672>~</span>syntax_error() <span style=color:#66d9ef>noexcept</span> <span style=color:#66d9ef>override</span> <span style=color:#f92672>=</span> <span style=color:#66d9ef>default</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>char</span><span style=color:#f92672>*</span> <span style=color:#a6e22e>what</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span> <span style=color:#66d9ef>override</span>;
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>error_info<span style=color:#f92672>></span> <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> errors() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>An exception thrown when a syntax error is detected in TOML.</p><p>It is thrown by <code>parse</code> but not by <code>try_parse</code>.</p><h1 id=file_io_error><code>file_io_error</code>
|
||||
<a class=anchor href=#file_io_error>#</a></h1><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>file_io_error</span> <span style=color:#66d9ef>final</span> <span style=color:#f92672>:</span> <span style=color:#66d9ef>public</span> <span style=color:#f92672>::</span>toml<span style=color:#f92672>::</span>exception
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>public</span><span style=color:#f92672>:</span>
|
||||
</span></span><span style=display:flex><span> file_io_error(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> msg, <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> fname);
|
||||
</span></span><span style=display:flex><span> file_io_error(<span style=color:#66d9ef>int</span> errnum, <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> msg, <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> fname);
|
||||
</span></span><span style=display:flex><span> <span style=color:#f92672>~</span>file_io_error() <span style=color:#66d9ef>noexcept</span> <span style=color:#66d9ef>override</span> <span style=color:#f92672>=</span> <span style=color:#66d9ef>default</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>char</span><span style=color:#f92672>*</span> <span style=color:#a6e22e>what</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span> <span style=color:#66d9ef>override</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>bool</span> <span style=color:#a6e22e>has_errno</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>int</span> <span style=color:#a6e22e>get_errno</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>An exception thrown when reading the contents of a file fails.</p><p>When using <code>FILE*</code> to read a file, <code>errno</code> is set.</p><h3 id=has_errno><code>has_errno</code>
|
||||
<a class=anchor href=#has_errno>#</a></h3><p>If <code>std::ifstream</code> fails, <code>errno</code> is not set.</p><p>In this case, <code>has_errno</code> returns <code>false</code>.</p><h3 id=get_errno><code>get_errno</code>
|
||||
<a class=anchor href=#get_errno>#</a></h3><p>Particularly when passing a <code>FILE*</code>, retrieves the value of <code>errno</code>.</p><p>If <code>has_errno</code> is <code>false</code>, it returns <code>0</code>.</p><h1 id=related>Related
|
||||
<a class=anchor href=#related>#</a></h1><ul><li><a href=https://toruniina.github.io/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=https://toruniina.github.io/toml11/docs/reference/result/>result.hpp</a></li><li><a href=https://toruniina.github.io/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=https://toruniina.github.io/toml11/docs/reference/value/>value.hpp</a></li></ul></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#parserhpp>parser.hpp</a></li><li><a href=#parse><code>parse</code></a><ul><li><ul><li><a href=#parsestdstring-filename-tomlspec><code>parse(std::string filename, toml::spec)</code></a></li><li><a href=#parseconst-char-n-filename-tomlspec><code>parse(const char (&)[N] filename, toml::spec)</code></a></li><li><a href=#parsestdfilesystempath-tomlspec><code>parse(std::filesystem::path, toml::spec)</code></a></li><li><a href=#parsestdistream-stdstring-filename-tomlspec><code>parse(std::istream&, std::string filename, toml::spec)</code></a></li><li><a href=#parsefile-stdstring-filename-tomlspec><code>parse(FILE*, std::string filename, toml::spec)</code></a></li><li><a href=#parsestdvectorunsigned-char-stdstring-filename-tomlspec><code>parse(std::vector<unsigned char>, std::string filename, toml::spec)</code></a></li></ul></li></ul></li><li><a href=#parse_str><code>parse_str</code></a><ul><li><ul><li><a href=#parse_strstdstring-tomlspec><code>parse_str(std::string, toml::spec)</code></a></li></ul></li></ul></li><li><a href=#try_parse><code>try_parse</code></a><ul><li><ul><li><a href=#try_parsestdstring-filename-tomlspec><code>try_parse(std::string filename, toml::spec)</code></a></li><li><a href=#try_parseconst-char-n-filename-tomlspec><code>try_parse(const char (&)[N] filename, toml::spec)</code></a></li><li><a href=#try_parsestdfilesystempath-tomlspec><code>try_parse(std::filesystem::path, toml::spec)</code></a></li><li><a href=#try_parsestdistream-stdstring-filename-tomlspec><code>try_parse(std::istream&, std::string filename, toml::spec)</code></a></li><li><a href=#try_parsefile-stdstring-filename-tomlspec><code>try_parse(FILE*, std::string filename, toml::spec)</code></a></li><li><a href=#try_parsestdvectorunsigned-char-stdstring-filename-tomlspec><code>try_parse(std::vector<unsigned char>, std::string filename, toml::spec)</code></a></li></ul></li></ul></li><li><a href=#try_parse_str><code>try_parse_str</code></a><ul><li><ul><li><a href=#try_parse_strstdstring-tomlspec><code>try_parse_str(std::string, toml::spec)</code></a></li></ul></li></ul></li><li><a href=#syntax_error><code>syntax_error</code></a></li><li><a href=#file_io_error><code>file_io_error</code></a><ul><li><ul><li><a href=#has_errno><code>has_errno</code></a></li><li><a href=#get_errno><code>get_errno</code></a></li></ul></li></ul></li><li><a href=#related>Related</a></li></ul></nav></div></aside></main></body></html>
|
||||
313
docs/reference/result/index.html
Normal file
313
docs/reference/result/index.html
Normal file
@@ -0,0 +1,313 @@
|
||||
<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
|
||||
result.hpp
|
||||
#
|
||||
|
||||
result.hpp defines the result type, which can hold either a success value or a failure value.
|
||||
This is used as the return type for toml::try_parse, which does not throw exceptions.
|
||||
|
||||
success
|
||||
#
|
||||
|
||||
A type that holds a success value.
|
||||
namespace toml
|
||||
{
|
||||
template<typename T>
|
||||
struct success
|
||||
{
|
||||
using value_type = T;
|
||||
|
||||
explicit success(value_type v);
|
||||
|
||||
~success() = default;
|
||||
success(const success&) = default;
|
||||
success(success&&) = default;
|
||||
success& operator=(const success&) = default;
|
||||
success& operator=(success&&) = default;
|
||||
|
||||
template<typename U>
|
||||
explicit success(U&& v);
|
||||
template<typename U>
|
||||
explicit success(success<U> v);
|
||||
|
||||
value_type& get() noexcept;
|
||||
value_type const& get() const noexcept;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
success<typename std::decay<T>::type> ok(T&& v);
|
||||
template<std::size_t N>
|
||||
success<std::string> ok(const char (&literal)[N])
|
||||
}
|
||||
|
||||
Member Types
|
||||
#
|
||||
|
||||
using value_type = T;
|
||||
The type of the success value."><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/reference/result/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="result.hpp"><meta property="og:description" content="result.hpp # result.hpp defines the result type, which can hold either a success value or a failure value.
|
||||
This is used as the return type for toml::try_parse, which does not throw exceptions.
|
||||
success # A type that holds a success value.
|
||||
namespace toml { template<typename T> struct success { using value_type = T; explicit success(value_type v); ~success() = default; success(const success&) = default; success(success&&) = default; success& operator=(const success&) = default; success& operator=(success&&) = default; template<typename U> explicit success(U&& v); template<typename U> explicit success(success<U> v); value_type& get() noexcept; value_type const& get() const noexcept; }; template<typename T> success<typename std::decay<T>::type> ok(T&& v); template<std::size_t N> success<std::string> ok(const char (&literal)[N]) } Member Types # using value_type = T; The type of the success value."><meta property="og:locale" content="en"><meta property="og:type" content="article"><meta property="article:section" content="docs"><title>result.hpp | toml11</title><link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/reference/result/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/reference/result/ title=result.hpp><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" crossorigin=anonymous></script></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
|
||||
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
|
||||
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
|
||||
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/reference/result/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle>
|
||||
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle checked>
|
||||
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/ class=active>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
|
||||
</label><strong>result.hpp</strong>
|
||||
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#resulthpp>result.hpp</a></li><li><a href=#success>success</a><ul><li><a href=#member-types>Member Types</a></li><li><a href=#member-functions>Member Functions</a><ul><li><a href=#constructor>Constructor</a></li><li><a href=#get><code>get()</code></a></li></ul></li><li><a href=#non-member-functions>Non-Member Functions</a><ul><li><a href=#okt><code>ok(T)</code></a></li></ul></li></ul></li><li><a href=#successreference_wrappert><code>success<reference_wrapper<T>></code></a><ul><li><a href=#member-types-1>Member Types</a><ul><li><a href=#get-1><code>get()</code></a></li></ul></li></ul></li><li><a href=#failure>failure</a><ul><li><a href=#member-types-2>Member Types</a></li><li><a href=#member-functions-1>Member Functions</a><ul><li><a href=#constructor-1>Constructor</a></li><li><a href=#get-2><code>get()</code></a></li></ul></li><li><a href=#non-member-functions-1>Non-Member Functions</a><ul><li><a href=#errt><code>err(T)</code></a></li></ul></li></ul></li><li><a href=#failurereference_wrappert><code>failure<reference_wrapper<T>></code></a><ul><li><a href=#member-types-3>Member Types</a><ul><li><a href=#get-3><code>get()</code></a></li></ul></li></ul></li><li><a href=#result>result</a><ul><li><a href=#member-types-4>Member Types</a><ul><li><a href=#success_type><code>success_type</code></a></li><li><a href=#failure_type><code>failure_type</code></a></li><li><a href=#value_type><code>value_type</code></a></li><li><a href=#error_type><code>error_type</code></a></li></ul></li><li><a href=#member-functions-2>Member Functions</a><ul><li><a href=#constructor-2>Constructor</a></li><li><a href=#copy-and-move-constructors>Copy and Move Constructors</a></li><li><a href=#operator><code>operator=</code></a></li><li><a href=#is_ok><code>is_ok()</code></a></li><li><a href=#is_err><code>is_err()</code></a></li><li><a href=#operator-bool><code>operator bool()</code></a></li><li><a href=#unwrap><code>unwrap()</code></a></li><li><a href=#unwrap_or><code>unwrap_or()</code></a></li><li><a href=#unwrap_err><code>unwrap_err()</code></a></li><li><a href=#as_ok><code>as_ok()</code></a></li><li><a href=#as_err><code>as_err()</code></a></li></ul></li></ul></li><li><a href=#bad_result_access>bad_result_access</a></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=resulthpp>result.hpp
|
||||
<a class=anchor href=#resulthpp>#</a></h1><p><code>result.hpp</code> defines the <code>result</code> type, which can hold either a success value or a failure value.</p><p>This is used as the return type for <code>toml::try_parse</code>, which does not throw exceptions.</p><h1 id=success>success
|
||||
<a class=anchor href=#success>#</a></h1><p>A type that holds a success value.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>success</span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> value_type <span style=color:#f92672>=</span> T;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>explicit</span> <span style=color:#a6e22e>success</span>(value_type v);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#f92672>~</span>success() <span style=color:#f92672>=</span> <span style=color:#66d9ef>default</span>;
|
||||
</span></span><span style=display:flex><span> success(<span style=color:#66d9ef>const</span> success<span style=color:#f92672>&</span>) <span style=color:#f92672>=</span> <span style=color:#66d9ef>default</span>;
|
||||
</span></span><span style=display:flex><span> success(success<span style=color:#f92672>&&</span>) <span style=color:#f92672>=</span> <span style=color:#66d9ef>default</span>;
|
||||
</span></span><span style=display:flex><span> success<span style=color:#f92672>&</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>=</span>(<span style=color:#66d9ef>const</span> success<span style=color:#f92672>&</span>) <span style=color:#f92672>=</span> <span style=color:#66d9ef>default</span>;
|
||||
</span></span><span style=display:flex><span> success<span style=color:#f92672>&</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>=</span>(success<span style=color:#f92672>&&</span>) <span style=color:#f92672>=</span> <span style=color:#66d9ef>default</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> U<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>explicit</span> success(U<span style=color:#f92672>&&</span> v);
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> U<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>explicit</span> success(success<span style=color:#f92672><</span>U<span style=color:#f92672>></span> v);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> value_type<span style=color:#f92672>&</span> get() <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span> value_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> get() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>success<span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> std<span style=color:#f92672>::</span>decay<span style=color:#f92672><</span>T<span style=color:#f92672>>::</span>type<span style=color:#f92672>></span> ok(T<span style=color:#f92672>&&</span> v);
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span>std<span style=color:#f92672>::</span>size_t N<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>success<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> ok(<span style=color:#66d9ef>const</span> <span style=color:#66d9ef>char</span> (<span style=color:#f92672>&</span>literal)[N])
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><h2 id=member-types>Member Types
|
||||
<a class=anchor href=#member-types>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>using</span> value_type <span style=color:#f92672>=</span> T;
|
||||
</span></span></code></pre></div><p>The type of the success value.</p><h2 id=member-functions>Member Functions
|
||||
<a class=anchor href=#member-functions>#</a></h2><h3 id=constructor>Constructor
|
||||
<a class=anchor href=#constructor>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>explicit</span> <span style=color:#a6e22e>success</span>(value_type v);
|
||||
</span></span></code></pre></div><p>Constructs with a <code>value_type</code> argument.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> U<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>explicit</span> success(U<span style=color:#f92672>&&</span> v);
|
||||
</span></span></code></pre></div><p>Constructs with another type that can be converted to <code>value_type</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> U<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>explicit</span> success(success<span style=color:#f92672><</span>U<span style=color:#f92672>></span> v);
|
||||
</span></span></code></pre></div><p>Constructs with another <code>success</code> type that can be converted to <code>value_type</code>.</p><h3 id=get><code>get()</code>
|
||||
<a class=anchor href=#get>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>value_type<span style=color:#f92672>&</span> get() <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>value_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> get() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><p>Accesses the stored value.</p><h2 id=non-member-functions>Non-Member Functions
|
||||
<a class=anchor href=#non-member-functions>#</a></h2><h3 id=okt><code>ok(T)</code>
|
||||
<a class=anchor href=#okt>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>success<span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> std<span style=color:#f92672>::</span>decay<span style=color:#f92672><</span>T<span style=color:#f92672>>::</span>type<span style=color:#f92672>></span> ok(T<span style=color:#f92672>&&</span> v);
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span>std<span style=color:#f92672>::</span>size_t N<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>success<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> ok(<span style=color:#66d9ef>const</span> <span style=color:#66d9ef>char</span> (<span style=color:#f92672>&</span>literal)[N]);
|
||||
</span></span></code></pre></div><p>Constructs and returns a <code>success</code> type from a success value.</p><p>Converts a string literal into <code>std::string</code>.</p><h1 id=successreference_wrappert><code>success<reference_wrapper<T>></code>
|
||||
<a class=anchor href=#successreference_wrappert>#</a></h1><p>Specialization of <code>success</code> for when the success value is a reference.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>success</span><span style=color:#f92672><</span>std<span style=color:#f92672>::</span>reference_wrapper<span style=color:#f92672><</span>T<span style=color:#f92672>>></span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> value_type <span style=color:#f92672>=</span> T;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>explicit</span> <span style=color:#a6e22e>success</span>(std<span style=color:#f92672>::</span>reference_wrapper<span style=color:#f92672><</span>value_type<span style=color:#f92672>></span> v) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> value_type<span style=color:#f92672>&</span> get() <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span> value_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> get() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><h2 id=member-types-1>Member Types
|
||||
<a class=anchor href=#member-types-1>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>using</span> value_type <span style=color:#f92672>=</span> T;
|
||||
</span></span></code></pre></div><p>The type of the success value. It is <code>T</code> from <code>std::reference_wrapper<T></code>, not the reference itself.</p><h3 id=get-1><code>get()</code>
|
||||
<a class=anchor href=#get-1>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>value_type<span style=color:#f92672>&</span> get() <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>value_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> get() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><p>Accesses the stored value.</p><h1 id=failure>failure
|
||||
<a class=anchor href=#failure>#</a></h1><p>A type that holds a failure value.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>failure</span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> value_type <span style=color:#f92672>=</span> T;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>explicit</span> <span style=color:#a6e22e>failure</span>(value_type v);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#f92672>~</span>failure() <span style=color:#f92672>=</span> <span style=color:#66d9ef>default</span>;
|
||||
</span></span><span style=display:flex><span> failure(<span style=color:#66d9ef>const</span> failure<span style=color:#f92672>&</span>) <span style=color:#f92672>=</span> <span style=color:#66d9ef>default</span>;
|
||||
</span></span><span style=display:flex><span> failure(failure<span style=color:#f92672>&&</span>) <span style=color:#f92672>=</span> <span style=color:#66d9ef>default</span>;
|
||||
</span></span><span style=display:flex><span> failure<span style=color:#f92672>&</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>=</span>(<span style=color:#66d9ef>const</span> failure<span style=color:#f92672>&</span>) <span style=color:#f92672>=</span> <span style=color:#66d9ef>default</span>;
|
||||
</span></span><span style=display:flex><span> failure<span style=color:#f92672>&</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>=</span>(failure<span style=color:#f92672>&&</span>) <span style=color:#f92672>=</span> <span style=color:#66d9ef>default</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> U<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>explicit</span> failure(U<span style=color:#f92672>&&</span> v);
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> U<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>explicit</span> failure(failure<span style=color:#f92672><</span>U<span style=color:#f92672>></span> v);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> value_type<span style=color:#f92672>&</span> get() <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span> value_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> get() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>failure<span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> std<span style=color:#f92672>::</span>decay<span style=color:#f92672><</span>T<span style=color:#f92672>>::</span>type<span style=color:#f92672>></span> err(T<span style=color:#f92672>&&</span> v);
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span>std<span style=color:#f92672>::</span>size_t N<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>failure<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> err(<span style=color:#66d9ef>const</span> <span style=color:#66d9ef>char</span> (<span style=color:#f92672>&</span>literal)[N]);
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><h2 id=member-types-2>Member Types
|
||||
<a class=anchor href=#member-types-2>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>using</span> value_type <span style=color:#f92672>=</span> T;
|
||||
</span></span></code></pre></div><p>The type of the failure value.</p><h2 id=member-functions-1>Member Functions
|
||||
<a class=anchor href=#member-functions-1>#</a></h2><h3 id=constructor-1>Constructor
|
||||
<a class=anchor href=#constructor-1>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>explicit</span> <span style=color:#a6e22e>failure</span>(value_type v);
|
||||
</span></span></code></pre></div><p>Constructs with a <code>value_type</code> argument.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> U<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>explicit</span> failure(U<span style=color:#f92672>&&</span> v);
|
||||
</span></span></code></pre></div><p>Constructs with another type that can be converted to <code>value_type</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> U<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>explicit</span> failure(failure<span style=color:#f92672><</span>U<span style=color:#f92672>></span> v);
|
||||
</span></span></code></pre></div><p>Constructs with another <code>failure</code> type that can be converted to <code>value_type</code>.</p><h3 id=get-2><code>get()</code>
|
||||
<a class=anchor href=#get-2>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>value_type<span style=color:#f92672>&</span> get() <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>value_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> get() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><p>Accesses the stored value.</p><h2 id=non-member-functions-1>Non-Member Functions
|
||||
<a class=anchor href=#non-member-functions-1>#</a></h2><h3 id=errt><code>err(T)</code>
|
||||
<a class=anchor href=#errt>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>failure<span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> std<span style=color:#f92672>::</span>decay<span style=color:#f92672><</span>T<span style=color:#f92672>>::</span>type<span style=color:#f92672>></span> err(T<span style=color:#f92672>&&</span> v);
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span>std<span style=color:#f92672>::</span>size_t N<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>failure<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> err(<span style=color:#66d9ef>const</span> <span style=color:#66d9ef>char</span> (<span style=color:#f92672>&</span>literal)[N]);
|
||||
</span></span></code></pre></div><p>Constructs and returns a <code>failure</code> type from a failure value.</p><p>Converts a string literal into <code>std::string</code>.</p><h1 id=failurereference_wrappert><code>failure<reference_wrapper<T>></code>
|
||||
<a class=anchor href=#failurereference_wrappert>#</a></h1><p>Specialization of <code>failure</code> for when the failure value is a reference.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>failure</span><span style=color:#f92672><</span>std<span style=color:#f92672>::</span>reference_wrapper<span style=color:#f92672><</span>T<span style=color:#f92672>>></span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> value_type <span style=color:#f92672>=</span> T;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>explicit</span> <span style=color:#a6e22e>failure</span>(std<span style=color:#f92672>::</span>reference_wrapper<span style=color:#f92672><</span>value_type<span style=color:#f92672>></span> v) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> value_type<span style=color:#f92672>&</span> get() <span style=color:#66d9ef>noexcept</span> {<span style=color:#66d9ef>return</span> value.get();}
|
||||
</span></span><span style=display:flex><span> value_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> get() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span> {<span style=color:#66d9ef>return</span> value.get();}
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><h2 id=member-types-3>Member Types
|
||||
<a class=anchor href=#member-types-3>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>using</span> value_type <span style=color:#f92672>=</span> T;
|
||||
</span></span></code></pre></div><p>The type of the failure value. It is <code>T</code> from <code>std::reference_wrapper<T></code>, not the reference itself.</p><h3 id=get-3><code>get()</code>
|
||||
<a class=anchor href=#get-3>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>value_type<span style=color:#f92672>&</span> get() <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>value_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> get() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><p>Accesses the stored value.</p><h1 id=result>result
|
||||
<a class=anchor href=#result>#</a></h1><p>A type that holds either a success value or a failure value.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#66d9ef>typename</span> E<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>result</span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> success_type <span style=color:#f92672>=</span> success<span style=color:#f92672><</span>T<span style=color:#f92672>></span>;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> failure_type <span style=color:#f92672>=</span> failure<span style=color:#f92672><</span>E<span style=color:#f92672>></span>;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> value_type <span style=color:#f92672>=</span> <span style=color:#66d9ef>typename</span> success_type<span style=color:#f92672>::</span>value_type;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> error_type <span style=color:#f92672>=</span> <span style=color:#66d9ef>typename</span> failure_type<span style=color:#f92672>::</span>value_type;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> result(success_type s);
|
||||
</span></span><span style=display:flex><span> result(failure_type f);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> U<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> result(success<span style=color:#f92672><</span>U<span style=color:#f92672>></span> s);
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> U<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> result(failure<span style=color:#f92672><</span>U<span style=color:#f92672>></span> f);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> result<span style=color:#f92672>&</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>=</span>(success_type s);
|
||||
</span></span><span style=display:flex><span> result<span style=color:#f92672>&</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>=</span>(failure_type f);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> U<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> result<span style=color:#f92672>&</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>=</span>(success<span style=color:#f92672><</span>U<span style=color:#f92672>></span> s);
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> U<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> result<span style=color:#f92672>&</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>=</span>(failure<span style=color:#f92672><</span>U<span style=color:#f92672>></span> f);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#f92672>~</span>result() <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> result(<span style=color:#66d9ef>const</span> result<span style=color:#f92672>&</span> other);
|
||||
</span></span><span style=display:flex><span> result(result<span style=color:#f92672>&&</span> other);
|
||||
</span></span><span style=display:flex><span> result<span style=color:#f92672>&</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>=</span>(<span style=color:#66d9ef>const</span> result<span style=color:#f92672>&</span> other);
|
||||
</span></span><span style=display:flex><span> result<span style=color:#f92672>&</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>=</span>(result<span style=color:#f92672>&&</span> other);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> U, <span style=color:#66d9ef>typename</span> F<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> result(result<span style=color:#f92672><</span>U, F<span style=color:#f92672>></span> other);
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> U, <span style=color:#66d9ef>typename</span> F<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> result<span style=color:#f92672>&</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>=</span>(result<span style=color:#f92672><</span>U, F<span style=color:#f92672>></span> other);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>bool</span> <span style=color:#a6e22e>is_ok</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>bool</span> <span style=color:#a6e22e>is_err</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>explicit</span> <span style=color:#66d9ef>operator</span> <span style=color:#a6e22e>bool</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> value_type<span style=color:#f92672>&</span> unwrap(cxx<span style=color:#f92672>::</span>source_location loc <span style=color:#f92672>=</span> cxx<span style=color:#f92672>::</span>source_location<span style=color:#f92672>::</span>current());
|
||||
</span></span><span style=display:flex><span> value_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> unwrap(cxx<span style=color:#f92672>::</span>source_location loc <span style=color:#f92672>=</span> cxx<span style=color:#f92672>::</span>source_location<span style=color:#f92672>::</span>current()) <span style=color:#66d9ef>const</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> value_type<span style=color:#f92672>&</span> unwrap_or(value_type<span style=color:#f92672>&</span> opt) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span> value_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> unwrap_or(value_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> opt) <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> error_type<span style=color:#f92672>&</span> unwrap_err(cxx<span style=color:#f92672>::</span>source_location loc <span style=color:#f92672>=</span> cxx<span style=color:#f92672>::</span>source_location<span style=color:#f92672>::</span>current());
|
||||
</span></span><span style=display:flex><span> error_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> unwrap_err(cxx<span style=color:#f92672>::</span>source_location loc <span style=color:#f92672>=</span> cxx<span style=color:#f92672>::</span>source_location<span style=color:#f92672>::</span>current()) <span style=color:#66d9ef>const</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> value_type<span style=color:#f92672>&</span> as_ok() <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span> value_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_ok() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> error_type<span style=color:#f92672>&</span> as_err() <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span> error_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_err() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><h2 id=member-types-4>Member Types
|
||||
<a class=anchor href=#member-types-4>#</a></h2><h3 id=success_type><code>success_type</code>
|
||||
<a class=anchor href=#success_type>#</a></h3><p><code>success<T></code>.</p><h3 id=failure_type><code>failure_type</code>
|
||||
<a class=anchor href=#failure_type>#</a></h3><p><code>failure<E></code>.</p><h3 id=value_type><code>value_type</code>
|
||||
<a class=anchor href=#value_type>#</a></h3><p>The type <code>T</code> of the success value, alias for <code>success_type::value_type</code>.</p><p>If <code>T</code> is <code>std::reference_wrapper<U></code>, then it is <code>U</code>.</p><h3 id=error_type><code>error_type</code>
|
||||
<a class=anchor href=#error_type>#</a></h3><p>The type <code>E</code> of the failure value, alias for <code>failure_type::value_type</code>.</p><p>If <code>E</code> is <code>std::reference_wrapper<F></code>, then it is <code>F</code>.</p><h2 id=member-functions-2>Member Functions
|
||||
<a class=anchor href=#member-functions-2>#</a></h2><h3 id=constructor-2>Constructor
|
||||
<a class=anchor href=#constructor-2>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>result() <span style=color:#f92672>=</span> <span style=color:#66d9ef>delete</span>;
|
||||
</span></span></code></pre></div><p>Cannot construct <code>result</code> type by default. Needs to be given either a success or failure type.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>result(success_type s);
|
||||
</span></span><span style=display:flex><span>result(failure_type f);
|
||||
</span></span></code></pre></div><p>Constructs with a <code>success_type</code> or <code>failure_type</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> U<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>result(success<span style=color:#f92672><</span>U<span style=color:#f92672>></span> s);
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> U<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>result(failure<span style=color:#f92672><</span>U<span style=color:#f92672>></span> f);
|
||||
</span></span></code></pre></div><p>Constructs with a <code>success<U></code> or <code>failure<U></code> that is convertible to <code>value_type</code> or <code>error_type</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> U, <span style=color:#66d9ef>typename</span> F<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>result(result<span style=color:#f92672><</span>U, F<span style=color:#f92672>></span> other);
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> U, <span style=color:#66d9ef>typename</span> F<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>result<span style=color:#f92672>&</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>=</span>(result<span style=color:#f92672><</span>U, F<span style=color:#f92672>></span> other);
|
||||
</span></span></code></pre></div><p>Constructs from or assigns to another <code>result</code> with convertible <code>success</code> or <code>failure</code> types.</p><h3 id=copy-and-move-constructors>Copy and Move Constructors
|
||||
<a class=anchor href=#copy-and-move-constructors>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>result(<span style=color:#66d9ef>const</span> result<span style=color:#f92672>&</span> other);
|
||||
</span></span><span style=display:flex><span>result(result<span style=color:#f92672>&&</span> other);
|
||||
</span></span></code></pre></div><p>Can be copy or move constructed.</p><h3 id=operator><code>operator=</code>
|
||||
<a class=anchor href=#operator>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>result<span style=color:#f92672>&</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>=</span>(<span style=color:#66d9ef>const</span> result<span style=color:#f92672>&</span> other);
|
||||
</span></span><span style=display:flex><span>result<span style=color:#f92672>&</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>=</span>(result<span style=color:#f92672>&&</span> other);
|
||||
</span></span></code></pre></div><p>Can be copy or move assigned.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> U<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>result<span style=color:#f92672>&</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>=</span>(success<span style=color:#f92672><</span>U<span style=color:#f92672>></span> s);
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> U<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>result<span style=color:#f92672>&</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>=</span>(failure<span style=color:#f92672><</span>U<span style=color:#f92672>></span> f);
|
||||
</span></span></code></pre></div><p>Can be assigned from convertible <code>success</code> or <code>failure</code> types.</p><h3 id=is_ok><code>is_ok()</code>
|
||||
<a class=anchor href=#is_ok>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>bool</span> <span style=color:#a6e22e>is_ok</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><p>Returns <code>true</code> if it holds a success value, <code>false</code> otherwise.</p><h3 id=is_err><code>is_err()</code>
|
||||
<a class=anchor href=#is_err>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>bool</span> <span style=color:#a6e22e>is_err</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><p>Returns <code>true</code> if it holds a failure value, <code>false</code> otherwise.</p><h3 id=operator-bool><code>operator bool()</code>
|
||||
<a class=anchor href=#operator-bool>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>explicit</span> <span style=color:#66d9ef>operator</span> <span style=color:#a6e22e>bool</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><p>Returns <code>true</code> if it holds a success value, <code>false</code> otherwise.</p><h3 id=unwrap><code>unwrap()</code>
|
||||
<a class=anchor href=#unwrap>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>value_type<span style=color:#f92672>&</span> unwrap(cxx<span style=color:#f92672>::</span>source_location loc <span style=color:#f92672>=</span> cxx<span style=color:#f92672>::</span>source_location<span style=color:#f92672>::</span>current());
|
||||
</span></span><span style=display:flex><span>value_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> unwrap(cxx<span style=color:#f92672>::</span>source_location loc <span style=color:#f92672>=</span> cxx<span style=color:#f92672>::</span>source_location<span style=color:#f92672>::</span>current()) <span style=color:#66d9ef>const</span>;
|
||||
</span></span></code></pre></div><p>Returns the stored success value.</p><p>Throws <code>toml::bad_result_access</code> if it holds a failure value.</p><p>If <code>std::source_location</code> or equivalent compiler extension is available, the file name and line number where <code>unwrap()</code> occurred are included in the <code>what()</code> string.</p><h3 id=unwrap_or><code>unwrap_or()</code>
|
||||
<a class=anchor href=#unwrap_or>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>value_type<span style=color:#f92672>&</span> unwrap_or(value_type<span style=color:#f92672>&</span> opt) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>value_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> unwrap_or(value_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> opt) <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><p>Returns the stored success value if present, otherwise returns the provided default value.</p><h3 id=unwrap_err><code>unwrap_err()</code>
|
||||
<a class=anchor href=#unwrap_err>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>error_type<span style=color:#f92672>&</span> unwrap_err(cxx<span style=color:#f92672>::</span>source_location loc <span style=color:#f92672>=</span> cxx<span style=color:#f92672>::</span>source_location<span style=color:#f92672>::</span>current());
|
||||
</span></span><span style=display:flex><span>error_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> unwrap_err(cxx<span style=color:#f92672>::</span>source_location loc <span style=color:#f92672>=</span> cxx<span style=color:#f92672>::</span>source_location<span style=color:#f92672>::</span>current()) <span style=color:#66d9ef>const</span>;
|
||||
</span></span></code></pre></div><p>Returns the stored failure value.</p><p>Throws <code>toml::bad_result_access</code> if it holds a success value.</p><p>If <code>std::source_location</code> or equivalent compiler extension is available, the file name and line number where <code>unwrap_err()</code> occurred are included in the <code>what()</code> string.</p><h3 id=as_ok><code>as_ok()</code>
|
||||
<a class=anchor href=#as_ok>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>value_type<span style=color:#f92672>&</span> as_ok() <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>value_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_ok() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><p>Returns the success value without checking.</p><p>Behavior is undefined if it holds a failure value.</p><h3 id=as_err><code>as_err()</code>
|
||||
<a class=anchor href=#as_err>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>error_type<span style=color:#f92672>&</span> as_err() <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>error_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_err() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><p>Returns the failure value without checking.</p><p>Behavior is undefined if it holds a success value.</p><h1 id=bad_result_access>bad_result_access
|
||||
<a class=anchor href=#bad_result_access>#</a></h1><p>An exception thrown when <code>unwrap</code> or <code>unwrap_err</code> fails in a <code>result</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>bad_result_access</span> <span style=color:#f92672>:</span> <span style=color:#66d9ef>public</span> <span style=color:#f92672>::</span>toml<span style=color:#f92672>::</span>exception
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>public</span><span style=color:#f92672>:</span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>explicit</span> bad_result_access(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> what_arg);
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>virtual</span> <span style=color:#f92672>~</span>bad_result_access() <span style=color:#66d9ef>noexcept</span> <span style=color:#66d9ef>override</span> <span style=color:#f92672>=</span> <span style=color:#66d9ef>default</span>;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>virtual</span> <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>char</span><span style=color:#f92672>*</span> <span style=color:#a6e22e>what</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span> <span style=color:#66d9ef>override</span>;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>protected</span><span style=color:#f92672>:</span>
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string what_;
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#resulthpp>result.hpp</a></li><li><a href=#success>success</a><ul><li><a href=#member-types>Member Types</a></li><li><a href=#member-functions>Member Functions</a><ul><li><a href=#constructor>Constructor</a></li><li><a href=#get><code>get()</code></a></li></ul></li><li><a href=#non-member-functions>Non-Member Functions</a><ul><li><a href=#okt><code>ok(T)</code></a></li></ul></li></ul></li><li><a href=#successreference_wrappert><code>success<reference_wrapper<T>></code></a><ul><li><a href=#member-types-1>Member Types</a><ul><li><a href=#get-1><code>get()</code></a></li></ul></li></ul></li><li><a href=#failure>failure</a><ul><li><a href=#member-types-2>Member Types</a></li><li><a href=#member-functions-1>Member Functions</a><ul><li><a href=#constructor-1>Constructor</a></li><li><a href=#get-2><code>get()</code></a></li></ul></li><li><a href=#non-member-functions-1>Non-Member Functions</a><ul><li><a href=#errt><code>err(T)</code></a></li></ul></li></ul></li><li><a href=#failurereference_wrappert><code>failure<reference_wrapper<T>></code></a><ul><li><a href=#member-types-3>Member Types</a><ul><li><a href=#get-3><code>get()</code></a></li></ul></li></ul></li><li><a href=#result>result</a><ul><li><a href=#member-types-4>Member Types</a><ul><li><a href=#success_type><code>success_type</code></a></li><li><a href=#failure_type><code>failure_type</code></a></li><li><a href=#value_type><code>value_type</code></a></li><li><a href=#error_type><code>error_type</code></a></li></ul></li><li><a href=#member-functions-2>Member Functions</a><ul><li><a href=#constructor-2>Constructor</a></li><li><a href=#copy-and-move-constructors>Copy and Move Constructors</a></li><li><a href=#operator><code>operator=</code></a></li><li><a href=#is_ok><code>is_ok()</code></a></li><li><a href=#is_err><code>is_err()</code></a></li><li><a href=#operator-bool><code>operator bool()</code></a></li><li><a href=#unwrap><code>unwrap()</code></a></li><li><a href=#unwrap_or><code>unwrap_or()</code></a></li><li><a href=#unwrap_err><code>unwrap_err()</code></a></li><li><a href=#as_ok><code>as_ok()</code></a></li><li><a href=#as_err><code>as_err()</code></a></li></ul></li></ul></li><li><a href=#bad_result_access>bad_result_access</a></li></ul></nav></div></aside></main></body></html>
|
||||
65
docs/reference/serializer/index.html
Normal file
65
docs/reference/serializer/index.html
Normal file
@@ -0,0 +1,65 @@
|
||||
<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
|
||||
serializer.hpp
|
||||
#
|
||||
|
||||
|
||||
format
|
||||
#
|
||||
|
||||
Serializes the data.
|
||||
namespace toml
|
||||
{
|
||||
template<typename TC>
|
||||
std::string format(const basic_value<TC>& v,
|
||||
const spec s = spec::default_version());
|
||||
template<typename TC>
|
||||
std::string format(const typename basic_value<TC>::key_type& k,
|
||||
const basic_value<TC>& v,
|
||||
const spec s = spec::default_version());
|
||||
template<typename TC>
|
||||
std::string format(const std::vector<typename basic_value<TC>::key_type>& ks,
|
||||
const basic_value<TC>& v,
|
||||
const spec s = spec::default_version());
|
||||
}
|
||||
If there’s a conflict between the format information and the spec, for example, when using v1.0.0 with table_format::multiline_oneline, the spec takes precedence."><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/reference/serializer/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="serializer.hpp"><meta property="og:description" content="serializer.hpp # format # Serializes the data.
|
||||
namespace toml { template<typename TC> std::string format(const basic_value<TC>& v, const spec s = spec::default_version()); template<typename TC> std::string format(const typename basic_value<TC>::key_type& k, const basic_value<TC>& v, const spec s = spec::default_version()); template<typename TC> std::string format(const std::vector<typename basic_value<TC>::key_type>& ks, const basic_value<TC>& v, const spec s = spec::default_version()); } If there’s a conflict between the format information and the spec, for example, when using v1.0.0 with table_format::multiline_oneline, the spec takes precedence."><meta property="og:locale" content="en"><meta property="og:type" content="article"><meta property="article:section" content="docs"><title>serializer.hpp | toml11</title><link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/reference/serializer/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/reference/serializer/ title=serializer.hpp><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" crossorigin=anonymous></script></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
|
||||
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
|
||||
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
|
||||
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/reference/serializer/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle>
|
||||
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle checked>
|
||||
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/ class=active>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
|
||||
</label><strong>serializer.hpp</strong>
|
||||
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#serializerhpp>serializer.hpp</a><ul><li><a href=#format><code>format</code></a><ul><li><a href=#formatv-spec><code>format(v, spec)</code></a></li><li><a href=#formatk-v-spec><code>format(k, v, spec)</code></a></li><li><a href=#formatk-v-spec-1><code>format([k,...], v, spec)</code></a></li></ul></li><li><a href=#serialization_error><code>serialization_error</code></a></li></ul></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=serializerhpp>serializer.hpp
|
||||
<a class=anchor href=#serializerhpp>#</a></h1><h2 id=format><code>format</code>
|
||||
<a class=anchor href=#format>#</a></h2><p>Serializes the data.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>string format(<span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v,
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> spec s <span style=color:#f92672>=</span> spec<span style=color:#f92672>::</span>default_version());
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>string format(<span style=color:#66d9ef>const</span> <span style=color:#66d9ef>typename</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>::</span>key_type<span style=color:#f92672>&</span> k,
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v,
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> spec s <span style=color:#f92672>=</span> spec<span style=color:#f92672>::</span>default_version());
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>string format(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>::</span>key_type<span style=color:#f92672>>&</span> ks,
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v,
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> spec s <span style=color:#f92672>=</span> spec<span style=color:#f92672>::</span>default_version());
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>If there’s a conflict between the format information and the <code>spec</code>, for example, when using <code>v1.0.0</code> with <code>table_format::multiline_oneline</code>, the <code>spec</code> takes precedence.</p><h3 id=formatv-spec><code>format(v, spec)</code>
|
||||
<a class=anchor href=#formatv-spec>#</a></h3><p>Formats a <code>toml::value</code> according to its format information and the provided <code>spec</code>.</p><p>If it’s a <code>table_type</code>, it’s formatted as if it were the root table. Otherwise, only the value is formatted.</p><h3 id=formatk-v-spec><code>format(k, v, spec)</code>
|
||||
<a class=anchor href=#formatk-v-spec>#</a></h3><p>Formats a <code>toml::value</code> along with the given key.</p><p><code>v</code> is interpreted as being defined under that key.</p><h3 id=formatk-v-spec-1><code>format([k,...], v, spec)</code>
|
||||
<a class=anchor href=#formatk-v-spec-1>#</a></h3><p><code>v</code> is interpreted as being defined under those keys.
|
||||
If multiple keys are provided, it’s interpreted as a recursively defined table.</p><h2 id=serialization_error><code>serialization_error</code>
|
||||
<a class=anchor href=#serialization_error>#</a></h2><p>Reports errors that occurred during serialization.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>serialization_error</span> <span style=color:#66d9ef>final</span> <span style=color:#f92672>:</span> <span style=color:#66d9ef>public</span> <span style=color:#f92672>::</span>toml<span style=color:#f92672>::</span>exception
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>public</span><span style=color:#f92672>:</span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>explicit</span> serialization_error(std<span style=color:#f92672>::</span>string what_arg, source_location loc);
|
||||
</span></span><span style=display:flex><span> <span style=color:#f92672>~</span>serialization_error() <span style=color:#66d9ef>noexcept</span> <span style=color:#66d9ef>override</span> <span style=color:#f92672>=</span> <span style=color:#66d9ef>default</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>char</span><span style=color:#f92672>*</span> <span style=color:#a6e22e>what</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span> <span style=color:#66d9ef>override</span>;
|
||||
</span></span><span style=display:flex><span> source_location <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> location() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#serializerhpp>serializer.hpp</a><ul><li><a href=#format><code>format</code></a><ul><li><a href=#formatv-spec><code>format(v, spec)</code></a></li><li><a href=#formatk-v-spec><code>format(k, v, spec)</code></a></li><li><a href=#formatk-v-spec-1><code>format([k,...], v, spec)</code></a></li></ul></li><li><a href=#serialization_error><code>serialization_error</code></a></li></ul></li></ul></nav></div></aside></main></body></html>
|
||||
162
docs/reference/source_location/index.html
Normal file
162
docs/reference/source_location/index.html
Normal file
@@ -0,0 +1,162 @@
|
||||
<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
|
||||
source_location.hpp
|
||||
#
|
||||
|
||||
source_location.hpp defines a class representing a specific area within a TOML file.
|
||||
This class is used to represent problematic areas in error messages.
|
||||
|
||||
toml::source_location
|
||||
#
|
||||
|
||||
source_location is a class representing a specific area within a TOML file.
|
||||
namespace toml
|
||||
{
|
||||
struct source_location
|
||||
{
|
||||
public:
|
||||
|
||||
explicit source_location(/* implementation-defined */);
|
||||
~source_location() = default;
|
||||
source_location(source_location const&) = default;
|
||||
source_location(source_location &&) = default;
|
||||
source_location& operator=(source_location const&) = default;
|
||||
source_location& operator=(source_location &&) = default;
|
||||
|
||||
bool is_ok() const noexcept;
|
||||
std::size_t length() const noexcept;
|
||||
|
||||
std::size_t first_line_number() const noexcept;
|
||||
std::size_t first_column_number() const noexcept;
|
||||
std::size_t last_line_number() const noexcept;
|
||||
std::size_t last_column_number() const noexcept;
|
||||
|
||||
std::string const& file_name() const noexcept;
|
||||
|
||||
std::size_t num_lines() const noexcept;
|
||||
|
||||
std::string const& first_line() const;
|
||||
std::string const& last_line() const;
|
||||
|
||||
std::vector<std::string> const& lines() const noexcept;
|
||||
};
|
||||
|
||||
template<typename ... Ts>
|
||||
std::string format_location(const source_location& loc, const std::string& msg, const Ts& ... locs_and_msgs);
|
||||
} //toml
|
||||
|
||||
Member Functions
|
||||
#
|
||||
|
||||
|
||||
Constructor
|
||||
#
|
||||
|
||||
explicit source_location(/* implementation-defined */);
|
||||
toml::source_location can only be constructed via toml::parse or the _toml literal."><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/reference/source_location/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="source_location.hpp"><meta property="og:description" content="source_location.hpp # source_location.hpp defines a class representing a specific area within a TOML file.
|
||||
This class is used to represent problematic areas in error messages.
|
||||
toml::source_location # source_location is a class representing a specific area within a TOML file.
|
||||
namespace toml { struct source_location { public: explicit source_location(/* implementation-defined */); ~source_location() = default; source_location(source_location const&) = default; source_location(source_location &&) = default; source_location& operator=(source_location const&) = default; source_location& operator=(source_location &&) = default; bool is_ok() const noexcept; std::size_t length() const noexcept; std::size_t first_line_number() const noexcept; std::size_t first_column_number() const noexcept; std::size_t last_line_number() const noexcept; std::size_t last_column_number() const noexcept; std::string const& file_name() const noexcept; std::size_t num_lines() const noexcept; std::string const& first_line() const; std::string const& last_line() const; std::vector<std::string> const& lines() const noexcept; }; template<typename ... Ts> std::string format_location(const source_location& loc, const std::string& msg, const Ts& ... locs_and_msgs); } //toml Member Functions # Constructor # explicit source_location(/* implementation-defined */); toml::source_location can only be constructed via toml::parse or the _toml literal."><meta property="og:locale" content="en"><meta property="og:type" content="article"><meta property="article:section" content="docs"><title>source_location.hpp | toml11</title><link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/reference/source_location/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/reference/source_location/ title=source_location.hpp><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" crossorigin=anonymous></script></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
|
||||
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
|
||||
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
|
||||
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/reference/source_location/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle>
|
||||
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle checked>
|
||||
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/ class=active>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
|
||||
</label><strong>source_location.hpp</strong>
|
||||
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#source_locationhpp>source_location.hpp</a></li><li><a href=#tomlsource_location><code>toml::source_location</code></a><ul><li><a href=#member-functions>Member Functions</a><ul><li><a href=#constructor>Constructor</a></li><li><a href=#is_ok><code>is_ok()</code></a></li><li><a href=#length><code>length()</code></a></li><li><a href=#first_line_number><code>first_line_number()</code></a></li><li><a href=#first_column_number><code>first_column_number()</code></a></li><li><a href=#last_line_number><code>last_line_number()</code></a></li><li><a href=#last_column_number><code>last_column_number()</code></a></li><li><a href=#file_name><code>file_name()</code></a></li><li><a href=#num_lines><code>num_lines()</code></a></li><li><a href=#first_line><code>first_line()</code></a></li><li><a href=#last_line><code>last_line()</code></a></li><li><a href=#lines><code>lines()</code></a></li></ul></li><li><a href=#non-member-functions>Non-Member Functions</a><ul><li><a href=#format_location><code>format_location</code></a></li></ul></li></ul></li><li><a href=#related>Related</a></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=source_locationhpp>source_location.hpp
|
||||
<a class=anchor href=#source_locationhpp>#</a></h1><p><code>source_location.hpp</code> defines a class representing a specific area within a TOML file.</p><p>This class is used to represent problematic areas in error messages.</p><h1 id=tomlsource_location><code>toml::source_location</code>
|
||||
<a class=anchor href=#tomlsource_location>#</a></h1><p><code>source_location</code> is a class representing a specific area within a TOML file.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>source_location</span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>public</span><span style=color:#f92672>:</span>
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>explicit</span> source_location(<span style=color:#75715e>/* implementation-defined */</span>);
|
||||
</span></span><span style=display:flex><span> <span style=color:#f92672>~</span>source_location() <span style=color:#f92672>=</span> <span style=color:#66d9ef>default</span>;
|
||||
</span></span><span style=display:flex><span> source_location(source_location <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span>) <span style=color:#f92672>=</span> <span style=color:#66d9ef>default</span>;
|
||||
</span></span><span style=display:flex><span> source_location(source_location <span style=color:#f92672>&&</span>) <span style=color:#f92672>=</span> <span style=color:#66d9ef>default</span>;
|
||||
</span></span><span style=display:flex><span> source_location<span style=color:#f92672>&</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>=</span>(source_location <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span>) <span style=color:#f92672>=</span> <span style=color:#66d9ef>default</span>;
|
||||
</span></span><span style=display:flex><span> source_location<span style=color:#f92672>&</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>=</span>(source_location <span style=color:#f92672>&&</span>) <span style=color:#f92672>=</span> <span style=color:#66d9ef>default</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>bool</span> <span style=color:#a6e22e>is_ok</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>size_t length() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>size_t first_line_number() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>size_t first_column_number() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>size_t last_line_number() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>size_t last_column_number() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> file_name() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>size_t num_lines() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> first_line() <span style=color:#66d9ef>const</span>;
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> last_line() <span style=color:#66d9ef>const</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> lines() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> ... Ts<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>string format_location(<span style=color:#66d9ef>const</span> source_location<span style=color:#f92672>&</span> loc, <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> msg, <span style=color:#66d9ef>const</span> Ts<span style=color:#f92672>&</span> ... locs_and_msgs);
|
||||
</span></span><span style=display:flex><span>} <span style=color:#75715e>//toml
|
||||
</span></span></span></code></pre></div><h2 id=member-functions>Member Functions
|
||||
<a class=anchor href=#member-functions>#</a></h2><h3 id=constructor>Constructor
|
||||
<a class=anchor href=#constructor>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>explicit</span> <span style=color:#a6e22e>source_location</span>(<span style=color:#75715e>/* implementation-defined */</span>);
|
||||
</span></span></code></pre></div><p><code>toml::source_location</code> can only be constructed via <code>toml::parse</code> or the <code>_toml</code> literal.</p><h3 id=is_ok><code>is_ok()</code>
|
||||
<a class=anchor href=#is_ok>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>bool</span> <span style=color:#a6e22e>is_ok</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><p>Returns <code>true</code> if the <code>source_location</code> holds a valid value, <code>false</code> otherwise.</p><p>The result of <code>location()</code> from <code>toml::value</code> constructed outside of <code>toml::parse</code> or <code>_toml</code> literals returns <code>false</code> for <code>is_ok</code> as it points to nothing.</p><h3 id=length><code>length()</code>
|
||||
<a class=anchor href=#length>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>std<span style=color:#f92672>::</span>size_t length() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><p>Returns the length of the area pointed to by the <code>source_location</code>.</p><p>Returns <code>0</code> if it does not hold a valid value.</p><h3 id=first_line_number><code>first_line_number()</code>
|
||||
<a class=anchor href=#first_line_number>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>std<span style=color:#f92672>::</span>size_t first_line_number() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><p>Returns the line number of the first line of the area pointed to by the <code>source_location</code>.</p><p>Returns <code>1</code> if it does not hold a valid value.</p><h3 id=first_column_number><code>first_column_number()</code>
|
||||
<a class=anchor href=#first_column_number>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>std<span style=color:#f92672>::</span>size_t first_column_number() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><p>Returns the column number of the first column of the area pointed to by the <code>source_location</code>.</p><p>Returns <code>1</code> if it does not hold a valid value.</p><h3 id=last_line_number><code>last_line_number()</code>
|
||||
<a class=anchor href=#last_line_number>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>std<span style=color:#f92672>::</span>size_t last_line_number() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><p>Returns the line number of the last line of the area pointed to by the <code>source_location</code>.</p><p>Returns <code>1</code> if it does not hold a valid value.</p><h3 id=last_column_number><code>last_column_number()</code>
|
||||
<a class=anchor href=#last_column_number>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>std<span style=color:#f92672>::</span>size_t last_column_number() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><p>Returns the column number of the last column of the area pointed to by the <code>source_location</code>.</p><p>Returns <code>1</code> if it does not hold a valid value.</p><h3 id=file_name><code>file_name()</code>
|
||||
<a class=anchor href=#file_name>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>std<span style=color:#f92672>::</span>string <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> file_name() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><p>Returns the file name containing the area pointed to by the <code>source_location</code>.</p><p>Returns <code>"unknown file"</code> if it does not hold a valid value.</p><h3 id=num_lines><code>num_lines()</code>
|
||||
<a class=anchor href=#num_lines>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>std<span style=color:#f92672>::</span>size_t num_lines() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><p>Returns the number of lines in the area pointed to by the <code>source_location</code>.</p><p>Returns <code>0</code> if it does not hold a valid value.</p><h3 id=first_line><code>first_line()</code>
|
||||
<a class=anchor href=#first_line>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>std<span style=color:#f92672>::</span>string <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> first_line() <span style=color:#66d9ef>const</span>;
|
||||
</span></span></code></pre></div><p>Returns the first line of the area pointed to by the <code>source_location</code>.</p><p>Throws <code>std::out_of_range</code> if it does not hold a valid value.</p><h3 id=last_line><code>last_line()</code>
|
||||
<a class=anchor href=#last_line>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>std<span style=color:#f92672>::</span>string <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> last_line() <span style=color:#66d9ef>const</span>;
|
||||
</span></span></code></pre></div><p>Returns the last line of the area pointed to by the <code>source_location</code>.</p><p>Throws <code>std::out_of_range</code> if it does not hold a valid value.</p><h3 id=lines><code>lines()</code>
|
||||
<a class=anchor href=#lines>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> lines() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><p>Returns all lines in the area pointed to by the <code>source_location</code>.</p><p>Returns a reference to an empty <code>std::vector</code> if it does not hold a valid value.</p><h2 id=non-member-functions>Non-Member Functions
|
||||
<a class=anchor href=#non-member-functions>#</a></h2><h3 id=format_location><code>format_location</code>
|
||||
<a class=anchor href=#format_location>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> ... Ts<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>string format_location(<span style=color:#66d9ef>const</span> source_location<span style=color:#f92672>&</span> loc, <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> msg,
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> Ts<span style=color:#f92672>&</span> ... locs_and_msgs);
|
||||
</span></span></code></pre></div><p>Formats the specified <code>source_location</code> and its associated message as follows:</p><pre tabindex=0><code> -> {filename.toml}
|
||||
|
|
||||
1 | a = 42
|
||||
| ^-- {message}
|
||||
</code></pre><p>If colorization is enabled, ANSI escape sequences will be added for coloring.</p><p>When multiple <code>locs_and_msgs</code> are provided, they must be in the order of <code>const source_location&</code> followed by <code>const std::string&</code>, and the next pair in the same order, and so on.</p><h4 id=example-multiple-source_location-and-stdstring>Example: Multiple <code>source_location</code> and <code>std::string</code>
|
||||
<a class=anchor href=#example-multiple-source_location-and-stdstring>#</a></h4><p>When multiple <code>source_location</code> and <code>std::string</code> pairs are provided, they are formatted as follows:</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>source_location<span style=color:#f92672>&</span> loc0;
|
||||
</span></span><span style=display:flex><span>source_location<span style=color:#f92672>&</span> loc1;
|
||||
</span></span><span style=display:flex><span>source_location<span style=color:#f92672>&</span> loc2;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>string msg0;
|
||||
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>string msg1;
|
||||
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>string msg2;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span>format_location(loc0, msg0,
|
||||
</span></span><span style=display:flex><span> loc1, msg1,
|
||||
</span></span><span style=display:flex><span> loc2, msg2);
|
||||
</span></span></code></pre></div><pre tabindex=0><code> -> {filename0.toml}
|
||||
|
|
||||
1 | a = 42
|
||||
| ^-- {message0}
|
||||
|
|
||||
-> {filename1.toml}
|
||||
|
|
||||
2 | b = 3.14
|
||||
| ^-- {message1}
|
||||
|
|
||||
-> {filename2.toml}
|
||||
|
|
||||
3 | c = "foo"
|
||||
| ^-- {message2}
|
||||
</code></pre><h1 id=related>Related
|
||||
<a class=anchor href=#related>#</a></h1><ul><li><a href=https://toruniina.github.io/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=https://toruniina.github.io/toml11/docs/reference/value/>value.hpp</a></li></ul></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#source_locationhpp>source_location.hpp</a></li><li><a href=#tomlsource_location><code>toml::source_location</code></a><ul><li><a href=#member-functions>Member Functions</a><ul><li><a href=#constructor>Constructor</a></li><li><a href=#is_ok><code>is_ok()</code></a></li><li><a href=#length><code>length()</code></a></li><li><a href=#first_line_number><code>first_line_number()</code></a></li><li><a href=#first_column_number><code>first_column_number()</code></a></li><li><a href=#last_line_number><code>last_line_number()</code></a></li><li><a href=#last_column_number><code>last_column_number()</code></a></li><li><a href=#file_name><code>file_name()</code></a></li><li><a href=#num_lines><code>num_lines()</code></a></li><li><a href=#first_line><code>first_line()</code></a></li><li><a href=#last_line><code>last_line()</code></a></li><li><a href=#lines><code>lines()</code></a></li></ul></li><li><a href=#non-member-functions>Non-Member Functions</a><ul><li><a href=#format_location><code>format_location</code></a></li></ul></li></ul></li><li><a href=#related>Related</a></li></ul></nav></div></aside></main></body></html>
|
||||
164
docs/reference/spec/index.html
Normal file
164
docs/reference/spec/index.html
Normal file
@@ -0,0 +1,164 @@
|
||||
<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
|
||||
spec.hpp
|
||||
#
|
||||
|
||||
spec.hpp defines classes for specifying the version of TOML.
|
||||
|
||||
toml::semantic_version
|
||||
#
|
||||
|
||||
semantic_version is a class that stores version information.
|
||||
namespace toml
|
||||
{
|
||||
struct semantic_version
|
||||
{
|
||||
constexpr semantic_version(std::uint32_t mjr, std::uint32_t mnr, std::uint32_t p) noexcept;
|
||||
|
||||
std::uint32_t major;
|
||||
std::uint32_t minor;
|
||||
std::uint32_t patch;
|
||||
};
|
||||
|
||||
constexpr semantic_version
|
||||
make_semver(std::uint32_t major, std::uint32_t minor, std::uint32_t patch) noexcept;
|
||||
|
||||
constexpr bool operator==(const semantic_version&, const semantic_version&) noexcept;
|
||||
constexpr bool operator!=(const semantic_version&, const semantic_version&) noexcept;
|
||||
constexpr bool operator< (const semantic_version&, const semantic_version&) noexcept;
|
||||
constexpr bool operator<=(const semantic_version&, const semantic_version&) noexcept;
|
||||
constexpr bool operator> (const semantic_version&, const semantic_version&) noexcept;
|
||||
constexpr bool operator>=(const semantic_version&, const semantic_version&) noexcept;
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const semantic_version& ver);
|
||||
} //toml
|
||||
|
||||
Member Functions
|
||||
#
|
||||
|
||||
|
||||
Constructor
|
||||
#
|
||||
|
||||
constexpr semantic_version(std::uint32_t mjr, std::uint32_t mnr, std::uint32_t p) noexcept;
|
||||
Constructs a semantic_version instance with the specified major, minor, and patch version numbers."><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/reference/spec/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="spec.hpp"><meta property="og:description" content="spec.hpp # spec.hpp defines classes for specifying the version of TOML.
|
||||
toml::semantic_version # semantic_version is a class that stores version information.
|
||||
namespace toml { struct semantic_version { constexpr semantic_version(std::uint32_t mjr, std::uint32_t mnr, std::uint32_t p) noexcept; std::uint32_t major; std::uint32_t minor; std::uint32_t patch; }; constexpr semantic_version make_semver(std::uint32_t major, std::uint32_t minor, std::uint32_t patch) noexcept; constexpr bool operator==(const semantic_version&, const semantic_version&) noexcept; constexpr bool operator!=(const semantic_version&, const semantic_version&) noexcept; constexpr bool operator< (const semantic_version&, const semantic_version&) noexcept; constexpr bool operator<=(const semantic_version&, const semantic_version&) noexcept; constexpr bool operator> (const semantic_version&, const semantic_version&) noexcept; constexpr bool operator>=(const semantic_version&, const semantic_version&) noexcept; std::ostream& operator<<(std::ostream& os, const semantic_version& ver); } //toml Member Functions # Constructor # constexpr semantic_version(std::uint32_t mjr, std::uint32_t mnr, std::uint32_t p) noexcept; Constructs a semantic_version instance with the specified major, minor, and patch version numbers."><meta property="og:locale" content="en"><meta property="og:type" content="article"><meta property="article:section" content="docs"><title>spec.hpp | toml11</title><link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/reference/spec/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/reference/spec/ title=spec.hpp><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" crossorigin=anonymous></script></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
|
||||
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
|
||||
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
|
||||
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/reference/spec/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle>
|
||||
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle checked>
|
||||
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/ class=active>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
|
||||
</label><strong>spec.hpp</strong>
|
||||
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#spechpp>spec.hpp</a></li><li><a href=#tomlsemantic_version><code>toml::semantic_version</code></a><ul><li><a href=#member-functions>Member Functions</a><ul><li><a href=#constructor>Constructor</a></li></ul></li><li><a href=#non-member-functions>Non-Member Functions</a><ul><li><a href=#comparison-operators>Comparison Operators</a></li><li><a href=#stream-operator>Stream Operator</a></li><li><a href=#to_string><code>to_string</code></a></li></ul></li></ul></li><li><a href=#tomlspec><code>toml::spec</code></a><ul><li><a href=#member-functions-1>Member Functions</a><ul><li><a href=#constructor-1>Constructor</a></li><li><a href=#default_version><code>default_version()</code></a></li><li><a href=#vmajor-minor-patch><code>v(major, minor, patch)</code></a></li></ul></li><li><a href=#member-variables>Member Variables</a><ul><li><a href=#example>Example</a></li><li><a href=#v1_1_0_allow_control_characters_in_comments><code>v1_1_0_allow_control_characters_in_comments</code></a></li><li><a href=#v1_1_0_allow_newlines_in_inline_tables><code>v1_1_0_allow_newlines_in_inline_tables</code></a></li><li><a href=#v1_1_0_allow_trailing_comma_in_inline_tables><code>v1_1_0_allow_trailing_comma_in_inline_tables</code></a></li><li><a href=#v1_1_0_add_escape_sequence_e><code>v1_1_0_add_escape_sequence_e</code></a></li><li><a href=#v1_1_0_add_escape_sequence_x><code>v1_1_0_add_escape_sequence_x</code></a></li><li><a href=#v1_1_0_make_seconds_optional><code>v1_1_0_make_seconds_optional</code></a></li><li><a href=#ext_hex_float><code>ext_hex_float</code></a></li><li><a href=#ext_num_suffix><code>ext_num_suffix</code></a></li><li><a href=#ext_null_value><code>ext_null_value</code></a></li></ul></li></ul></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=spechpp>spec.hpp
|
||||
<a class=anchor href=#spechpp>#</a></h1><p><code>spec.hpp</code> defines classes for specifying the version of TOML.</p><h1 id=tomlsemantic_version><code>toml::semantic_version</code>
|
||||
<a class=anchor href=#tomlsemantic_version>#</a></h1><p><code>semantic_version</code> is a class that stores version information.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>semantic_version</span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>constexpr</span> <span style=color:#a6e22e>semantic_version</span>(std<span style=color:#f92672>::</span><span style=color:#66d9ef>uint32_t</span> mjr, std<span style=color:#f92672>::</span><span style=color:#66d9ef>uint32_t</span> mnr, std<span style=color:#f92672>::</span><span style=color:#66d9ef>uint32_t</span> p) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span><span style=color:#66d9ef>uint32_t</span> major;
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span><span style=color:#66d9ef>uint32_t</span> minor;
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span><span style=color:#66d9ef>uint32_t</span> patch;
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>constexpr</span> semantic_version
|
||||
</span></span><span style=display:flex><span><span style=color:#a6e22e>make_semver</span>(std<span style=color:#f92672>::</span><span style=color:#66d9ef>uint32_t</span> major, std<span style=color:#f92672>::</span><span style=color:#66d9ef>uint32_t</span> minor, std<span style=color:#f92672>::</span><span style=color:#66d9ef>uint32_t</span> patch) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>constexpr</span> <span style=color:#66d9ef>bool</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>==</span>(<span style=color:#66d9ef>const</span> semantic_version<span style=color:#f92672>&</span>, <span style=color:#66d9ef>const</span> semantic_version<span style=color:#f92672>&</span>) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>constexpr</span> <span style=color:#66d9ef>bool</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>!=</span>(<span style=color:#66d9ef>const</span> semantic_version<span style=color:#f92672>&</span>, <span style=color:#66d9ef>const</span> semantic_version<span style=color:#f92672>&</span>) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>constexpr</span> <span style=color:#66d9ef>bool</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672><</span> (<span style=color:#66d9ef>const</span> semantic_version<span style=color:#f92672>&</span>, <span style=color:#66d9ef>const</span> semantic_version<span style=color:#f92672>&</span>) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>constexpr</span> <span style=color:#66d9ef>bool</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672><=</span>(<span style=color:#66d9ef>const</span> semantic_version<span style=color:#f92672>&</span>, <span style=color:#66d9ef>const</span> semantic_version<span style=color:#f92672>&</span>) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>constexpr</span> <span style=color:#66d9ef>bool</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>></span> (<span style=color:#66d9ef>const</span> semantic_version<span style=color:#f92672>&</span>, <span style=color:#66d9ef>const</span> semantic_version<span style=color:#f92672>&</span>) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>constexpr</span> <span style=color:#66d9ef>bool</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>>=</span>(<span style=color:#66d9ef>const</span> semantic_version<span style=color:#f92672>&</span>, <span style=color:#66d9ef>const</span> semantic_version<span style=color:#f92672>&</span>) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672><<</span>(std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&</span> os, <span style=color:#66d9ef>const</span> semantic_version<span style=color:#f92672>&</span> ver);
|
||||
</span></span><span style=display:flex><span>} <span style=color:#75715e>//toml
|
||||
</span></span></span></code></pre></div><h2 id=member-functions>Member Functions
|
||||
<a class=anchor href=#member-functions>#</a></h2><h3 id=constructor>Constructor
|
||||
<a class=anchor href=#constructor>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>constexpr</span> <span style=color:#a6e22e>semantic_version</span>(std<span style=color:#f92672>::</span><span style=color:#66d9ef>uint32_t</span> mjr, std<span style=color:#f92672>::</span><span style=color:#66d9ef>uint32_t</span> mnr, std<span style=color:#f92672>::</span><span style=color:#66d9ef>uint32_t</span> p) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><p>Constructs a <code>semantic_version</code> instance with the specified <code>major</code>, <code>minor</code>, and <code>patch</code> version numbers.</p><h2 id=non-member-functions>Non-Member Functions
|
||||
<a class=anchor href=#non-member-functions>#</a></h2><h3 id=comparison-operators>Comparison Operators
|
||||
<a class=anchor href=#comparison-operators>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>constexpr</span> <span style=color:#66d9ef>bool</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>==</span>(<span style=color:#66d9ef>const</span> semantic_version<span style=color:#f92672>&</span>, <span style=color:#66d9ef>const</span> semantic_version<span style=color:#f92672>&</span>) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>constexpr</span> <span style=color:#66d9ef>bool</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>!=</span>(<span style=color:#66d9ef>const</span> semantic_version<span style=color:#f92672>&</span>, <span style=color:#66d9ef>const</span> semantic_version<span style=color:#f92672>&</span>) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>constexpr</span> <span style=color:#66d9ef>bool</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672><</span> (<span style=color:#66d9ef>const</span> semantic_version<span style=color:#f92672>&</span>, <span style=color:#66d9ef>const</span> semantic_version<span style=color:#f92672>&</span>) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>constexpr</span> <span style=color:#66d9ef>bool</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672><=</span>(<span style=color:#66d9ef>const</span> semantic_version<span style=color:#f92672>&</span>, <span style=color:#66d9ef>const</span> semantic_version<span style=color:#f92672>&</span>) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>constexpr</span> <span style=color:#66d9ef>bool</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>></span> (<span style=color:#66d9ef>const</span> semantic_version<span style=color:#f92672>&</span>, <span style=color:#66d9ef>const</span> semantic_version<span style=color:#f92672>&</span>) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>constexpr</span> <span style=color:#66d9ef>bool</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>>=</span>(<span style=color:#66d9ef>const</span> semantic_version<span style=color:#f92672>&</span>, <span style=color:#66d9ef>const</span> semantic_version<span style=color:#f92672>&</span>) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><p>Compares two <code>semantic_version</code> instances according to semantic versioning rules.</p><h3 id=stream-operator>Stream Operator
|
||||
<a class=anchor href=#stream-operator>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672><<</span>(std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&</span> os, <span style=color:#66d9ef>const</span> semantic_version<span style=color:#f92672>&</span> ver);
|
||||
</span></span></code></pre></div><p>Outputs the version in the format <code>{major}.{minor}.{patch}</code>.</p><h3 id=to_string><code>to_string</code>
|
||||
<a class=anchor href=#to_string>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>std<span style=color:#f92672>::</span>string to_string(<span style=color:#66d9ef>const</span> semantic_version<span style=color:#f92672>&</span> ver);
|
||||
</span></span></code></pre></div><p>Converts the version to a string in the format <code>{major}.{minor}.{patch}</code>.</p><h1 id=tomlspec><code>toml::spec</code>
|
||||
<a class=anchor href=#tomlspec>#</a></h1><p><code>spec</code> is a class that stores TOML version information.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>spec</span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>constexpr</span> <span style=color:#66d9ef>static</span> spec <span style=color:#a6e22e>default_version</span>() <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>constexpr</span> <span style=color:#66d9ef>static</span> spec <span style=color:#a6e22e>v</span>(std<span style=color:#f92672>::</span><span style=color:#66d9ef>uint32_t</span> mjr, std<span style=color:#f92672>::</span><span style=color:#66d9ef>uint32_t</span> mnr, std<span style=color:#f92672>::</span><span style=color:#66d9ef>uint32_t</span> p) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>constexpr</span> <span style=color:#66d9ef>explicit</span> <span style=color:#a6e22e>spec</span>(<span style=color:#66d9ef>const</span> semantic_version<span style=color:#f92672>&</span> semver) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> semantic_version version; <span style=color:#75715e>// toml version
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#75715e>// diff from v1.0.0 -> v1.1.0
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span> <span style=color:#66d9ef>bool</span> v1_1_0_allow_control_characters_in_comments;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>bool</span> v1_1_0_allow_newlines_in_inline_tables;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>bool</span> v1_1_0_allow_trailing_comma_in_inline_tables;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>bool</span> v1_1_0_allow_non_english_in_bare_keys;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>bool</span> v1_1_0_add_escape_sequence_e;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>bool</span> v1_1_0_add_escape_sequence_x;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>bool</span> v1_1_0_make_seconds_optional;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#75715e>// library extensions
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span> <span style=color:#66d9ef>bool</span> ext_hex_float; <span style=color:#75715e>// allow hex float
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span> <span style=color:#66d9ef>bool</span> ext_num_suffix; <span style=color:#75715e>// allow number suffix
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span> <span style=color:#66d9ef>bool</span> ext_null_value; <span style=color:#75715e>// allow null value
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>};
|
||||
</span></span></code></pre></div><h2 id=member-functions-1>Member Functions
|
||||
<a class=anchor href=#member-functions-1>#</a></h2><h3 id=constructor-1>Constructor
|
||||
<a class=anchor href=#constructor-1>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>constexpr</span> <span style=color:#66d9ef>explicit</span> <span style=color:#a6e22e>spec</span>(<span style=color:#66d9ef>const</span> semantic_version<span style=color:#f92672>&</span> semver) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><p>Constructs a <code>spec</code> with the specified TOML version.</p><p>Supports TOML v1.0.0 and TOML v1.1.0.</p><h3 id=default_version><code>default_version()</code>
|
||||
<a class=anchor href=#default_version>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>constexpr</span> <span style=color:#66d9ef>static</span> spec <span style=color:#a6e22e>default_version</span>() <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><p>Constructs a <code>spec</code> with the default version.</p><p>Used as the default value for <code>toml::parse</code> and <code>toml::format</code>.</p><p>In toml11 v4.4.0, the value is v1.0.0.</p><h3 id=vmajor-minor-patch><code>v(major, minor, patch)</code>
|
||||
<a class=anchor href=#vmajor-minor-patch>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>constexpr</span> <span style=color:#66d9ef>static</span> spec <span style=color:#a6e22e>v</span>(std<span style=color:#f92672>::</span><span style=color:#66d9ef>uint32_t</span> mjr, std<span style=color:#f92672>::</span><span style=color:#66d9ef>uint32_t</span> mnr, std<span style=color:#f92672>::</span><span style=color:#66d9ef>uint32_t</span> p) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><p>Constructs a <code>spec</code> with the specified version.</p><h2 id=member-variables>Member Variables
|
||||
<a class=anchor href=#member-variables>#</a></h2><p>Each flag is automatically set to <code>true</code> when the specified version includes the corresponding feature.</p><p>You can modify these flags to change the behavior of <code>toml::parse</code> and <code>toml::format</code>.</p><blockquote class="book-hint warning"><p>Some features of TOML v1.1.0 are still under fairly lengthy discussion and may still be reverted.</p><p>If they are indeed reverted, toml11 will remove those features in a minor version upgrade or move them to a corresponding later version.</p><p>As such, any features related to future versions should be considered unstable.</p></blockquote><h3 id=example>Example
|
||||
<a class=anchor href=#example>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>auto</span> spec <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>spec<span style=color:#f92672>::</span>v(<span style=color:#ae81ff>1</span>, <span style=color:#ae81ff>0</span>, <span style=color:#ae81ff>0</span>);
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e>// Allow newlines in inline tables in addition to v1.0.0 features.
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e>// Other v1.1.0 features are not enabled.
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>spec.v1_1_0_allow_newlines_in_inline_tables <span style=color:#f92672>=</span> true;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>auto</span> input <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>parse(<span style=color:#e6db74>"input_file.toml"</span>, spec);
|
||||
</span></span></code></pre></div><h3 id=v1_1_0_allow_control_characters_in_comments><code>v1_1_0_allow_control_characters_in_comments</code>
|
||||
<a class=anchor href=#v1_1_0_allow_control_characters_in_comments>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>bool</span> v1_1_0_allow_control_characters_in_comments;
|
||||
</span></span></code></pre></div><p>Allows most control characters in comments.</p><p>Added in TOML v1.1.0.</p><h3 id=v1_1_0_allow_newlines_in_inline_tables><code>v1_1_0_allow_newlines_in_inline_tables</code>
|
||||
<a class=anchor href=#v1_1_0_allow_newlines_in_inline_tables>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>bool</span> v1_1_0_allow_newlines_in_inline_tables;
|
||||
</span></span></code></pre></div><p>Allows newlines in inline tables.</p><p>Added in TOML v1.1.0.</p><h3 id=v1_1_0_allow_trailing_comma_in_inline_tables><code>v1_1_0_allow_trailing_comma_in_inline_tables</code>
|
||||
<a class=anchor href=#v1_1_0_allow_trailing_comma_in_inline_tables>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>bool</span> v1_1_0_allow_trailing_comma_in_inline_tables;
|
||||
</span></span></code></pre></div><p>Allows trailing commas in inline tables.</p><p>Added in TOML v1.1.0.</p><h3 id=v1_1_0_add_escape_sequence_e><code>v1_1_0_add_escape_sequence_e</code>
|
||||
<a class=anchor href=#v1_1_0_add_escape_sequence_e>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>bool</span> v1_1_0_add_escape_sequence_e;
|
||||
</span></span></code></pre></div><p>Allows <code>\e</code> to represent the ESC character.</p><p>Added in TOML v1.1.0.</p><h3 id=v1_1_0_add_escape_sequence_x><code>v1_1_0_add_escape_sequence_x</code>
|
||||
<a class=anchor href=#v1_1_0_add_escape_sequence_x>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>bool</span> v1_1_0_add_escape_sequence_x;
|
||||
</span></span></code></pre></div><p>Allows <code>\xHH</code> to represent a single byte character.</p><p>Added in TOML v1.1.0.</p><h3 id=v1_1_0_make_seconds_optional><code>v1_1_0_make_seconds_optional</code>
|
||||
<a class=anchor href=#v1_1_0_make_seconds_optional>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>bool</span> v1_1_0_make_seconds_optional;
|
||||
</span></span></code></pre></div><p>Makes the seconds component in time optional.</p><p>Unspecified seconds default to <code>0</code>.</p><p>Added in TOML v1.1.0.</p><h3 id=ext_hex_float><code>ext_hex_float</code>
|
||||
<a class=anchor href=#ext_hex_float>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>bool</span> ext_hex_float;
|
||||
</span></span></code></pre></div><p>This is a language extension specific to toml11.</p><p>It is initialized to <code>false</code> regardless of the specified version.
|
||||
You must explicitly set it to <code>true</code> if you want to use it.</p><p>Allows hexadecimal representation of floating-point numbers.</p><p>The hexadecimal representation conforms to the <code>printf</code> format specifier <code>%a/%A</code>.</p><pre tabindex=0><code>hexf = 0xC0FFEEp-10
|
||||
</code></pre><p><code>toml::format</code> will format using hexadecimal notation only if the passed <code>toml::spec</code> has <code>ext_hex_float</code> set to <code>true</code>.
|
||||
If the format specifier indicates <code>hex</code> but the <code>toml::spec</code> passed to <code>toml::format</code> has <code>ext_hex_float</code> set to <code>false</code>, the hexadecimal specification is ignored, and the number is output in decimal notation with maximum precision.</p><h3 id=ext_num_suffix><code>ext_num_suffix</code>
|
||||
<a class=anchor href=#ext_num_suffix>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>bool</span> ext_num_suffix;
|
||||
</span></span></code></pre></div><p>This is a language extension specific to toml11.</p><p>It is initialized to <code>false</code> regardless of the specified version.
|
||||
You must explicitly set it to <code>true</code> if you want to use it.</p><p>Allows the addition of suffixes to decimal integers and floating-point numbers. This does not apply to hexadecimal, octal, or binary notations.</p><p>There must be an <code>_</code> separator between the number and the suffix.</p><p>The suffix cannot start with a digit to avoid confusion with the numeric part.</p><pre tabindex=0><code>distance = 10_m # valid
|
||||
distance = 10_2m # invalid
|
||||
distance = 10_2_m # valid
|
||||
</code></pre><p>The suffix is stored in the format information as <code>std::string suffix</code>.
|
||||
The <code>_</code> separating the number from the suffix is not included in the <code>suffix</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>toml<span style=color:#f92672>::</span>value distance <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>find(input, <span style=color:#e6db74>"distance"</span>);
|
||||
</span></span><span style=display:flex><span>assert(distance.as_integer_fmt().suffix <span style=color:#f92672>==</span> std<span style=color:#f92672>::</span>string(<span style=color:#e6db74>"m"</span>));
|
||||
</span></span></code></pre></div><p><code>toml::format</code> will format the value with the suffix only if the passed <code>toml::spec</code> has <code>ext_num_suffix</code> set to <code>true</code>.</p><p>The <code>suffix</code> follows the grammar defined as:</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-abnf data-lang=abnf><span style=display:flex><span><span style=color:#a6e22e>non-digit-graph</span> <span style=color:#f92672>=</span> <span style=color:#66d9ef>ALPHA</span> <span style=color:#f92672>/</span> <span style=color:#a6e22e>non-ascii</span>
|
||||
</span></span><span style=display:flex><span><span style=color:#a6e22e>graph</span> <span style=color:#f92672>=</span> <span style=color:#66d9ef>ALPHA</span> <span style=color:#f92672>/</span> <span style=color:#66d9ef>DIGIT</span> <span style=color:#f92672>/</span> <span style=color:#a6e22e>non-ascii</span>
|
||||
</span></span><span style=display:flex><span><span style=color:#a6e22e>suffix</span> <span style=color:#f92672>=</span> _ <span style=color:#a6e22e>non-digit-graph</span> <span style=color:#f92672>*</span>( <span style=color:#a6e22e>graph</span> <span style=color:#f92672>/</span> ( _ <span style=color:#a6e22e>graph</span> ) )
|
||||
</span></span></code></pre></div><h3 id=ext_null_value><code>ext_null_value</code>
|
||||
<a class=anchor href=#ext_null_value>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>bool</span> ext_null_value;
|
||||
</span></span></code></pre></div><p>This is a language extension specific to toml11.</p><p>Allows the use of <code>null</code> as a value.</p><p>A <code>toml::value</code> specified as <code>null</code> will have no value, and <code>is_empty()</code> will return <code>true</code>.</p><p><code>toml::format</code> will format it as <code>null</code> only if the passed <code>toml::spec</code> has <code>ext_null_value</code> set to <code>true</code>.
|
||||
Otherwise, <code>toml::format</code> will terminate with an error.</p></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#spechpp>spec.hpp</a></li><li><a href=#tomlsemantic_version><code>toml::semantic_version</code></a><ul><li><a href=#member-functions>Member Functions</a><ul><li><a href=#constructor>Constructor</a></li></ul></li><li><a href=#non-member-functions>Non-Member Functions</a><ul><li><a href=#comparison-operators>Comparison Operators</a></li><li><a href=#stream-operator>Stream Operator</a></li><li><a href=#to_string><code>to_string</code></a></li></ul></li></ul></li><li><a href=#tomlspec><code>toml::spec</code></a><ul><li><a href=#member-functions-1>Member Functions</a><ul><li><a href=#constructor-1>Constructor</a></li><li><a href=#default_version><code>default_version()</code></a></li><li><a href=#vmajor-minor-patch><code>v(major, minor, patch)</code></a></li></ul></li><li><a href=#member-variables>Member Variables</a><ul><li><a href=#example>Example</a></li><li><a href=#v1_1_0_allow_control_characters_in_comments><code>v1_1_0_allow_control_characters_in_comments</code></a></li><li><a href=#v1_1_0_allow_newlines_in_inline_tables><code>v1_1_0_allow_newlines_in_inline_tables</code></a></li><li><a href=#v1_1_0_allow_trailing_comma_in_inline_tables><code>v1_1_0_allow_trailing_comma_in_inline_tables</code></a></li><li><a href=#v1_1_0_add_escape_sequence_e><code>v1_1_0_add_escape_sequence_e</code></a></li><li><a href=#v1_1_0_add_escape_sequence_x><code>v1_1_0_add_escape_sequence_x</code></a></li><li><a href=#v1_1_0_make_seconds_optional><code>v1_1_0_make_seconds_optional</code></a></li><li><a href=#ext_hex_float><code>ext_hex_float</code></a></li><li><a href=#ext_num_suffix><code>ext_num_suffix</code></a></li><li><a href=#ext_null_value><code>ext_null_value</code></a></li></ul></li></ul></li></ul></nav></div></aside></main></body></html>
|
||||
19
docs/reference/toml/index.html
Normal file
19
docs/reference/toml/index.html
Normal file
@@ -0,0 +1,19 @@
|
||||
<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
|
||||
toml.hpp
|
||||
#
|
||||
|
||||
toml.hpp includes all other headers.
|
||||
This allows access to all features of toml11.
|
||||
This header file and toml_fwd.hpp are located under ${TOML11_INCLUDE_DIR}/,
|
||||
while other header files are located under ${toml11_include_dir}/toml11/."><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/reference/toml/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="toml.hpp"><meta property="og:description" content="toml.hpp # toml.hpp includes all other headers.
|
||||
This allows access to all features of toml11.
|
||||
This header file and toml_fwd.hpp are located under ${TOML11_INCLUDE_DIR}/, while other header files are located under ${toml11_include_dir}/toml11/."><meta property="og:locale" content="en"><meta property="og:type" content="article"><meta property="article:section" content="docs"><title>toml.hpp | toml11</title><link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/reference/toml/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/reference/toml/ title=toml.hpp><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" crossorigin=anonymous></script></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
|
||||
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
|
||||
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
|
||||
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/reference/toml/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle>
|
||||
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle checked>
|
||||
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/ class=active>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
|
||||
</label><strong>toml.hpp</strong>
|
||||
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#tomlhpp>toml.hpp</a></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=tomlhpp>toml.hpp
|
||||
<a class=anchor href=#tomlhpp>#</a></h1><p><code>toml.hpp</code> includes all other headers.</p><p>This allows access to all features of toml11.</p><p>This header file and <code>toml_fwd.hpp</code> are located under <code>${TOML11_INCLUDE_DIR}/</code>,
|
||||
while other header files are located under <code>${toml11_include_dir}/toml11/</code>.</p></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#tomlhpp>toml.hpp</a></li></ul></nav></div></aside></main></body></html>
|
||||
21
docs/reference/toml_fwd/index.html
Normal file
21
docs/reference/toml_fwd/index.html
Normal file
@@ -0,0 +1,21 @@
|
||||
<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
|
||||
toml_fwd.hpp
|
||||
#
|
||||
|
||||
toml_fwd.hpp contains forward declarations of structures defined in toml11 and macro definitions.
|
||||
When only forward declarations of toml11 structures are needed and implementation is not required, including toml_fwd.hpp instead of toml.hpp can reduce compilation time.
|
||||
|
||||
Since this file only contains forward declarations, you cannot use toml::table, defined as toml::basic_value<toml::type_config>::table_type, and similarly defined toml::array. This is because they require the implementation of basic_value.
|
||||
|
||||
|
||||
This header file and toml.hpp are located under ${TOML11_INCLUDE_DIR}/, while other header files are located under ${TOML11_INCLUDE_DIR}/toml11/."><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/reference/toml_fwd/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="toml_fwd.hpp"><meta property="og:description" content="toml_fwd.hpp # toml_fwd.hpp contains forward declarations of structures defined in toml11 and macro definitions.
|
||||
When only forward declarations of toml11 structures are needed and implementation is not required, including toml_fwd.hpp instead of toml.hpp can reduce compilation time.
|
||||
Since this file only contains forward declarations, you cannot use toml::table, defined as toml::basic_value<toml::type_config>::table_type, and similarly defined toml::array. This is because they require the implementation of basic_value. This header file and toml.hpp are located under ${TOML11_INCLUDE_DIR}/, while other header files are located under ${TOML11_INCLUDE_DIR}/toml11/."><meta property="og:locale" content="en"><meta property="og:type" content="article"><meta property="article:section" content="docs"><title>toml_fwd.hpp | toml11</title><link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/reference/toml_fwd/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/reference/toml_fwd/ title=toml_fwd.hpp><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" crossorigin=anonymous></script></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
|
||||
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
|
||||
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
|
||||
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/reference/toml_fwd/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle>
|
||||
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle checked>
|
||||
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/ class=active>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
|
||||
</label><strong>toml_fwd.hpp</strong>
|
||||
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#toml_fwdhpp>toml_fwd.hpp</a></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=toml_fwdhpp>toml_fwd.hpp
|
||||
<a class=anchor href=#toml_fwdhpp>#</a></h1><p><code>toml_fwd.hpp</code> contains forward declarations of structures defined in toml11 and macro definitions.</p><p>When only forward declarations of toml11 structures are needed and implementation is not required, including <code>toml_fwd.hpp</code> instead of <code>toml.hpp</code> can reduce compilation time.</p><blockquote class="book-hint warning">Since this file only contains forward declarations, you cannot use <code>toml::table</code>, defined as <code>toml::basic_value<toml::type_config>::table_type</code>, and similarly defined <code>toml::array</code>. This is because they require the implementation of <code>basic_value</code>.</blockquote><p>This header file and <code>toml.hpp</code> are located under <code>${TOML11_INCLUDE_DIR}/</code>, while other header files are located under <code>${TOML11_INCLUDE_DIR}/toml11/</code>.</p></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#toml_fwdhpp>toml_fwd.hpp</a></li></ul></nav></div></aside></main></body></html>
|
||||
148
docs/reference/types/index.html
Normal file
148
docs/reference/types/index.html
Normal file
@@ -0,0 +1,148 @@
|
||||
<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
|
||||
types.hpp
|
||||
#
|
||||
|
||||
This document defines classes that specifies type information.
|
||||
|
||||
type_config
|
||||
#
|
||||
|
||||
type_config is a type that encapsulates parameters given to toml::basic_value.
|
||||
When using different types within toml::basic_value<T>, you need to define and pass this type separately.
|
||||
All elements listed are required.
|
||||
If you use numerical types that cannot use standard stream operators, define and replace the equivalents for read_int and read_float.
|
||||
namespace toml
|
||||
{
|
||||
struct type_config
|
||||
{
|
||||
using comment_type = preserve_comments;
|
||||
|
||||
using boolean_type = bool;
|
||||
using integer_type = std::int64_t;
|
||||
using floating_type = double;
|
||||
using string_type = std::string;
|
||||
|
||||
template<typename T>
|
||||
using array_type = std::vector<T>;
|
||||
template<typename K, typename T>
|
||||
using table_type = std::unordered_map<K, T>;
|
||||
|
||||
static result<integer_type, error_info>
|
||||
parse_int(const std::string& str, const source_location src, const std::uint8_t base);
|
||||
|
||||
static result<floating_type, error_info>
|
||||
parse_float(const std::string& str, const source_location src, const bool is_hex);
|
||||
};
|
||||
|
||||
using value = basic_value<type_config>;
|
||||
using table = typename value::table_type;
|
||||
using array = typename value::array_type;
|
||||
|
||||
} // toml
|
||||
|
||||
static Member Functions
|
||||
#
|
||||
|
||||
|
||||
parse_int(str, src, base)
|
||||
#
|
||||
|
||||
static result<integer_type, error_info>
|
||||
parse_int(const std::string& str, const source_location src, const std::uint8_t base);
|
||||
If you use a type as integer_type that cannot utilize standard stream operators, implement this function.
|
||||
Otherwise, use read_int described later."><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/reference/types/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="types.hpp"><meta property="og:description" content="types.hpp # This document defines classes that specifies type information.
|
||||
type_config # type_config is a type that encapsulates parameters given to toml::basic_value.
|
||||
When using different types within toml::basic_value<T>, you need to define and pass this type separately. All elements listed are required.
|
||||
If you use numerical types that cannot use standard stream operators, define and replace the equivalents for read_int and read_float.
|
||||
namespace toml { struct type_config { using comment_type = preserve_comments; using boolean_type = bool; using integer_type = std::int64_t; using floating_type = double; using string_type = std::string; template<typename T> using array_type = std::vector<T>; template<typename K, typename T> using table_type = std::unordered_map<K, T>; static result<integer_type, error_info> parse_int(const std::string& str, const source_location src, const std::uint8_t base); static result<floating_type, error_info> parse_float(const std::string& str, const source_location src, const bool is_hex); }; using value = basic_value<type_config>; using table = typename value::table_type; using array = typename value::array_type; } // toml static Member Functions # parse_int(str, src, base) # static result<integer_type, error_info> parse_int(const std::string& str, const source_location src, const std::uint8_t base); If you use a type as integer_type that cannot utilize standard stream operators, implement this function. Otherwise, use read_int described later."><meta property="og:locale" content="en"><meta property="og:type" content="article"><meta property="article:section" content="docs"><title>types.hpp | toml11</title><link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/reference/types/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/reference/types/ title=types.hpp><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" crossorigin=anonymous></script></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
|
||||
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
|
||||
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
|
||||
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/reference/types/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle>
|
||||
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle checked>
|
||||
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/ class=active>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
|
||||
</label><strong>types.hpp</strong>
|
||||
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#typeshpp>types.hpp</a></li><li><a href=#type_config><code>type_config</code></a><ul><li><a href=#static-member-functions><code>static</code> Member Functions</a><ul><li><a href=#parse_intstr-src-base><code>parse_int(str, src, base)</code></a></li><li><a href=#parse_floatstr-src-is_hex><code>parse_float(str, src, is_hex)</code></a></li></ul></li><li><a href=#non-member-functions>Non-member Functions</a><ul><li><a href=#read_int><code>read_int</code></a></li><li><a href=#read_float><code>read_float</code></a></li></ul></li></ul></li><li><a href=#ordered_type_config><code>ordered_type_config</code></a></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=typeshpp>types.hpp
|
||||
<a class=anchor href=#typeshpp>#</a></h1><p>This document defines classes that specifies type information.</p><h1 id=type_config><code>type_config</code>
|
||||
<a class=anchor href=#type_config>#</a></h1><p><code>type_config</code> is a type that encapsulates parameters given to <code>toml::basic_value</code>.</p><p>When using different types within <code>toml::basic_value<T></code>, you need to define and pass this type separately.
|
||||
All elements listed are required.</p><p>If you use numerical types that cannot use standard stream operators, define and replace the equivalents for <code>read_int</code> and <code>read_float</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>type_config</span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> comment_type <span style=color:#f92672>=</span> preserve_comments;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> boolean_type <span style=color:#f92672>=</span> <span style=color:#66d9ef>bool</span>;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> integer_type <span style=color:#f92672>=</span> std<span style=color:#f92672>::</span><span style=color:#66d9ef>int64_t</span>;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> floating_type <span style=color:#f92672>=</span> <span style=color:#66d9ef>double</span>;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> string_type <span style=color:#f92672>=</span> std<span style=color:#f92672>::</span>string;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> array_type <span style=color:#f92672>=</span> std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>T<span style=color:#f92672>></span>;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> K, <span style=color:#66d9ef>typename</span> T<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> table_type <span style=color:#f92672>=</span> std<span style=color:#f92672>::</span>unordered_map<span style=color:#f92672><</span>K, T<span style=color:#f92672>></span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>static</span> result<span style=color:#f92672><</span>integer_type, error_info<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> parse_int(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> str, <span style=color:#66d9ef>const</span> source_location src, <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span><span style=color:#66d9ef>uint8_t</span> base);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>static</span> result<span style=color:#f92672><</span>floating_type, error_info<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> parse_float(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> str, <span style=color:#66d9ef>const</span> source_location src, <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>bool</span> is_hex);
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>using</span> value <span style=color:#f92672>=</span> basic_value<span style=color:#f92672><</span>type_config<span style=color:#f92672>></span>;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>using</span> table <span style=color:#f92672>=</span> <span style=color:#66d9ef>typename</span> value<span style=color:#f92672>::</span>table_type;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>using</span> array <span style=color:#f92672>=</span> <span style=color:#66d9ef>typename</span> value<span style=color:#f92672>::</span>array_type;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span>} <span style=color:#75715e>// toml
|
||||
</span></span></span></code></pre></div><h2 id=static-member-functions><code>static</code> Member Functions
|
||||
<a class=anchor href=#static-member-functions>#</a></h2><h3 id=parse_intstr-src-base><code>parse_int(str, src, base)</code>
|
||||
<a class=anchor href=#parse_intstr-src-base>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>static</span> result<span style=color:#f92672><</span>integer_type, error_info<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>parse_int(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> str, <span style=color:#66d9ef>const</span> source_location src, <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span><span style=color:#66d9ef>uint8_t</span> base);
|
||||
</span></span></code></pre></div><p>If you use a type as <code>integer_type</code> that cannot utilize standard stream operators, implement this function.
|
||||
Otherwise, use <code>read_int</code> described later.</p><p>The <code>str</code> parameter receives a string with prefixes, leading zeros, and underscores removed.</p><p>The <code>src</code> parameter receives a <code>source_location</code> pointing to where the string was defined.</p><p>The <code>base</code> parameter receives one of <code>10</code>, <code>2</code>, <code>8</code>, or <code>16</code>.</p><h3 id=parse_floatstr-src-is_hex><code>parse_float(str, src, is_hex)</code>
|
||||
<a class=anchor href=#parse_floatstr-src-is_hex>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>static</span> result<span style=color:#f92672><</span>floating_type, error_info<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>parse_float(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> str, <span style=color:#66d9ef>const</span> source_location src, <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>bool</span> is_hex);
|
||||
</span></span></code></pre></div><p>If you use a type as <code>floating_type</code> that cannot utilize standard stream operators, implement this function.
|
||||
Otherwise, use <code>read_float</code> described later.</p><p>The <code>str</code> parameter receives a string with prefixes, leading zeros, and underscores removed.</p><p>The <code>src</code> parameter receives a <code>source_location</code> pointing to where the string was defined.</p><p>The <code>is_hex</code> parameter indicates whether the format is <code>hexfloat</code>. If you don’t use the <code>hexfloat</code> extension, you don’t need to implement this.</p><p>For details on the <code>hexfloat</code> extension, refer to <a href=https://toruniina.github.io/toml11/docs/reference/spec/>spec.hpp</a>.</p><h2 id=non-member-functions>Non-member Functions
|
||||
<a class=anchor href=#non-member-functions>#</a></h2><h3 id=read_int><code>read_int</code>
|
||||
<a class=anchor href=#read_int>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>result<span style=color:#f92672><</span>T, error_info<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>read_int(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> str, <span style=color:#66d9ef>const</span> source_location src, <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span><span style=color:#66d9ef>uint8_t</span> base);
|
||||
</span></span></code></pre></div><p>This is the default function used. It parses using <code>std::istringstream</code>.</p><p>If <code>operator>></code> and manipulators like <code>std::hex</code>, and <code>std::numeric_limits<T></code> are defined (such as for <code>boost::multiprecision</code>), you can use this without modifications.</p><h3 id=read_float><code>read_float</code>
|
||||
<a class=anchor href=#read_float>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>result<span style=color:#f92672><</span>T, error_info<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>read_float(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> str, <span style=color:#66d9ef>const</span> source_location src, <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>bool</span> is_hex);
|
||||
</span></span></code></pre></div><p>This is the default function used. It parses decimals using <code>std::istringstream</code> and hexfloats using <code>sscanf()</code>.</p><p>It supports <code>double</code> and <code>float</code>.</p><p>For other types, if <code>operator>></code> is defined and <code>hex</code> is not used, you can use this function.</p><h1 id=ordered_type_config><code>ordered_type_config</code>
|
||||
<a class=anchor href=#ordered_type_config>#</a></h1><p><code>ordered_type_config</code> is a variation of <code>toml::type_config</code> where the table type is replaced with <code>toml::ordered_map</code>.
|
||||
Additionally, it defines the <code>toml::ordered_value</code> alias.</p><p>Other than these changes, it is identical to <code>type_config</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>ordered_type_config</span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> comment_type <span style=color:#f92672>=</span> preserve_comments;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> boolean_type <span style=color:#f92672>=</span> <span style=color:#66d9ef>bool</span>;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> integer_type <span style=color:#f92672>=</span> std<span style=color:#f92672>::</span><span style=color:#66d9ef>int64_t</span>;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> floating_type <span style=color:#f92672>=</span> <span style=color:#66d9ef>double</span>;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> string_type <span style=color:#f92672>=</span> std<span style=color:#f92672>::</span>string;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> array_type <span style=color:#f92672>=</span> std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>T<span style=color:#f92672>></span>;
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> K, <span style=color:#66d9ef>typename</span> T<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>using</span> table_type <span style=color:#f92672>=</span> ordered_map<span style=color:#f92672><</span>K, T<span style=color:#f92672>></span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>static</span> result<span style=color:#f92672><</span>integer_type, error_info<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> parse_int(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> str, <span style=color:#66d9ef>const</span> source_location src, <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span><span style=color:#66d9ef>uint8_t</span> base)
|
||||
</span></span><span style=display:flex><span> {
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> read_int<span style=color:#f92672><</span>integer_type<span style=color:#f92672>></span>(str, src, base);
|
||||
</span></span><span style=display:flex><span> }
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>static</span> result<span style=color:#f92672><</span>floating_type, error_info<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span> parse_float(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string<span style=color:#f92672>&</span> str, <span style=color:#66d9ef>const</span> source_location src, <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>bool</span> is_hex)
|
||||
</span></span><span style=display:flex><span> {
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> read_float<span style=color:#f92672><</span>floating_type<span style=color:#f92672>></span>(str, src, is_hex);
|
||||
</span></span><span style=display:flex><span> }
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>using</span> ordered_value <span style=color:#f92672>=</span> basic_value<span style=color:#f92672><</span>ordered_type_config<span style=color:#f92672>></span>;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>using</span> ordered_table <span style=color:#f92672>=</span> <span style=color:#66d9ef>typename</span> ordered_value<span style=color:#f92672>::</span>table_type;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>using</span> ordered_array <span style=color:#f92672>=</span> <span style=color:#66d9ef>typename</span> ordered_value<span style=color:#f92672>::</span>array_type;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span>} <span style=color:#75715e>// toml
|
||||
</span></span></span></code></pre></div></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#typeshpp>types.hpp</a></li><li><a href=#type_config><code>type_config</code></a><ul><li><a href=#static-member-functions><code>static</code> Member Functions</a><ul><li><a href=#parse_intstr-src-base><code>parse_int(str, src, base)</code></a></li><li><a href=#parse_floatstr-src-is_hex><code>parse_float(str, src, is_hex)</code></a></li></ul></li><li><a href=#non-member-functions>Non-member Functions</a><ul><li><a href=#read_int><code>read_int</code></a></li><li><a href=#read_float><code>read_float</code></a></li></ul></li></ul></li><li><a href=#ordered_type_config><code>ordered_type_config</code></a></li></ul></nav></div></aside></main></body></html>
|
||||
439
docs/reference/value/index.html
Normal file
439
docs/reference/value/index.html
Normal file
@@ -0,0 +1,439 @@
|
||||
<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
|
||||
value.hpp
|
||||
#
|
||||
|
||||
value.hpp defines basic_value.
|
||||
|
||||
toml::basic_value
|
||||
#
|
||||
|
||||
basic_value is a class that stores TOML values.
|
||||
namespace toml
|
||||
{
|
||||
template <class TypeConfig>
|
||||
class basic_value;
|
||||
|
||||
// Defined in types.hpp
|
||||
// using value = basic_value<type_config>;
|
||||
// using table = typename basic_value<type_config>::table_type;
|
||||
// using array = typename basic_value<type_config>::array_type;
|
||||
|
||||
template<typename TC>
|
||||
bool operator==(const basic_value<TC>&, const basic_value<TC>&);
|
||||
template<typename TC>
|
||||
bool operator!=(const basic_value<TC>&, const basic_value<TC>&);
|
||||
template<typename TC>
|
||||
bool operator< (const basic_value<TC>&, const basic_value<TC>&);
|
||||
template<typename TC>
|
||||
bool operator<=(const basic_value<TC>&, const basic_value<TC>&);
|
||||
template<typename TC>
|
||||
bool operator> (const basic_value<TC>&, const basic_value<TC>&);
|
||||
template<typename TC>
|
||||
bool operator>=(const basic_value<TC>&, const basic_value<TC>&);
|
||||
} //toml
|
||||
|
||||
Member Types
|
||||
#
|
||||
|
||||
The following member types are defined."><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/reference/value/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="value.hpp"><meta property="og:description" content="value.hpp # value.hpp defines basic_value.
|
||||
toml::basic_value # basic_value is a class that stores TOML values.
|
||||
namespace toml { template <class TypeConfig> class basic_value; // Defined in types.hpp // using value = basic_value<type_config>; // using table = typename basic_value<type_config>::table_type; // using array = typename basic_value<type_config>::array_type; template<typename TC> bool operator==(const basic_value<TC>&, const basic_value<TC>&); template<typename TC> bool operator!=(const basic_value<TC>&, const basic_value<TC>&); template<typename TC> bool operator< (const basic_value<TC>&, const basic_value<TC>&); template<typename TC> bool operator<=(const basic_value<TC>&, const basic_value<TC>&); template<typename TC> bool operator> (const basic_value<TC>&, const basic_value<TC>&); template<typename TC> bool operator>=(const basic_value<TC>&, const basic_value<TC>&); } //toml Member Types # The following member types are defined."><meta property="og:locale" content="en"><meta property="og:type" content="article"><meta property="article:section" content="docs"><title>value.hpp | toml11</title><link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/reference/value/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/reference/value/ title=value.hpp><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" crossorigin=anonymous></script></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
|
||||
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
|
||||
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
|
||||
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/reference/value/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle>
|
||||
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle checked>
|
||||
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/ class=active>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
|
||||
</label><strong>value.hpp</strong>
|
||||
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#valuehpp>value.hpp</a></li><li><a href=#tomlbasic_value><code>toml::basic_value</code></a><ul><li><a href=#member-types>Member Types</a></li><li><a href=#member-functions>Member Functions</a><ul><li><a href=#default-constructor>Default Constructor</a></li><li><a href=#copy-and-move-constructors>Copy and Move Constructors</a></li><li><a href=#copy-and-move-constructors-with-comments>Copy and Move Constructors with Comments</a></li><li><a href=#conversion-constructors>Conversion Constructors</a></li><li><a href=#constructor-boolean>Constructor (boolean)</a></li><li><a href=#constructor-integer>Constructor (integer)</a></li><li><a href=#constructor-floating>Constructor (floating)</a></li><li><a href=#constructor-string>Constructor (string)</a></li><li><a href=#constructor-local_date>Constructor (local_date)</a></li><li><a href=#constructor-local_time>Constructor (local_time)</a></li><li><a href=#constructor-local_datetime>Constructor (local_datetime)</a></li><li><a href=#constructor-offset_datetime>Constructor (offset_datetime)</a></li><li><a href=#constructor-array>Constructor (array)</a></li><li><a href=#constructor-table>Constructor (table)</a></li><li><a href=#constructor-user-defined>Constructor (user-defined)</a></li><li><a href=#operatorbasic_value><code>operator=(basic_value)</code></a></li><li><a href=#operatort><code>operator=(T)</code></a></li><li><a href=#ist><code>is<T>()</code></a></li><li><a href=#istomlvalue_t><code>is(toml::value_t)</code></a></li><li><a href=#is_xxx><code>is_xxx()</code></a></li><li><a href=#is_empty><code>is_empty()</code></a></li><li><a href=#is_array_of_tables><code>is_array_of_tables()</code></a></li><li><a href=#type><code>type()</code></a></li><li><a href=#as_xxx><code>as_xxx()</code></a></li><li><a href=#as_xxxstdnothrow><code>as_xxx(std::nothrow)</code></a></li><li><a href=#as_xxx_fmt><code>as_xxx_fmt()</code></a></li><li><a href=#as_xxx_fmtstdnothrow><code>as_xxx_fmt(std::nothrow)</code></a></li><li><a href=#atkey><code>at(key)</code></a></li><li><a href=#countkey><code>count(key)</code></a></li><li><a href=#containskey><code>contains(key)</code></a></li><li><a href=#atidx><code>at(idx)</code></a></li><li><a href=#operatoridx><code>operator[](idx)</code></a></li><li><a href=#push_backvalue><code>push_back(value)</code></a></li><li><a href=#emplace_backargs><code>emplace_back(args...)</code></a></li><li><a href=#size><code>size()</code></a></li><li><a href=#location><code>location()</code></a></li><li><a href=#comments><code>comments()</code></a></li><li><a href=#accessed><code>accessed()</code></a></li></ul></li><li><a href=#non-member-functions>Non-Member Functions</a><ul><li><a href=#operator><code>operator==</code></a></li><li><a href=#operator-1><code>operator!=</code></a></li><li><a href=#operator-2><code>operator<</code></a></li><li><a href=#operator-3><code>operator<=</code></a></li><li><a href=#operator-4><code>operator></code></a></li><li><a href=#operator-5><code>operator>=</code></a></li></ul></li></ul></li><li><a href=#tomltype_error><code>toml::type_error</code></a></li><li><a href=#tomlmake_error_info><code>toml::make_error_info</code></a></li><li><a href=#tomlformat_error><code>toml::format_error</code></a></li><li><a href=#related>Related</a></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=valuehpp>value.hpp
|
||||
<a class=anchor href=#valuehpp>#</a></h1><p><code>value.hpp</code> defines <code>basic_value</code>.</p><h1 id=tomlbasic_value><code>toml::basic_value</code>
|
||||
<a class=anchor href=#tomlbasic_value>#</a></h1><p><code>basic_value</code> is a class that stores TOML values.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span> <span style=color:#f92672><</span><span style=color:#66d9ef>class</span> <span style=color:#a6e22e>TypeConfig</span><span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>class</span> <span style=color:#a6e22e>basic_value</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e>// Defined in types.hpp
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e>// using value = basic_value<type_config>;
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e>// using table = typename basic_value<type_config>::table_type;
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e>// using array = typename basic_value<type_config>::array_type;
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>bool</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>==</span>(<span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span>, <span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span>);
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>bool</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>!=</span>(<span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span>, <span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span>);
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>bool</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672><</span> (<span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span>, <span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span>);
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>bool</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672><=</span>(<span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span>, <span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span>);
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>bool</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>></span> (<span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span>, <span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span>);
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>bool</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>>=</span>(<span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span>, <span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span>);
|
||||
</span></span><span style=display:flex><span>} <span style=color:#75715e>//toml
|
||||
</span></span></span></code></pre></div><h2 id=member-types>Member Types
|
||||
<a class=anchor href=#member-types>#</a></h2><p>The following member types are defined.</p><p>You can modify the member types using <code>TypeConfig</code>.</p><p>See also: <a href=https://toruniina.github.io/toml11/docs/reference/types/>types.hpp</a></p><table><thead><tr><th style=text-align:left>Name</th><th style=text-align:left>Definition</th></tr></thead><tbody><tr><td style=text-align:left><code>char_type</code></td><td style=text-align:left><code>typename TypeConfig::char_type</code></td></tr><tr><td style=text-align:left><code>key_type</code></td><td style=text-align:left><code>typename TypeConfig::string_type</code></td></tr><tr><td style=text-align:left><code>value_type</code></td><td style=text-align:left><code>basic_value<TypeConfig></code></td></tr><tr><td style=text-align:left><code>boolean_type</code></td><td style=text-align:left><code>typename TypeConfig::boolean_type</code></td></tr><tr><td style=text-align:left><code>integer_type</code></td><td style=text-align:left><code>typename TypeConfig::integer_type</code></td></tr><tr><td style=text-align:left><code>floating_type</code></td><td style=text-align:left><code>typename TypeConfig::floating_type</code></td></tr><tr><td style=text-align:left><code>string_type</code></td><td style=text-align:left><code>typename TypeConfig::string_type</code></td></tr><tr><td style=text-align:left><code>local_time_type</code></td><td style=text-align:left><code>toml::local_time</code></td></tr><tr><td style=text-align:left><code>local_date_type</code></td><td style=text-align:left><code>toml::local_date</code></td></tr><tr><td style=text-align:left><code>local_datetime_type</code></td><td style=text-align:left><code>toml::local_datetime</code></td></tr><tr><td style=text-align:left><code>offset_datetime_type</code></td><td style=text-align:left><code>toml::offset_datetime</code></td></tr><tr><td style=text-align:left><code>array_type</code></td><td style=text-align:left><code>typename TypeConfig::template array_type<value_type></code></td></tr><tr><td style=text-align:left><code>table_type</code></td><td style=text-align:left><code>typename TypeConfig::template table_type<key_type, value_type></code></td></tr><tr><td style=text-align:left><code>comment_type</code></td><td style=text-align:left><code>typename TypeConfig::comment_type</code></td></tr></tbody></table><h2 id=member-functions>Member Functions
|
||||
<a class=anchor href=#member-functions>#</a></h2><h3 id=default-constructor>Default Constructor
|
||||
<a class=anchor href=#default-constructor>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>basic_value() <span style=color:#66d9ef>noexcept</span>
|
||||
</span></span></code></pre></div><p>Constructs an empty <code>toml::value</code>.</p><p>The constructed <code>toml::value</code> will be empty.</p><h3 id=copy-and-move-constructors>Copy and Move Constructors
|
||||
<a class=anchor href=#copy-and-move-constructors>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>basic_value(<span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672>&</span> v)
|
||||
</span></span><span style=display:flex><span>basic_value(basic_value<span style=color:#f92672>&&</span> v)
|
||||
</span></span></code></pre></div><p>Copies or moves all information including values, format information, comments, and file regions.</p><h3 id=copy-and-move-constructors-with-comments>Copy and Move Constructors with Comments
|
||||
<a class=anchor href=#copy-and-move-constructors-with-comments>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>basic_value(basic_value v, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> com)
|
||||
</span></span></code></pre></div><p>Copies or moves the object while overwriting comments.</p><h3 id=conversion-constructors>Conversion Constructors
|
||||
<a class=anchor href=#conversion-constructors>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TI<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value(basic_value<span style=color:#f92672><</span>TI<span style=color:#f92672>></span> other)
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TI<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value(basic_value<span style=color:#f92672><</span>TI<span style=color:#f92672>></span> other, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> com)
|
||||
</span></span></code></pre></div><p>Copies or moves from a <code>basic_value</code> with a different <code>type_config</code>.</p><h3 id=constructor-boolean>Constructor (boolean)
|
||||
<a class=anchor href=#constructor-boolean>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>basic_value(boolean_type x)
|
||||
</span></span><span style=display:flex><span>basic_value(boolean_type x, boolean_format_info fmt)
|
||||
</span></span><span style=display:flex><span>basic_value(boolean_type x, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> com)
|
||||
</span></span><span style=display:flex><span>basic_value(boolean_type x, boolean_format_info fmt, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> com)
|
||||
</span></span></code></pre></div><p>Constructs an object with a <code>bool</code>, its format information, and comments.</p><h3 id=constructor-integer>Constructor (integer)
|
||||
<a class=anchor href=#constructor-integer>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#75715e>/* std::is_integral<T> is true */</span><span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value(T x)
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#75715e>/* std::is_integral<T> is true */</span><span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value(T x, integer_format_info fmt)
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#75715e>/* std::is_integral<T> is true */</span><span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value(T x, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> com)
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#75715e>/* std::is_integral<T> is true */</span><span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value(T x, integer_format_info fmt, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> com)
|
||||
</span></span></code></pre></div><p>Constructs an object with an <code>integer</code>, its format information, and comments.</p><h3 id=constructor-floating>Constructor (floating)
|
||||
<a class=anchor href=#constructor-floating>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#75715e>/* std::is_floating_point<T> is true */</span><span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value(T x)
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#75715e>/* std::is_floating_point<T> is true */</span><span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value(T x, floating_format_info fmt)
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#75715e>/* std::is_floating_point<T> is true */</span><span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value(T x, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> com)
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#75715e>/* std::is_floating_point<T> is true */</span><span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value(T x, floating_format_info fmt, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> com)
|
||||
</span></span></code></pre></div><p>Constructs an object with a <code>floating</code> point number, its format information, and comments.</p><h3 id=constructor-string>Constructor (string)
|
||||
<a class=anchor href=#constructor-string>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>basic_value(string_type x)
|
||||
</span></span><span style=display:flex><span>basic_value(string_type x, string_format_info fmt)
|
||||
</span></span><span style=display:flex><span>basic_value(string_type x, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> com)
|
||||
</span></span><span style=display:flex><span>basic_value(string_type x, string_format_info fmt, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> com)
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span>basic_value(<span style=color:#66d9ef>const</span> string_type<span style=color:#f92672>::</span>value_type<span style=color:#f92672>*</span> x)
|
||||
</span></span><span style=display:flex><span>basic_value(<span style=color:#66d9ef>const</span> string_type<span style=color:#f92672>::</span>value_type<span style=color:#f92672>*</span> x, string_format_info fmt)
|
||||
</span></span><span style=display:flex><span>basic_value(<span style=color:#66d9ef>const</span> string_type<span style=color:#f92672>::</span>value_type<span style=color:#f92672>*</span> x, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> com)
|
||||
</span></span><span style=display:flex><span>basic_value(<span style=color:#66d9ef>const</span> string_type<span style=color:#f92672>::</span>value_type<span style=color:#f92672>*</span> x, string_format_info fmt, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> com)
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e>// C++17以降
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>basic_value(string_view_type x)
|
||||
</span></span><span style=display:flex><span>basic_value(string_view_type x, string_format_info fmt)
|
||||
</span></span><span style=display:flex><span>basic_value(string_view_type x, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> com)
|
||||
</span></span><span style=display:flex><span>basic_value(string_view_type x, string_format_info fmt, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> com)
|
||||
</span></span></code></pre></div><p>Constructs an object with a <code>string</code>, its format information, and comments.</p><p><code>string_view_type</code> shares the same <code>value_type</code> and <code>traits_type</code> as <code>string_type</code>.</p><h3 id=constructor-local_date>Constructor (local_date)
|
||||
<a class=anchor href=#constructor-local_date>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>basic_value(local_date_type x)
|
||||
</span></span><span style=display:flex><span>basic_value(local_date_type x, local_date_format_info fmt)
|
||||
</span></span><span style=display:flex><span>basic_value(local_date_type x, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> com)
|
||||
</span></span><span style=display:flex><span>basic_value(local_date_type x, local_date_format_info fmt, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> com)
|
||||
</span></span></code></pre></div><p>Constructs an object with a <code>local_date_type</code>, its format information, and comments.</p><h3 id=constructor-local_time>Constructor (local_time)
|
||||
<a class=anchor href=#constructor-local_time>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>basic_value(local_time_type x)
|
||||
</span></span><span style=display:flex><span>basic_value(local_time_type x, local_time_format_info fmt)
|
||||
</span></span><span style=display:flex><span>basic_value(local_time_type x, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> com)
|
||||
</span></span><span style=display:flex><span>basic_value(local_time_type x, local_time_format_info fmt, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> com)
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> Rep, <span style=color:#66d9ef>typename</span> Period<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>chrono<span style=color:#f92672>::</span>duration<span style=color:#f92672><</span>Rep, Period<span style=color:#f92672>>&</span> x)
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> Rep, <span style=color:#66d9ef>typename</span> Period<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>chrono<span style=color:#f92672>::</span>duration<span style=color:#f92672><</span>Rep, Period<span style=color:#f92672>>&</span> x, local_time_format_info fmt)
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> Rep, <span style=color:#66d9ef>typename</span> Period<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>chrono<span style=color:#f92672>::</span>duration<span style=color:#f92672><</span>Rep, Period<span style=color:#f92672>>&</span> x, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> com)
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> Rep, <span style=color:#66d9ef>typename</span> Period<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>chrono<span style=color:#f92672>::</span>duration<span style=color:#f92672><</span>Rep, Period<span style=color:#f92672>>&</span> x, local_time_format_info fmt, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> com)
|
||||
</span></span></code></pre></div><p>Constructs an object with a <code>local_time_type</code>, its format information, and comments.</p><p>For <code>std::chrono::duration</code>, constructs as a time span from <code>00:00:00</code>.</p><h3 id=constructor-local_datetime>Constructor (local_datetime)
|
||||
<a class=anchor href=#constructor-local_datetime>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>basic_value(local_datetime_type x)
|
||||
</span></span><span style=display:flex><span>basic_value(local_datetime_type x, local_date_format_info fmt)
|
||||
</span></span><span style=display:flex><span>basic_value(local_datetime_type x, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> com)
|
||||
</span></span><span style=display:flex><span>basic_value(local_datetime_type x, local_date_format_info fmt, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> com)
|
||||
</span></span></code></pre></div><p>Constructs an object with a <code>local_datetime_type</code>, its format information, and comments.</p><h3 id=constructor-offset_datetime>Constructor (offset_datetime)
|
||||
<a class=anchor href=#constructor-offset_datetime>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>basic_value(offset_datetime_type x)
|
||||
</span></span><span style=display:flex><span>basic_value(offset_datetime_type x, offset_date_format_info fmt)
|
||||
</span></span><span style=display:flex><span>basic_value(offset_datetime_type x, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> com)
|
||||
</span></span><span style=display:flex><span>basic_value(offset_datetime_type x, offset_date_format_info fmt, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> com)
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span>basic_value(std<span style=color:#f92672>::</span>chrono<span style=color:#f92672>::</span>system_clock<span style=color:#f92672>::</span>time_point x)
|
||||
</span></span><span style=display:flex><span>basic_value(std<span style=color:#f92672>::</span>chrono<span style=color:#f92672>::</span>system_clock<span style=color:#f92672>::</span>time_point x, offset_date_format_info fmt)
|
||||
</span></span><span style=display:flex><span>basic_value(std<span style=color:#f92672>::</span>chrono<span style=color:#f92672>::</span>system_clock<span style=color:#f92672>::</span>time_point x, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> com)
|
||||
</span></span><span style=display:flex><span>basic_value(std<span style=color:#f92672>::</span>chrono<span style=color:#f92672>::</span>system_clock<span style=color:#f92672>::</span>time_point x, offset_date_format_info fmt, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> com)
|
||||
</span></span></code></pre></div><p>Constructs an object with an <code>offset_datetime_type</code>, its format information, and comments.</p><p>For <code>std::chrono::system_clock::time_point</code>, constructs for the pointed time.</p><h3 id=constructor-array>Constructor (array)
|
||||
<a class=anchor href=#constructor-array>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>basic_value(array_type x)
|
||||
</span></span><span style=display:flex><span>basic_value(array_type x, integer_format_info fmt)
|
||||
</span></span><span style=display:flex><span>basic_value(array_type x, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> com)
|
||||
</span></span><span style=display:flex><span>basic_value(array_type x, integer_format_info fmt, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> com)
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#75715e>/* T is array-like */</span><span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value(T x)
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#75715e>/* T is array-like */</span><span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value(T x, array_format_info fmt)
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#75715e>/* T is array-like */</span><span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value(T x, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> com)
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#75715e>/* T is array-like */</span><span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value(T x, array_format_info fmt, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> com)
|
||||
</span></span></code></pre></div><p>Constructs an object with an <code>array</code>, its format information, and comments.</p><p><code>array-like</code> types must meet the following criteria:</p><ul><li>Has <code>T::iterator</code>.</li><li>Has <code>T::value_type</code>.</li><li>Does <strong>not</strong> have <code>T::key_type</code>.</li><li>Does <strong>not</strong> have <code>T::mapped_type</code>.</li><li>Is <strong>not</strong> <code>std::string</code>.</li><li>Is <strong>not</strong> <code>std::string_view</code> (since C++17).</li></ul><h3 id=constructor-table>Constructor (table)
|
||||
<a class=anchor href=#constructor-table>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>basic_value(table_type x)
|
||||
</span></span><span style=display:flex><span>basic_value(table_type x, integer_format_info fmt)
|
||||
</span></span><span style=display:flex><span>basic_value(table_type x, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> com)
|
||||
</span></span><span style=display:flex><span>basic_value(table_type x, integer_format_info fmt, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> com)
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#75715e>/* T is table-like */</span><span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value(T x)
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#75715e>/* T is table-like */</span><span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value(T x, table_format_info fmt)
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#75715e>/* T is table-like */</span><span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value(T x, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> com)
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T, <span style=color:#75715e>/* T is table-like */</span><span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value(T x, table_format_info fmt, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> com)
|
||||
</span></span></code></pre></div><p>Constructs an object with a <code>table</code>, its format information, and comments.</p><p><code>table-like</code> types must meet the following criteria:</p><ul><li>Has <code>T::iterator</code>.</li><li>Has <code>T::value_type</code>.</li><li>Has <code>T::key_type</code>.</li><li>Has <code>T::mapped_type</code>.</li></ul><h3 id=constructor-user-defined>Constructor (user-defined)
|
||||
<a class=anchor href=#constructor-user-defined>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T <span style=color:#75715e>/* toml::into<T> is defined */</span><span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value(<span style=color:#66d9ef>const</span> T<span style=color:#f92672>&</span> ud);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T <span style=color:#75715e>/* toml::into<T> is defined */</span><span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value(<span style=color:#66d9ef>const</span> T<span style=color:#f92672>&</span> ud, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> com);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T <span style=color:#75715e>/* toml::into<T> is not defined, but T{}.into_toml() exists */</span><span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value(<span style=color:#66d9ef>const</span> T<span style=color:#f92672>&</span> ud);
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T <span style=color:#75715e>/* toml::into<T> is not defined, but T{}.into_toml() exists */</span><span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value(<span style=color:#66d9ef>const</span> T<span style=color:#f92672>&</span> ud, std<span style=color:#f92672>::</span>vector<span style=color:#f92672><</span>std<span style=color:#f92672>::</span>string<span style=color:#f92672>></span> com);
|
||||
</span></span></code></pre></div><p>If <code>toml::into<T></code> is defined, constructs from the result of <code>toml::into<T>(ud)</code>.</p><p>If <code>toml::into<T></code> is not defined but <code>T</code> has a <code>into_toml()</code> member function, constructs from the result of <code>ud.into_toml()</code>.</p><hr><h3 id=operatorbasic_value><code>operator=(basic_value)</code>
|
||||
<a class=anchor href=#operatorbasic_value>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>basic_value<span style=color:#f92672>&</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>=</span>(<span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672>&</span> v)
|
||||
</span></span><span style=display:flex><span>basic_value<span style=color:#f92672>&</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>=</span>(basic_value<span style=color:#f92672>&&</span> v)
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TI<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value<span style=color:#f92672>&</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>=</span>(basic_value<span style=color:#f92672><</span>TI<span style=color:#f92672>></span> other)
|
||||
</span></span></code></pre></div><p>Assigns the right-hand side <code>basic_value</code> to the current object.</p><h3 id=operatort><code>operator=(T)</code>
|
||||
<a class=anchor href=#operatort>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> T<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>basic_value<span style=color:#f92672>&</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>=</span>(T x)
|
||||
</span></span></code></pre></div><p>Assigns a value corresponding to <code>T</code>.</p><p>The contents pointed to by <code>source_location</code> are discarded.</p><p>If the object already holds a value of the same type, the original format information is retained.</p><hr><h3 id=ist><code>is<T>()</code>
|
||||
<a class=anchor href=#ist>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>bool</span> is<span style=color:#f92672><</span>T<span style=color:#f92672>></span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>
|
||||
</span></span></code></pre></div><h4 id=requirements>Requirements
|
||||
<a class=anchor href=#requirements>#</a></h4><p><code>T</code> must be an exact TOML type, meaning it corresponds to one of the <code>toml::value::xxx_type</code>.</p><h4 id=return-value>Return Value
|
||||
<a class=anchor href=#return-value>#</a></h4><p>Returns <code>true</code> if the stored type matches <code>T</code>, otherwise returns <code>false</code>.</p><hr><h3 id=istomlvalue_t><code>is(toml::value_t)</code>
|
||||
<a class=anchor href=#istomlvalue_t>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>bool</span> is(toml<span style=color:#f92672>::</span>value_t t) <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>
|
||||
</span></span></code></pre></div><h4 id=return-value-1>Return Value
|
||||
<a class=anchor href=#return-value-1>#</a></h4><p>Returns <code>true</code> if the tag of the stored type matches <code>t</code>, otherwise returns <code>false</code>.</p><hr><h3 id=is_xxx><code>is_xxx()</code>
|
||||
<a class=anchor href=#is_xxx>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>bool</span> <span style=color:#a6e22e>is_boolean</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>bool</span> <span style=color:#a6e22e>is_integer</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>bool</span> <span style=color:#a6e22e>is_floating</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>bool</span> <span style=color:#a6e22e>is_string</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>bool</span> <span style=color:#a6e22e>is_offset_datetime</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>bool</span> <span style=color:#a6e22e>is_local_datetime</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>bool</span> <span style=color:#a6e22e>is_local_date</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>bool</span> <span style=color:#a6e22e>is_local_time</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>bool</span> <span style=color:#a6e22e>is_array</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>bool</span> <span style=color:#a6e22e>is_table</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><h4 id=return-value-2>Return Value
|
||||
<a class=anchor href=#return-value-2>#</a></h4><p>Returns <code>true</code> if the stored type matches the corresponding type, otherwise returns <code>false</code>.</p><hr><h3 id=is_empty><code>is_empty()</code>
|
||||
<a class=anchor href=#is_empty>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>bool</span> <span style=color:#a6e22e>is_empty</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><h4 id=return-value-3>Return Value
|
||||
<a class=anchor href=#return-value-3>#</a></h4><p>Returns <code>true</code> if the object is default constructed and no value is assigned, otherwise returns <code>false</code>.</p><h3 id=is_array_of_tables><code>is_array_of_tables()</code>
|
||||
<a class=anchor href=#is_array_of_tables>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>bool</span> <span style=color:#a6e22e>is_array_of_tables</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><h4 id=return-value-4>Return Value
|
||||
<a class=anchor href=#return-value-4>#</a></h4><p>Returns <code>true</code> if the stored type is an array that is not empty and all elements are tables, otherwise returns <code>false</code>.</p><hr><h3 id=type><code>type()</code>
|
||||
<a class=anchor href=#type>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>toml<span style=color:#f92672>::</span>value_t type() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>
|
||||
</span></span></code></pre></div><h4 id=return-value-5>Return Value
|
||||
<a class=anchor href=#return-value-5>#</a></h4><p>Returns the tag corresponding to the stored type.</p><hr><h3 id=as_xxx><code>as_xxx()</code>
|
||||
<a class=anchor href=#as_xxx>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>boolean_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_boolean () <span style=color:#66d9ef>const</span>;
|
||||
</span></span><span style=display:flex><span>integer_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_integer () <span style=color:#66d9ef>const</span>;
|
||||
</span></span><span style=display:flex><span>floating_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_floating () <span style=color:#66d9ef>const</span>;
|
||||
</span></span><span style=display:flex><span>string_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_string () <span style=color:#66d9ef>const</span>;
|
||||
</span></span><span style=display:flex><span>offset_datetime_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_offset_datetime() <span style=color:#66d9ef>const</span>;
|
||||
</span></span><span style=display:flex><span>local_datetime_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_local_datetime () <span style=color:#66d9ef>const</span>;
|
||||
</span></span><span style=display:flex><span>local_date_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_local_date () <span style=color:#66d9ef>const</span>;
|
||||
</span></span><span style=display:flex><span>local_time_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_local_time () <span style=color:#66d9ef>const</span>;
|
||||
</span></span><span style=display:flex><span>array_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_array () <span style=color:#66d9ef>const</span>;
|
||||
</span></span><span style=display:flex><span>table_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_table () <span style=color:#66d9ef>const</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span>boolean_type <span style=color:#f92672>&</span> as_boolean ();
|
||||
</span></span><span style=display:flex><span>integer_type <span style=color:#f92672>&</span> as_integer ();
|
||||
</span></span><span style=display:flex><span>floating_type <span style=color:#f92672>&</span> as_floating ();
|
||||
</span></span><span style=display:flex><span>string_type <span style=color:#f92672>&</span> as_string ();
|
||||
</span></span><span style=display:flex><span>offset_datetime_type<span style=color:#f92672>&</span> as_offset_datetime();
|
||||
</span></span><span style=display:flex><span>local_datetime_type <span style=color:#f92672>&</span> as_local_datetime ();
|
||||
</span></span><span style=display:flex><span>local_date_type <span style=color:#f92672>&</span> as_local_date ();
|
||||
</span></span><span style=display:flex><span>local_time_type <span style=color:#f92672>&</span> as_local_time ();
|
||||
</span></span><span style=display:flex><span>array_type <span style=color:#f92672>&</span> as_array ();
|
||||
</span></span><span style=display:flex><span>table_type <span style=color:#f92672>&</span> as_table ();
|
||||
</span></span></code></pre></div><h4 id=return-value-6>Return Value
|
||||
<a class=anchor href=#return-value-6>#</a></h4><p>Returns a reference to the value of the specified type.</p><h4 id=exception>Exception
|
||||
<a class=anchor href=#exception>#</a></h4><p>Throws <code>toml::type_error</code> if the stored value’s type does not match the specified type.</p><hr><h3 id=as_xxxstdnothrow><code>as_xxx(std::nothrow)</code>
|
||||
<a class=anchor href=#as_xxxstdnothrow>#</a></h3><p>Invoke with a <code>std::nothrow</code> object.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>boolean_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_boolean (<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>integer_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_integer (<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>floating_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_floating (<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>string_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_string (<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>offset_datetime_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_offset_datetime(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>local_datetime_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_local_datetime (<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>local_date_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_local_date (<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>local_time_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_local_time (<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>array_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_array (<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>table_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_table (<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span>boolean_type <span style=color:#f92672>&</span> as_boolean (<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>integer_type <span style=color:#f92672>&</span> as_integer (<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>floating_type <span style=color:#f92672>&</span> as_floating (<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>string_type <span style=color:#f92672>&</span> as_string (<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>offset_datetime_type<span style=color:#f92672>&</span> as_offset_datetime(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>local_datetime_type <span style=color:#f92672>&</span> as_local_datetime (<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>local_date_type <span style=color:#f92672>&</span> as_local_date (<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>local_time_type <span style=color:#f92672>&</span> as_local_time (<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>array_type <span style=color:#f92672>&</span> as_array (<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>table_type <span style=color:#f92672>&</span> as_table (<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><h4 id=return-value-7>Return Value
|
||||
<a class=anchor href=#return-value-7>#</a></h4><p>Returns a reference to the value of the specified type.</p><h4 id=note>Note
|
||||
<a class=anchor href=#note>#</a></h4><p>If the type of the stored value does not match the specified type, the behavior is undefined.</p><hr><h3 id=as_xxx_fmt><code>as_xxx_fmt()</code>
|
||||
<a class=anchor href=#as_xxx_fmt>#</a></h3><p>Accesses format information.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>boolean_format_info <span style=color:#f92672>&</span> as_boolean_fmt ();
|
||||
</span></span><span style=display:flex><span>integer_format_info <span style=color:#f92672>&</span> as_integer_fmt ();
|
||||
</span></span><span style=display:flex><span>floating_format_info <span style=color:#f92672>&</span> as_floating_fmt ();
|
||||
</span></span><span style=display:flex><span>string_format_info <span style=color:#f92672>&</span> as_string_fmt ();
|
||||
</span></span><span style=display:flex><span>offset_datetime_format_info<span style=color:#f92672>&</span> as_offset_datetime_fmt();
|
||||
</span></span><span style=display:flex><span>local_datetime_format_info <span style=color:#f92672>&</span> as_local_datetime_fmt ();
|
||||
</span></span><span style=display:flex><span>local_date_format_info <span style=color:#f92672>&</span> as_local_date_fmt ();
|
||||
</span></span><span style=display:flex><span>local_time_format_info <span style=color:#f92672>&</span> as_local_time_fmt ();
|
||||
</span></span><span style=display:flex><span>array_format_info <span style=color:#f92672>&</span> as_array_fmt ();
|
||||
</span></span><span style=display:flex><span>table_format_info <span style=color:#f92672>&</span> as_table_fmt ();
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span>boolean_format_info <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_boolean_fmt () <span style=color:#66d9ef>const</span>;
|
||||
</span></span><span style=display:flex><span>integer_format_info <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_integer_fmt () <span style=color:#66d9ef>const</span>;
|
||||
</span></span><span style=display:flex><span>floating_format_info <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_floating_fmt () <span style=color:#66d9ef>const</span>;
|
||||
</span></span><span style=display:flex><span>string_format_info <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_string_fmt () <span style=color:#66d9ef>const</span>;
|
||||
</span></span><span style=display:flex><span>offset_datetime_format_info <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_offset_datetime_fmt() <span style=color:#66d9ef>const</span>;
|
||||
</span></span><span style=display:flex><span>local_datetime_format_info <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_local_datetime_fmt () <span style=color:#66d9ef>const</span>;
|
||||
</span></span><span style=display:flex><span>local_date_format_info <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_local_date_fmt () <span style=color:#66d9ef>const</span>;
|
||||
</span></span><span style=display:flex><span>local_time_format_info <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_local_time_fmt () <span style=color:#66d9ef>const</span>;
|
||||
</span></span><span style=display:flex><span>array_format_info <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_array_fmt () <span style=color:#66d9ef>const</span>;
|
||||
</span></span><span style=display:flex><span>table_format_info <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_table_fmt () <span style=color:#66d9ef>const</span>;
|
||||
</span></span></code></pre></div><h4 id=return-value-8>Return Value
|
||||
<a class=anchor href=#return-value-8>#</a></h4><p>Returns a reference to the structure holding the format information for the specified type.</p><h4 id=exception-1>Exception
|
||||
<a class=anchor href=#exception-1>#</a></h4><p>Throws <code>toml::type_error</code> if the stored value’s type does not match the specified type.</p><hr><h3 id=as_xxx_fmtstdnothrow><code>as_xxx_fmt(std::nothrow)</code>
|
||||
<a class=anchor href=#as_xxx_fmtstdnothrow>#</a></h3><p>Invoke with a <code>std::nothrow</code> object.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>boolean_format_info <span style=color:#f92672>&</span> as_boolean_fmt (<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>integer_format_info <span style=color:#f92672>&</span> as_integer_fmt (<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>floating_format_info <span style=color:#f92672>&</span> as_floating_fmt (<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>string_format_info <span style=color:#f92672>&</span> as_string_fmt (<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>offset_datetime_format_info<span style=color:#f92672>&</span> as_offset_datetime_fmt(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>local_datetime_format_info <span style=color:#f92672>&</span> as_local_datetime_fmt (<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>local_date_format_info <span style=color:#f92672>&</span> as_local_date_fmt (<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>local_time_format_info <span style=color:#f92672>&</span> as_local_time_fmt (<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>array_format_info <span style=color:#f92672>&</span> as_array_fmt (<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>table_format_info <span style=color:#f92672>&</span> as_table_fmt (<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span>boolean_format_info <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_boolean_fmt (<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>integer_format_info <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_integer_fmt (<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>floating_format_info <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_floating_fmt (<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>string_format_info <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_string_fmt (<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>offset_datetime_format_info <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_offset_datetime_fmt(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>local_datetime_format_info <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_local_datetime_fmt (<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>local_date_format_info <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_local_date_fmt (<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>local_time_format_info <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_local_time_fmt (<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>array_format_info <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_array_fmt (<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>table_format_info <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> as_table_fmt (<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>nothrow_t<span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><h4 id=return-value-9>Return Value
|
||||
<a class=anchor href=#return-value-9>#</a></h4><p>Returns a reference to the structure holding the format information for the specified type.</p><h4 id=note-1>Note
|
||||
<a class=anchor href=#note-1>#</a></h4><p>If the type of the stored value does not match the specified type, the behavior is undefined.</p><hr><h3 id=atkey><code>at(key)</code>
|
||||
<a class=anchor href=#atkey>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>value_type<span style=color:#f92672>&</span> at(<span style=color:#66d9ef>const</span> key_type<span style=color:#f92672>&</span> key);
|
||||
</span></span><span style=display:flex><span>value_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> at(<span style=color:#66d9ef>const</span> key_type<span style=color:#f92672>&</span> key) <span style=color:#66d9ef>const</span>;
|
||||
</span></span></code></pre></div><h4 id=return-value-10>Return Value
|
||||
<a class=anchor href=#return-value-10>#</a></h4><p>Casts the current <code>value</code> to a <code>table</code> and returns the element specified by <code>key</code>.</p><h4 id=exception-2>Exception
|
||||
<a class=anchor href=#exception-2>#</a></h4><p>Throws <code>toml::type_error</code> if the stored value is not a <code>table</code>.</p><p>Throws <code>std::out_of_range</code> if the <code>table</code> does not contain the specified element.</p><hr><h4 id=operatorkey><code>operator[](key)</code>
|
||||
<a class=anchor href=#operatorkey>#</a></h4><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>value_type<span style=color:#f92672>&</span> <span style=color:#66d9ef>operator</span>[](<span style=color:#66d9ef>const</span> key_type<span style=color:#f92672>&</span> k);
|
||||
</span></span></code></pre></div><h5 id=return-value-11>Return Value
|
||||
<a class=anchor href=#return-value-11>#</a></h5><p>Casts the current <code>value</code> to a <code>table</code> and returns a reference to the element specified by <code>key</code>.</p><p>If the element specified by <code>key</code> does not exist, it is default-constructed.</p><h5 id=exception-3>Exception
|
||||
<a class=anchor href=#exception-3>#</a></h5><p>Throws <code>toml::type_error</code> if the stored value is not a <code>table</code>.</p><hr><h3 id=countkey><code>count(key)</code>
|
||||
<a class=anchor href=#countkey>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>std<span style=color:#f92672>::</span>size_t count(<span style=color:#66d9ef>const</span> key_type<span style=color:#f92672>&</span> key) <span style=color:#66d9ef>const</span>;
|
||||
</span></span></code></pre></div><h4 id=return-value-12>Return Value
|
||||
<a class=anchor href=#return-value-12>#</a></h4><p>Casts the current <code>value</code> to a <code>table</code> and returns <code>1</code> if the element corresponding to <code>key</code> is present, otherwise returns <code>0</code>.</p><h4 id=exception-4>Exception
|
||||
<a class=anchor href=#exception-4>#</a></h4><p>Throws <code>toml::type_error</code> if the stored value is not a <code>table</code>.</p><hr><h3 id=containskey><code>contains(key)</code>
|
||||
<a class=anchor href=#containskey>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>bool</span> <span style=color:#a6e22e>contains</span>(<span style=color:#66d9ef>const</span> key_type<span style=color:#f92672>&</span> key) <span style=color:#66d9ef>const</span>;
|
||||
</span></span></code></pre></div><h4 id=return-value-13>Return Value
|
||||
<a class=anchor href=#return-value-13>#</a></h4><p>Casts the current <code>value</code> to a <code>table</code> and returns <code>true</code> if the element corresponding to <code>key</code> is present, otherwise returns <code>false</code>.</p><h4 id=exception-5>Exception
|
||||
<a class=anchor href=#exception-5>#</a></h4><p>Throws <code>toml::type_error</code> if the stored value is not a <code>table</code>.</p><hr><h3 id=atidx><code>at(idx)</code>
|
||||
<a class=anchor href=#atidx>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>value_type<span style=color:#f92672>&</span> at(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>size_t idx);
|
||||
</span></span><span style=display:flex><span>value_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> at(<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>size_t idx) <span style=color:#66d9ef>const</span>;
|
||||
</span></span></code></pre></div><h4 id=return-value-14>Return Value
|
||||
<a class=anchor href=#return-value-14>#</a></h4><p>Casts the current <code>value</code> to an <code>array</code> and returns the element specified by <code>idx</code>.</p><h4 id=exception-6>Exception
|
||||
<a class=anchor href=#exception-6>#</a></h4><p>Throws <code>toml::type_error</code> if the stored value is not an <code>array</code>.</p><p>Throws <code>std::out_of_range</code> if the specified element does not exist in the <code>array</code>.</p><hr><h3 id=operatoridx><code>operator[](idx)</code>
|
||||
<a class=anchor href=#operatoridx>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>value_type<span style=color:#f92672>&</span> <span style=color:#66d9ef>operator</span>[](<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>size_t idx) <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>value_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> <span style=color:#66d9ef>operator</span>[](<span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>size_t idx) <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><h4 id=return-value-15>Return Value
|
||||
<a class=anchor href=#return-value-15>#</a></h4><p>Casts the current <code>value</code> to an <code>array</code> and returns a reference to the element specified by <code>idx</code>.</p><h4 id=note-2>Note
|
||||
<a class=anchor href=#note-2>#</a></h4><p>Performs no checks. Behavior is undefined if the stored value is not an <code>array</code> or if the specified element does not exist.</p><hr><h3 id=push_backvalue><code>push_back(value)</code>
|
||||
<a class=anchor href=#push_backvalue>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>void</span> <span style=color:#a6e22e>push_back</span>(<span style=color:#66d9ef>const</span> value_type<span style=color:#f92672>&</span> x);
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>void</span> <span style=color:#a6e22e>push_back</span>(value_type<span style=color:#f92672>&&</span> x);
|
||||
</span></span></code></pre></div><p>Casts the current <code>value</code> to an <code>array</code> and performs <code>push_back</code> on the <code>array</code>.</p><h4 id=return-value-16>Return Value
|
||||
<a class=anchor href=#return-value-16>#</a></h4><p>None.</p><h4 id=exception-7>Exception
|
||||
<a class=anchor href=#exception-7>#</a></h4><p>Throws <code>toml::type_error</code> if the stored value is not an <code>array</code>.</p><hr><h3 id=emplace_backargs><code>emplace_back(args...)</code>
|
||||
<a class=anchor href=#emplace_backargs>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> ... Ts<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>value_type<span style=color:#f92672>&</span> emplace_back(Ts<span style=color:#f92672>&&</span> ... args)
|
||||
</span></span></code></pre></div><p>Casts the current <code>value</code> to an <code>array</code> and performs <code>emplace_back</code> on the <code>array</code>.</p><h4 id=return-value-17>Return Value
|
||||
<a class=anchor href=#return-value-17>#</a></h4><p>A reference to the constructed value.</p><h4 id=exception-8>Exception
|
||||
<a class=anchor href=#exception-8>#</a></h4><p>Throws <code>toml::type_error</code> if the stored value is not an <code>array</code>.</p><hr><h3 id=size><code>size()</code>
|
||||
<a class=anchor href=#size>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>std<span style=color:#f92672>::</span>size_t size() <span style=color:#66d9ef>const</span>;
|
||||
</span></span></code></pre></div><h4 id=return-value-18>Return Value
|
||||
<a class=anchor href=#return-value-18>#</a></h4><p>Casts the current <code>value</code> to an <code>array</code>, <code>string</code>, or <code>table</code> and returns the number of elements. For a <code>string</code>, it returns the number of characters.</p><h4 id=exception-9>Exception
|
||||
<a class=anchor href=#exception-9>#</a></h4><p>Throws <code>toml::type_error</code> if the stored value is not an <code>array</code>, <code>string</code>, or <code>table</code>.</p><hr><h3 id=location><code>location()</code>
|
||||
<a class=anchor href=#location>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>source_location <span style=color:#a6e22e>location</span>() <span style=color:#66d9ef>const</span>;
|
||||
</span></span></code></pre></div><h4 id=return-value-19>Return Value
|
||||
<a class=anchor href=#return-value-19>#</a></h4><p>Returns a <code>source_location</code> object representing the position within the TOML document where the <code>value</code> is defined.</p><p>If the <code>value</code> was not constructed by parsing a TOML document, returns a <code>source_location</code> that points to nowhere.</p><hr><h3 id=comments><code>comments()</code>
|
||||
<a class=anchor href=#comments>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>comment_type <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> comments() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>comment_type<span style=color:#f92672>&</span> comments() <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span></code></pre></div><h4 id=return-value-20>Return Value
|
||||
<a class=anchor href=#return-value-20>#</a></h4><p>Returns a reference to the comment container.</p><hr><h3 id=accessed><code>accessed()</code>
|
||||
<a class=anchor href=#accessed>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>bool</span> <span style=color:#a6e22e>accessed</span>() <span style=color:#66d9ef>const</span>;
|
||||
</span></span></code></pre></div><h4 id=return-value-21>Return Value
|
||||
<a class=anchor href=#return-value-21>#</a></h4><p>Returns <code>true</code> only if the <code>value</code> has been accessed via <code>as_xxx</code> or <code>is_xxx</code>.
|
||||
Otherwise, it returns <code>false</code>.</p><h4 id=remarks>Remarks
|
||||
<a class=anchor href=#remarks>#</a></h4><p>It exists only when <code>TOML11_ENABLE_ACCESS_CHECK</code> is defined.</p><h2 id=non-member-functions>Non-Member Functions
|
||||
<a class=anchor href=#non-member-functions>#</a></h2><h3 id=operator><code>operator==</code>
|
||||
<a class=anchor href=#operator>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>bool</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>==</span>(<span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span>, <span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span>);
|
||||
</span></span></code></pre></div><p>Two <code>basic_value<T></code> instances are considered equal if they satisfy the following conditions:</p><ul><li>The contained type is the same.</li><li>The contained values are identical.</li><li>The comments are identical at the byte level.</li></ul><h3 id=operator-1><code>operator!=</code>
|
||||
<a class=anchor href=#operator-1>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>bool</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>!=</span>(<span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> lhs, <span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> rhs)
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#f92672>!</span>(lhs <span style=color:#f92672>==</span> rhs);
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><h3 id=operator-2><code>operator<</code>
|
||||
<a class=anchor href=#operator-2>#</a></h3><p>Defined only if <code>array_type</code> and <code>table_type</code> have <code>operator<</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>bool</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672><</span>(<span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span>, <span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span>);
|
||||
</span></span></code></pre></div><p>Comparison order:</p><ol><li>TOML type</li><li>If TOML types are the same, their values</li><li>If both the TOML types and values are the same, the comments</li></ol><p>TOML types have the following order (from smallest to largest):</p><ol><li><code>toml::value_t::empty</code></li><li><code>toml::value_t::boolean</code></li><li><code>toml::value_t::integer</code></li><li><code>toml::value_t::floating</code></li><li><code>toml::value_t::string</code></li><li><code>toml::value_t::offset_datetime</code></li><li><code>toml::value_t::local_datetime</code></li><li><code>toml::value_t::local_date</code></li><li><code>toml::value_t::local_time</code></li><li><code>toml::value_t::array</code></li><li><code>toml::value_t::table</code></li></ol><h3 id=operator-3><code>operator<=</code>
|
||||
<a class=anchor href=#operator-3>#</a></h3><p>Defined only if <code>array_type</code> and <code>table_type</code> have <code>operator<</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>bool</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672><=</span>(<span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> lhs, <span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> rhs)
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> (lhs <span style=color:#f92672><</span> rhs) <span style=color:#f92672>||</span> (lhs <span style=color:#f92672>==</span> rhs);
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><h3 id=operator-4><code>operator></code>
|
||||
<a class=anchor href=#operator-4>#</a></h3><p>Defined only if <code>array_type</code> and <code>table_type</code> have <code>operator<</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>bool</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>></span>(<span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> lhs, <span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> rhs)
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#f92672>!</span>(lhs <span style=color:#f92672><=</span> rhs);
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><h3 id=operator-5><code>operator>=</code>
|
||||
<a class=anchor href=#operator-5>#</a></h3><p>Defined only if <code>array_type</code> and <code>table_type</code> have <code>operator<</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>bool</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672>>=</span>(<span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> lhs, <span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> rhs)
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#f92672>!</span>(lhs <span style=color:#f92672><</span> rhs);
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><h1 id=tomltype_error><code>toml::type_error</code>
|
||||
<a class=anchor href=#tomltype_error>#</a></h1><p>Exception thrown in case of a type error.</p><p>Contains the location information of the value that caused the type error.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>type_error</span> <span style=color:#66d9ef>final</span> <span style=color:#f92672>:</span> <span style=color:#66d9ef>public</span> <span style=color:#f92672>::</span>toml<span style=color:#f92672>::</span>exception
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>public</span><span style=color:#f92672>:</span>
|
||||
</span></span><span style=display:flex><span> type_error(std<span style=color:#f92672>::</span>string what_arg, source_location loc);
|
||||
</span></span><span style=display:flex><span> <span style=color:#f92672>~</span>type_error() <span style=color:#66d9ef>noexcept</span> <span style=color:#66d9ef>override</span> <span style=color:#f92672>=</span> <span style=color:#66d9ef>default</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>char</span><span style=color:#f92672>*</span> <span style=color:#a6e22e>what</span>() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span> <span style=color:#66d9ef>override</span>;
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span> source_location <span style=color:#66d9ef>const</span><span style=color:#f92672>&</span> location() <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span></code></pre></div><h1 id=tomlmake_error_info><code>toml::make_error_info</code>
|
||||
<a class=anchor href=#tomlmake_error_info>#</a></h1><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC, <span style=color:#66d9ef>typename</span> ... Ts<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>error_info make_error_info(
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string title, <span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v, std<span style=color:#f92672>::</span>string msg, Ts<span style=color:#f92672>&&</span> ... tail);
|
||||
</span></span></code></pre></div><p>Calls <code>location()</code> on a <code>basic_value</code>, passes the resulting <code>source_location</code> to
|
||||
<a href=https://toruniina.github.io/toml11/docs/reference/error_info/#make_error_info><code>make_error_info</code></a>
|
||||
to create an <code>error_info</code>.</p><p>Refer to <a href=https://toruniina.github.io/toml11/docs/reference/error_info/><code>error_info</code></a> for more details.</p><h1 id=tomlformat_error><code>toml::format_error</code>
|
||||
<a class=anchor href=#tomlformat_error>#</a></h1><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> TC, <span style=color:#66d9ef>typename</span> ... Ts<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>string format_error(std<span style=color:#f92672>::</span>string title,
|
||||
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> basic_value<span style=color:#f92672><</span>TC<span style=color:#f92672>>&</span> v, std<span style=color:#f92672>::</span>string msg, Ts<span style=color:#f92672>&&</span> ... tail);
|
||||
</span></span></code></pre></div><p>Calls <code>location()</code> on a <code>basic_value</code>, passes the resulting <code>source_location</code> to
|
||||
<a href=https://toruniina.github.io/toml11/docs/reference/error_info/#format_error><code>format_error</code></a>
|
||||
to create an <code>error_info</code>, then converts it to a string and returns it.</p><p>Refer to <a href=https://toruniina.github.io/toml11/docs/reference/error_info/><code>error_info</code></a> for more details.</p><h1 id=related>Related
|
||||
<a class=anchor href=#related>#</a></h1><ul><li><a href=https://toruniina.github.io/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=https://toruniina.github.io/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=https://toruniina.github.io/toml11/docs/reference/types/>types.hpp</a></li><li><a href=https://toruniina.github.io/toml11/docs/reference/visit/>visit.hpp</a></li></ul></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#valuehpp>value.hpp</a></li><li><a href=#tomlbasic_value><code>toml::basic_value</code></a><ul><li><a href=#member-types>Member Types</a></li><li><a href=#member-functions>Member Functions</a><ul><li><a href=#default-constructor>Default Constructor</a></li><li><a href=#copy-and-move-constructors>Copy and Move Constructors</a></li><li><a href=#copy-and-move-constructors-with-comments>Copy and Move Constructors with Comments</a></li><li><a href=#conversion-constructors>Conversion Constructors</a></li><li><a href=#constructor-boolean>Constructor (boolean)</a></li><li><a href=#constructor-integer>Constructor (integer)</a></li><li><a href=#constructor-floating>Constructor (floating)</a></li><li><a href=#constructor-string>Constructor (string)</a></li><li><a href=#constructor-local_date>Constructor (local_date)</a></li><li><a href=#constructor-local_time>Constructor (local_time)</a></li><li><a href=#constructor-local_datetime>Constructor (local_datetime)</a></li><li><a href=#constructor-offset_datetime>Constructor (offset_datetime)</a></li><li><a href=#constructor-array>Constructor (array)</a></li><li><a href=#constructor-table>Constructor (table)</a></li><li><a href=#constructor-user-defined>Constructor (user-defined)</a></li><li><a href=#operatorbasic_value><code>operator=(basic_value)</code></a></li><li><a href=#operatort><code>operator=(T)</code></a></li><li><a href=#ist><code>is<T>()</code></a></li><li><a href=#istomlvalue_t><code>is(toml::value_t)</code></a></li><li><a href=#is_xxx><code>is_xxx()</code></a></li><li><a href=#is_empty><code>is_empty()</code></a></li><li><a href=#is_array_of_tables><code>is_array_of_tables()</code></a></li><li><a href=#type><code>type()</code></a></li><li><a href=#as_xxx><code>as_xxx()</code></a></li><li><a href=#as_xxxstdnothrow><code>as_xxx(std::nothrow)</code></a></li><li><a href=#as_xxx_fmt><code>as_xxx_fmt()</code></a></li><li><a href=#as_xxx_fmtstdnothrow><code>as_xxx_fmt(std::nothrow)</code></a></li><li><a href=#atkey><code>at(key)</code></a></li><li><a href=#countkey><code>count(key)</code></a></li><li><a href=#containskey><code>contains(key)</code></a></li><li><a href=#atidx><code>at(idx)</code></a></li><li><a href=#operatoridx><code>operator[](idx)</code></a></li><li><a href=#push_backvalue><code>push_back(value)</code></a></li><li><a href=#emplace_backargs><code>emplace_back(args...)</code></a></li><li><a href=#size><code>size()</code></a></li><li><a href=#location><code>location()</code></a></li><li><a href=#comments><code>comments()</code></a></li><li><a href=#accessed><code>accessed()</code></a></li></ul></li><li><a href=#non-member-functions>Non-Member Functions</a><ul><li><a href=#operator><code>operator==</code></a></li><li><a href=#operator-1><code>operator!=</code></a></li><li><a href=#operator-2><code>operator<</code></a></li><li><a href=#operator-3><code>operator<=</code></a></li><li><a href=#operator-4><code>operator></code></a></li><li><a href=#operator-5><code>operator>=</code></a></li></ul></li></ul></li><li><a href=#tomltype_error><code>toml::type_error</code></a></li><li><a href=#tomlmake_error_info><code>toml::make_error_info</code></a></li><li><a href=#tomlformat_error><code>toml::format_error</code></a></li><li><a href=#related>Related</a></li></ul></nav></div></aside></main></body></html>
|
||||
74
docs/reference/value_t/index.html
Normal file
74
docs/reference/value_t/index.html
Normal file
@@ -0,0 +1,74 @@
|
||||
<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
|
||||
value_t.hpp
|
||||
#
|
||||
|
||||
|
||||
value_t
|
||||
#
|
||||
|
||||
value_t is used to handle the type information of toml::value.
|
||||
namespace toml
|
||||
{
|
||||
enum class value_t : std::uint8_t
|
||||
{
|
||||
empty = 0,
|
||||
boolean = 1,
|
||||
integer = 2,
|
||||
floating = 3,
|
||||
string = 4,
|
||||
offset_datetime = 5,
|
||||
local_datetime = 6,
|
||||
local_date = 7,
|
||||
local_time = 8,
|
||||
array = 9,
|
||||
table = 10
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, value_t t);
|
||||
std::string to_string(value_t t);
|
||||
} // toml
|
||||
|
||||
Non-member Functions
|
||||
#
|
||||
|
||||
|
||||
Stream Operator
|
||||
#
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, value_t t);
|
||||
Outputs the string representation of the value_t to the stream."><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/reference/value_t/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="value_t.hpp"><meta property="og:description" content="value_t.hpp # value_t # value_t is used to handle the type information of toml::value.
|
||||
namespace toml { enum class value_t : std::uint8_t { empty = 0, boolean = 1, integer = 2, floating = 3, string = 4, offset_datetime = 5, local_datetime = 6, local_date = 7, local_time = 8, array = 9, table = 10 }; std::ostream& operator<<(std::ostream& os, value_t t); std::string to_string(value_t t); } // toml Non-member Functions # Stream Operator # std::ostream& operator<<(std::ostream& os, value_t t); Outputs the string representation of the value_t to the stream."><meta property="og:locale" content="en"><meta property="og:type" content="article"><meta property="article:section" content="docs"><title>value_t.hpp | toml11</title><link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/reference/value_t/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/reference/value_t/ title=value_t.hpp><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" crossorigin=anonymous></script></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
|
||||
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
|
||||
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
|
||||
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/reference/value_t/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle>
|
||||
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle checked>
|
||||
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/ class=active>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
|
||||
</label><strong>value_t.hpp</strong>
|
||||
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#value_thpp>value_t.hpp</a></li><li><a href=#value_t><code>value_t</code></a><ul><li><a href=#non-member-functions>Non-member Functions</a><ul><li><a href=#stream-operator>Stream Operator</a></li><li><a href=#to_string><code>to_string</code></a></li></ul></li></ul></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=value_thpp>value_t.hpp
|
||||
<a class=anchor href=#value_thpp>#</a></h1><h1 id=value_t><code>value_t</code>
|
||||
<a class=anchor href=#value_t>#</a></h1><p><code>value_t</code> is used to handle the type information of <code>toml::value</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>enum</span> <span style=color:#66d9ef>class</span> <span style=color:#a6e22e>value_t</span> <span style=color:#f92672>:</span> std<span style=color:#f92672>::</span><span style=color:#66d9ef>uint8_t</span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> empty <span style=color:#f92672>=</span> <span style=color:#ae81ff>0</span>,
|
||||
</span></span><span style=display:flex><span> boolean <span style=color:#f92672>=</span> <span style=color:#ae81ff>1</span>,
|
||||
</span></span><span style=display:flex><span> integer <span style=color:#f92672>=</span> <span style=color:#ae81ff>2</span>,
|
||||
</span></span><span style=display:flex><span> floating <span style=color:#f92672>=</span> <span style=color:#ae81ff>3</span>,
|
||||
</span></span><span style=display:flex><span> string <span style=color:#f92672>=</span> <span style=color:#ae81ff>4</span>,
|
||||
</span></span><span style=display:flex><span> offset_datetime <span style=color:#f92672>=</span> <span style=color:#ae81ff>5</span>,
|
||||
</span></span><span style=display:flex><span> local_datetime <span style=color:#f92672>=</span> <span style=color:#ae81ff>6</span>,
|
||||
</span></span><span style=display:flex><span> local_date <span style=color:#f92672>=</span> <span style=color:#ae81ff>7</span>,
|
||||
</span></span><span style=display:flex><span> local_time <span style=color:#f92672>=</span> <span style=color:#ae81ff>8</span>,
|
||||
</span></span><span style=display:flex><span> array <span style=color:#f92672>=</span> <span style=color:#ae81ff>9</span>,
|
||||
</span></span><span style=display:flex><span> table <span style=color:#f92672>=</span> <span style=color:#ae81ff>10</span>
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672><<</span>(std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&</span> os, value_t t);
|
||||
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>string to_string(value_t t);
|
||||
</span></span><span style=display:flex><span>} <span style=color:#75715e>// toml
|
||||
</span></span></span></code></pre></div><h2 id=non-member-functions>Non-member Functions
|
||||
<a class=anchor href=#non-member-functions>#</a></h2><h3 id=stream-operator>Stream Operator
|
||||
<a class=anchor href=#stream-operator>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&</span> <span style=color:#66d9ef>operator</span><span style=color:#f92672><<</span>(std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&</span> os, value_t t);
|
||||
</span></span></code></pre></div><p>Outputs the string representation of the <code>value_t</code> to the stream.</p><h3 id=to_string><code>to_string</code>
|
||||
<a class=anchor href=#to_string>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span>std<span style=color:#f92672>::</span>string to_string(value_t t);
|
||||
</span></span></code></pre></div><p>Returns the string representation of the <code>value_t</code>.</p></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#value_thpp>value_t.hpp</a></li><li><a href=#value_t><code>value_t</code></a><ul><li><a href=#non-member-functions>Non-member Functions</a><ul><li><a href=#stream-operator>Stream Operator</a></li><li><a href=#to_string><code>to_string</code></a></li></ul></li></ul></li></ul></nav></div></aside></main></body></html>
|
||||
61
docs/reference/version/index.html
Normal file
61
docs/reference/version/index.html
Normal file
@@ -0,0 +1,61 @@
|
||||
<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
|
||||
version.hpp
|
||||
#
|
||||
|
||||
In version.hpp, macros related to the version information of toml11 are defined.
|
||||
|
||||
Macros
|
||||
#
|
||||
|
||||
|
||||
TOML11_VERSION_MAJOR
|
||||
#
|
||||
|
||||
The major version of toml11.
|
||||
|
||||
TOML11_VERSION_MINOR
|
||||
#
|
||||
|
||||
The minor version of toml11.
|
||||
|
||||
TOML11_VERSION_PATCH
|
||||
#
|
||||
|
||||
The patch version of toml11.
|
||||
|
||||
Function
|
||||
#
|
||||
|
||||
|
||||
license_notice
|
||||
#
|
||||
|
||||
namespace toml
|
||||
{
|
||||
const char* license_notice() noexcept;
|
||||
}
|
||||
Returns the license notice.
|
||||
Provided for convenience when redistributing without source code."><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/reference/version/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="version.hpp"><meta property="og:description" content="version.hpp # In version.hpp, macros related to the version information of toml11 are defined.
|
||||
Macros # TOML11_VERSION_MAJOR # The major version of toml11.
|
||||
TOML11_VERSION_MINOR # The minor version of toml11.
|
||||
TOML11_VERSION_PATCH # The patch version of toml11.
|
||||
Function # license_notice # namespace toml { const char* license_notice() noexcept; } Returns the license notice.
|
||||
Provided for convenience when redistributing without source code."><meta property="og:locale" content="en"><meta property="og:type" content="article"><meta property="article:section" content="docs"><title>version.hpp | toml11</title><link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/reference/version/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/reference/version/ title=version.hpp><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" crossorigin=anonymous></script></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
|
||||
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
|
||||
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
|
||||
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/reference/version/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle>
|
||||
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle checked>
|
||||
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/ class=active>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
|
||||
</label><strong>version.hpp</strong>
|
||||
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#versionhpp>version.hpp</a><ul><li><a href=#macros>Macros</a><ul><li><a href=#toml11_version_major><code>TOML11_VERSION_MAJOR</code></a></li><li><a href=#toml11_version_minor><code>TOML11_VERSION_MINOR</code></a></li><li><a href=#toml11_version_patch><code>TOML11_VERSION_PATCH</code></a></li></ul></li><li><a href=#function>Function</a><ul><li><a href=#license_notice><code>license_notice</code></a></li></ul></li></ul></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=versionhpp>version.hpp
|
||||
<a class=anchor href=#versionhpp>#</a></h1><p>In <code>version.hpp</code>, macros related to the version information of toml11 are defined.</p><h2 id=macros>Macros
|
||||
<a class=anchor href=#macros>#</a></h2><h3 id=toml11_version_major><code>TOML11_VERSION_MAJOR</code>
|
||||
<a class=anchor href=#toml11_version_major>#</a></h3><p>The major version of toml11.</p><h3 id=toml11_version_minor><code>TOML11_VERSION_MINOR</code>
|
||||
<a class=anchor href=#toml11_version_minor>#</a></h3><p>The minor version of toml11.</p><h3 id=toml11_version_patch><code>TOML11_VERSION_PATCH</code>
|
||||
<a class=anchor href=#toml11_version_patch>#</a></h3><p>The patch version of toml11.</p><h2 id=function>Function
|
||||
<a class=anchor href=#function>#</a></h2><h3 id=license_notice><code>license_notice</code>
|
||||
<a class=anchor href=#license_notice>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>const</span> <span style=color:#66d9ef>char</span><span style=color:#f92672>*</span> <span style=color:#a6e22e>license_notice</span>() <span style=color:#66d9ef>noexcept</span>;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p>Returns the license notice.</p><p>Provided for convenience when redistributing without source code.</p></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#versionhpp>version.hpp</a><ul><li><a href=#macros>Macros</a><ul><li><a href=#toml11_version_major><code>TOML11_VERSION_MAJOR</code></a></li><li><a href=#toml11_version_minor><code>TOML11_VERSION_MINOR</code></a></li><li><a href=#toml11_version_patch><code>TOML11_VERSION_PATCH</code></a></li></ul></li><li><a href=#function>Function</a><ul><li><a href=#license_notice><code>license_notice</code></a></li></ul></li></ul></li></ul></nav></div></aside></main></body></html>
|
||||
69
docs/reference/visit/index.html
Normal file
69
docs/reference/visit/index.html
Normal file
@@ -0,0 +1,69 @@
|
||||
<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
|
||||
visit.hpp
|
||||
#
|
||||
|
||||
In visit.hpp, toml::visit is defined.
|
||||
|
||||
toml::visit
|
||||
#
|
||||
|
||||
|
||||
Functions
|
||||
#
|
||||
|
||||
namespace toml
|
||||
{
|
||||
template<typename Visitor, typename ... Args>
|
||||
/* Return value when Visitor is called with a value of basic_value<TC> */
|
||||
visit(Visitor&& visitor, Args&& ... args);
|
||||
}
|
||||
toml::visit calls the overload of Visitor corresponding to the type held by basic_value<TC>, and returns the result.
|
||||
|
||||
Requirements
|
||||
#
|
||||
|
||||
Visitor must be a function or function object callable with any type held by basic_value<TC>."><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/reference/visit/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="visit.hpp"><meta property="og:description" content="visit.hpp # In visit.hpp, toml::visit is defined.
|
||||
toml::visit # Functions # namespace toml { template<typename Visitor, typename ... Args> /* Return value when Visitor is called with a value of basic_value<TC> */ visit(Visitor&& visitor, Args&& ... args); } toml::visit calls the overload of Visitor corresponding to the type held by basic_value<TC>, and returns the result.
|
||||
Requirements # Visitor must be a function or function object callable with any type held by basic_value<TC>."><meta property="og:locale" content="en"><meta property="og:type" content="article"><meta property="article:section" content="docs"><title>visit.hpp | toml11</title><link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/reference/visit/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/reference/visit/ title=visit.hpp><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" crossorigin=anonymous></script></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
|
||||
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
|
||||
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
|
||||
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/reference/visit/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle>
|
||||
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle checked>
|
||||
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/ class=active>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
|
||||
</label><strong>visit.hpp</strong>
|
||||
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#visithpp>visit.hpp</a></li><li><a href=#tomlvisit><code>toml::visit</code></a><ul><li><a href=#functions>Functions</a><ul><li></li></ul></li></ul></li><li><a href=#related>Related</a></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=visithpp>visit.hpp
|
||||
<a class=anchor href=#visithpp>#</a></h1><p>In <code>visit.hpp</code>, <code>toml::visit</code> is defined.</p><h1 id=tomlvisit><code>toml::visit</code>
|
||||
<a class=anchor href=#tomlvisit>#</a></h1><h2 id=functions>Functions
|
||||
<a class=anchor href=#functions>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>template</span><span style=color:#f92672><</span><span style=color:#66d9ef>typename</span> Visitor, <span style=color:#66d9ef>typename</span> ... Args<span style=color:#f92672>></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e>/* Return value when Visitor is called with a value of basic_value<TC> */</span>
|
||||
</span></span><span style=display:flex><span>visit(Visitor<span style=color:#f92672>&&</span> visitor, Args<span style=color:#f92672>&&</span> ... args);
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><p><code>toml::visit</code> calls the overload of <code>Visitor</code> corresponding to the type held by <code>basic_value<TC></code>, and returns the result.</p><h4 id=requirements>Requirements
|
||||
<a class=anchor href=#requirements>#</a></h4><p><code>Visitor</code> must be a function or function object callable with any type held by <code>basic_value<TC></code>.</p><p>Additionally, the return value must be consistent across all overloads.</p><h4 id=example>Example
|
||||
<a class=anchor href=#example>#</a></h4><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><toml.hpp></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><iostream></span><span style=color:#75715e>
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>struct</span> <span style=color:#a6e22e>type_name_of</span>
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string <span style=color:#66d9ef>operator</span>()(<span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value<span style=color:#f92672>::</span>boolean_type <span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> {<span style=color:#66d9ef>return</span> <span style=color:#e6db74>"boolean"</span>;}
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string <span style=color:#66d9ef>operator</span>()(<span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value<span style=color:#f92672>::</span>integer_type <span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> {<span style=color:#66d9ef>return</span> <span style=color:#e6db74>"integer"</span>;}
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string <span style=color:#66d9ef>operator</span>()(<span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value<span style=color:#f92672>::</span>floating_type <span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> {<span style=color:#66d9ef>return</span> <span style=color:#e6db74>"floating"</span>;}
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string <span style=color:#66d9ef>operator</span>()(<span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value<span style=color:#f92672>::</span>string_type <span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> {<span style=color:#66d9ef>return</span> <span style=color:#e6db74>"string"</span>;}
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string <span style=color:#66d9ef>operator</span>()(<span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value<span style=color:#f92672>::</span>local_time_type <span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> {<span style=color:#66d9ef>return</span> <span style=color:#e6db74>"local_time"</span>;}
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string <span style=color:#66d9ef>operator</span>()(<span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value<span style=color:#f92672>::</span>local_date_type <span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> {<span style=color:#66d9ef>return</span> <span style=color:#e6db74>"local_date"</span>;}
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string <span style=color:#66d9ef>operator</span>()(<span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value<span style=color:#f92672>::</span>local_datetime_type <span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> {<span style=color:#66d9ef>return</span> <span style=color:#e6db74>"local_datetime"</span>;}
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string <span style=color:#66d9ef>operator</span>()(<span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value<span style=color:#f92672>::</span>offset_datetime_type<span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> {<span style=color:#66d9ef>return</span> <span style=color:#e6db74>"offset_datetime"</span>;}
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string <span style=color:#66d9ef>operator</span>()(<span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value<span style=color:#f92672>::</span>array_type <span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> {<span style=color:#66d9ef>return</span> <span style=color:#e6db74>"array"</span>;}
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>string <span style=color:#66d9ef>operator</span>()(<span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value<span style=color:#f92672>::</span>table_type <span style=color:#f92672>&</span>) <span style=color:#66d9ef>const</span> {<span style=color:#66d9ef>return</span> <span style=color:#e6db74>"table"</span>;}
|
||||
</span></span><span style=display:flex><span>};
|
||||
</span></span><span style=display:flex><span>
|
||||
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
|
||||
</span></span><span style=display:flex><span>{
|
||||
</span></span><span style=display:flex><span> toml<span style=color:#f92672>::</span>value v(<span style=color:#ae81ff>3.14</span>);
|
||||
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>cout <span style=color:#f92672><<</span> toml<span style=color:#f92672>::</span>visit(type_name_of{}, v) <span style=color:#f92672><<</span> std<span style=color:#f92672>::</span>endl; <span style=color:#75715e>// floating
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
|
||||
</span></span><span style=display:flex><span>}
|
||||
</span></span></code></pre></div><h1 id=related>Related
|
||||
<a class=anchor href=#related>#</a></h1><ul><li><a href=https://toruniina.github.io/toml11/docs/reference/value/>value.hpp</a></li></ul></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#visithpp>visit.hpp</a></li><li><a href=#tomlvisit><code>toml::visit</code></a><ul><li><a href=#functions>Functions</a><ul><li></li></ul></li></ul></li><li><a href=#related>Related</a></li></ul></nav></div></aside></main></body></html>
|
||||
Reference in New Issue
Block a user