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:
1
404.html
Normal file
1
404.html
Normal file
@@ -0,0 +1 @@
|
||||
<!doctype html><html lang=en><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/404.html"><meta property="og:site_name" content="toml11"><meta property="og:title" content="404 Page not found"><meta property="og:locale" content="en"><meta property="og:type" content="website"><title>404 Page not found | 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/404.html><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/404.html title="404 Page not found"><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><style>.not-found{text-align:center}.not-found h1{margin:.25em 0 0;opacity:.25;font-size:40vmin}</style></head><body><main class="flex justify-center not-found"><div><h1>404</h1><h2>Page Not Found</h2><h3><a href=/toml11/>toml11</a></h3></div></main></body></html>
|
||||
File diff suppressed because one or more lines are too long
8
categories/index.html
Normal file
8
categories/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/categories/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="Categories"><meta property="og:locale" content="en"><meta property="og:type" content="website"><title>Categories | 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/categories/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/categories/ title=Categories><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/categories/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/categories/>日本語</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>Categories</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><ul><li class=book-section-flat><strong>Categories</strong><ul></ul></li><li class=book-section-flat><strong>Tags</strong><ul></ul></li></ul></nav></aside></header><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><ul><li class=book-section-flat><strong>Categories</strong><ul></ul></li><li class=book-section-flat><strong>Tags</strong><ul></ul></li></ul></nav></div></aside></main></body></html>
|
||||
1
categories/index.xml
Normal file
1
categories/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>Categories on toml11</title><link>https://toruniina.github.io/toml11/categories/</link><description>Recent content in Categories on toml11</description><generator>Hugo</generator><language>en</language><atom:link href="https://toruniina.github.io/toml11/categories/index.xml" rel="self" type="application/rss+xml"/></channel></rss>
|
||||
1
categories/page/1/index.html
Normal file
1
categories/page/1/index.html
Normal file
@@ -0,0 +1 @@
|
||||
<!doctype html><html lang=en><head><title>https://toruniina.github.io/toml11/categories/</title><link rel=canonical href=https://toruniina.github.io/toml11/categories/><meta charset=utf-8><meta http-equiv=refresh content="0; url=https://toruniina.github.io/toml11/categories/"></head></html>
|
||||
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>
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
||||
"use strict";(function(){const o="/toml11/en.search-data.min.ef6f129152c30a4fb49b0cc2bc7f1637a35b28fd98467446dabbe214866d2b6b.json",i=Object.assign({cache:!0},{includeScore:!0,useExtendedSearch:!0,fieldNormWeight:1.5,threshold:.2,ignoreLocation:!0,keys:[{name:"title",weight:.7},{name:"content",weight:.3}]}),e=document.querySelector("#book-search-input"),t=document.querySelector("#book-search-results");if(!e)return;e.addEventListener("focus",n),e.addEventListener("keyup",s),document.addEventListener("keypress",a);function a(t){if(t.target.value!==0[0])return;if(e===document.activeElement)return;const n=String.fromCharCode(t.charCode);if(!r(n))return;e.focus(),t.preventDefault()}function r(t){const n=e.getAttribute("data-hotkeys")||"";return n.indexOf(t)>=0}function n(){e.removeEventListener("focus",n),e.required=!0,fetch(o).then(e=>e.json()).then(e=>{window.bookSearchIndex=new Fuse(e,i)}).then(()=>e.required=!1).then(s)}function s(){for(;t.firstChild;)t.removeChild(t.firstChild);if(!e.value)return;const n=window.bookSearchIndex.search(e.value).slice(0,10);n.forEach(function(e){const n=c("<li><a href></a><small></small></li>"),s=n.querySelector("a"),o=n.querySelector("small");s.href=e.item.href,s.textContent=e.item.title,o.textContent=e.item.section,t.appendChild(n)})}function c(e){const t=document.createElement("div");return t.innerHTML=e,t.firstChild}})()
|
||||
1
en/index.html
Normal file
1
en/index.html
Normal file
@@ -0,0 +1 @@
|
||||
<!doctype html><html lang=en><head><title>https://toruniina.github.io/toml11/</title><link rel=canonical href=https://toruniina.github.io/toml11/><meta charset=utf-8><meta http-equiv=refresh content="0; url=https://toruniina.github.io/toml11/"></head></html>
|
||||
1
en/sitemap.xml
Normal file
1
en/sitemap.xml
Normal file
File diff suppressed because one or more lines are too long
BIN
favicon.png
Normal file
BIN
favicon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 109 B |
1
favicon.svg
Normal file
1
favicon.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M3 18h12v-2H3v2zM3 6v2h18V6H3zm0 7h18v-2H3v2z"/></svg>
|
||||
|
After Width: | Height: | Size: 185 B |
BIN
fonts/roboto-mono-v13-latin-regular.woff
Normal file
BIN
fonts/roboto-mono-v13-latin-regular.woff
Normal file
Binary file not shown.
BIN
fonts/roboto-mono-v13-latin-regular.woff2
Normal file
BIN
fonts/roboto-mono-v13-latin-regular.woff2
Normal file
Binary file not shown.
BIN
fonts/roboto-v27-latin-700.woff
Normal file
BIN
fonts/roboto-v27-latin-700.woff
Normal file
Binary file not shown.
BIN
fonts/roboto-v27-latin-700.woff2
Normal file
BIN
fonts/roboto-v27-latin-700.woff2
Normal file
Binary file not shown.
BIN
fonts/roboto-v27-latin-regular.woff
Normal file
BIN
fonts/roboto-v27-latin-regular.woff
Normal file
Binary file not shown.
BIN
fonts/roboto-v27-latin-regular.woff2
Normal file
BIN
fonts/roboto-v27-latin-regular.woff2
Normal file
Binary file not shown.
9
fuse.min.js
vendored
Normal file
9
fuse.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
41
index.html
Normal file
41
index.html
Normal file
@@ -0,0 +1,41 @@
|
||||
<!doctype html><html lang=en dir=ltr><head><meta name=generator content="Hugo 0.152.2"><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
|
||||
Introduction
|
||||
#
|
||||
|
||||
日本語版はこちら
|
||||
|
||||
Installation
|
||||
#
|
||||
|
||||
This section describes how to build and install toml11.
|
||||
|
||||
Features
|
||||
#
|
||||
|
||||
This section describes how to use toml11’s features with examples.
|
||||
|
||||
Reference
|
||||
#
|
||||
|
||||
This section details toml11 functions and classes.
|
||||
|
||||
ChangeLog
|
||||
#
|
||||
|
||||
This section describes changes from release to release."><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/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="Introduction"><meta property="og:description" content="Introduction # 日本語版はこちら
|
||||
Installation # This section describes how to build and install toml11.
|
||||
Features # This section describes how to use toml11’s features with examples.
|
||||
Reference # This section details toml11 functions and classes.
|
||||
ChangeLog # This section describes changes from release to release."><meta property="og:locale" content="en"><meta property="og:type" content="website"><title>Introduction | 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/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/ title=Introduction><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/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/>日本語</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>Introduction</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=#introduction>Introduction</a><ul><li><a href=#installation>Installation</a></li><li><a href=#features>Features</a></li><li><a href=#reference>Reference</a></li><li><a href=#changelog>ChangeLog</a></li></ul></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=introduction>Introduction
|
||||
<a class=anchor href=#introduction>#</a></h1><p>日本語版は<a href=/toml11/ja/>こちら</a></p><h2 id=installation><a href=docs/installation>Installation</a>
|
||||
<a class=anchor href=#installation>#</a></h2><p>This section describes how to build and install toml11.</p><h2 id=features><a href=docs/features>Features</a>
|
||||
<a class=anchor href=#features>#</a></h2><p>This section describes how to use toml11’s features with examples.</p><h2 id=reference><a href=docs/reference>Reference</a>
|
||||
<a class=anchor href=#reference>#</a></h2><p>This section details toml11 functions and classes.</p><h2 id=changelog><a href=docs/changelog>ChangeLog</a>
|
||||
<a class=anchor href=#changelog>#</a></h2><p>This section describes changes from release to release.</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=#introduction>Introduction</a><ul><li><a href=#installation>Installation</a></li><li><a href=#features>Features</a></li><li><a href=#reference>Reference</a></li><li><a href=#changelog>ChangeLog</a></li></ul></li></ul></nav></div></aside></main></body></html>
|
||||
902
index.xml
Normal file
902
index.xml
Normal file
@@ -0,0 +1,902 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Introduction on toml11</title><link>https://toruniina.github.io/toml11/</link><description>Recent content in Introduction on toml11</description><generator>Hugo</generator><language>en</language><atom:link href="https://toruniina.github.io/toml11/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><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>
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
||||
"use strict";(function(){const o="/toml11/ja.search-data.min.84d897ed014964ac5279bb91b70a5568813e7722da0cff29b3e403c1e8de45ca.json",i=Object.assign({encode:!1,tokenize:function(e){return e.replace(/[\x00-\x7F]/g,"").split("")}},{includeScore:!0,useExtendedSearch:!0,fieldNormWeight:1.5,threshold:.2,ignoreLocation:!0,keys:[{name:"title",weight:.7},{name:"content",weight:.3}]}),e=document.querySelector("#book-search-input"),t=document.querySelector("#book-search-results");if(!e)return;e.addEventListener("focus",n),e.addEventListener("keyup",s),document.addEventListener("keypress",a);function a(t){if(t.target.value!==0[0])return;if(e===document.activeElement)return;const n=String.fromCharCode(t.charCode);if(!r(n))return;e.focus(),t.preventDefault()}function r(t){const n=e.getAttribute("data-hotkeys")||"";return n.indexOf(t)>=0}function n(){e.removeEventListener("focus",n),e.required=!0,fetch(o).then(e=>e.json()).then(e=>{window.bookSearchIndex=new Fuse(e,i)}).then(()=>e.required=!1).then(s)}function s(){for(;t.firstChild;)t.removeChild(t.firstChild);if(!e.value)return;const n=window.bookSearchIndex.search(e.value).slice(0,10);n.forEach(function(e){const n=c("<li><a href></a><small></small></li>"),s=n.querySelector("a"),o=n.querySelector("small");s.href=e.item.href,s.textContent=e.item.title,o.textContent=e.item.section,t.appendChild(n)})}function c(e){const t=document.createElement("div");return t.innerHTML=e,t.firstChild}})()
|
||||
1
ja/404.html
Normal file
1
ja/404.html
Normal file
@@ -0,0 +1 @@
|
||||
<!doctype html><html lang=ja><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/ja/404.html"><meta property="og:site_name" content="toml11"><meta property="og:title" content="404 Page not found"><meta property="og:locale" content="ja"><meta property="og:type" content="website"><title>404 Page not found | 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/ja/404.html><link rel=alternate hreflang=en href=https://toruniina.github.io/toml11/404.html title="404 Page not found"><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/ja.search.min.b1a1e3e4be0fdf11fae2bb2370353d99ecd7abea7ccc29273319c021dda76dfd.js integrity="sha256-saHj5L4P3xH64rsjcDU9mezXq+p8zCknMxnAId2nbf0=" crossorigin=anonymous></script><style>.not-found{text-align:center}.not-found h1{margin:.25em 0 0;opacity:.25;font-size:40vmin}</style></head><body><main class="flex justify-center not-found"><div><h1>404</h1><h2>Page Not Found</h2><h3><a href=/toml11/ja/>toml11</a></h3></div></main></body></html>
|
||||
8
ja/categories/index.html
Normal file
8
ja/categories/index.html
Normal file
@@ -0,0 +1,8 @@
|
||||
<!doctype html><html lang=ja 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/ja/categories/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="Categories"><meta property="og:locale" content="ja"><meta property="og:type" content="website"><title>Categories | 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/ja/categories/><link rel=alternate hreflang=en href=https://toruniina.github.io/toml11/categories/ title=Categories><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/ja.search.min.b1a1e3e4be0fdf11fae2bb2370353d99ecd7abea7ccc29273319c021dda76dfd.js integrity="sha256-saHj5L4P3xH64rsjcDU9mezXq+p8zCknMxnAId2nbf0=" crossorigin=anonymous></script><link rel=alternate type=application/rss+xml href=https://toruniina.github.io/toml11/ja/categories/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/ja/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=検索 aria-label=検索 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>
|
||||
日本語</a></label><ul><li><a href=https://toruniina.github.io/toml11/categories/>English</a></li></ul></li></ul><ul><li><a href=/toml11/ja/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-b4cfb5b55e913a8d853eacf5e8fba05f class=toggle>
|
||||
<label for=section-b4cfb5b55e913a8d853eacf5e8fba05f class="flex justify-between"><a href=/toml11/ja/docs/features/>features</a></label><ul><li><a href=/toml11/ja/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/ja/docs/features/value/>getting values</a></li><li><a href=/toml11/ja/docs/features/error_message/>error message</a></li><li><a href=/toml11/ja/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/ja/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/ja/docs/features/literal/>toml literal</a></li><li><a href=/toml11/ja/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/ja/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-01b096afc5186aea96713b408b47c967 class=toggle>
|
||||
<label for=section-01b096afc5186aea96713b408b47c967 class="flex justify-between"><a href=/toml11/ja/docs/reference/>reference</a></label><ul><li><a href=/toml11/ja/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/ja/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/ja/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/ja/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/ja/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/ja/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/ja/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/ja/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/ja/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/ja/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/ja/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/ja/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/ja/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/ja/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/ja/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/ja/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/ja/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/ja/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/ja/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/ja/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/ja/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/ja/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/ja/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/ja/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>Categories</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><ul><li class=book-section-flat><strong>Categories</strong><ul></ul></li><li class=book-section-flat><strong>Tags</strong><ul></ul></li></ul></nav></aside></header><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><ul><li class=book-section-flat><strong>Categories</strong><ul></ul></li><li class=book-section-flat><strong>Tags</strong><ul></ul></li></ul></nav></div></aside></main></body></html>
|
||||
1
ja/categories/index.xml
Normal file
1
ja/categories/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>Categories on toml11</title><link>https://toruniina.github.io/toml11/ja/categories/</link><description>Recent content in Categories on toml11</description><generator>Hugo</generator><language>ja</language><atom:link href="https://toruniina.github.io/toml11/ja/categories/index.xml" rel="self" type="application/rss+xml"/></channel></rss>
|
||||
1
ja/categories/page/1/index.html
Normal file
1
ja/categories/page/1/index.html
Normal file
@@ -0,0 +1 @@
|
||||
<!doctype html><html lang=ja><head><title>https://toruniina.github.io/toml11/ja/categories/</title><link rel=canonical href=https://toruniina.github.io/toml11/ja/categories/><meta charset=utf-8><meta http-equiv=refresh content="0; url=https://toruniina.github.io/toml11/ja/categories/"></head></html>
|
||||
371
ja/docs/changelog/index.html
Normal file
371
ja/docs/changelog/index.html
Normal file
File diff suppressed because one or more lines are too long
1
ja/docs/changelog/index.xml
Normal file
1
ja/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/ja/docs/changelog/</link><description>Recent content in changelog on toml11</description><generator>Hugo</generator><language>ja</language><atom:link href="https://toruniina.github.io/toml11/ja/docs/changelog/index.xml" rel="self" type="application/rss+xml"/></channel></rss>
|
||||
203
ja/docs/features/configure_types/index.html
Normal file
203
ja/docs/features/configure_types/index.html
Normal file
@@ -0,0 +1,203 @@
|
||||
<!doctype html><html lang=ja dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
|
||||
型をカスタマイズする
|
||||
#
|
||||
|
||||
toml::value は integer_type として std::int64_t を、
|
||||
table_type として std::unordered_map<key_type, value_type> を使用します。
|
||||
しかし、場合によっては boost::multiprecision::int128_t や、 std::map を使用したい場合もあります。
|
||||
そのため、 toml::value は template 引数を取って格納する型を変えられるように実装されています。
|
||||
std::string が実際には std::basic_string<char, std::char_traits<char>, std::allocator<char>> の
|
||||
エイリアスであるように、 toml::value は実際には toml::basic_value<toml::type_config> のエイリアスです。
|
||||
ここでは、 toml::type_config が持つ型と、異なる config 型を定義する方法を説明します。
|
||||
|
||||
type_config
|
||||
#
|
||||
|
||||
type_config は、以下のメンバ型とstaticメンバ関数を持つクラスです。
|
||||
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);
|
||||
};
|
||||
}
|
||||
toml::basic_value<TypeConfig> は、格納する boolean_type を TypeConfig::boolean_type、
|
||||
格納する integer_type を TypeConfig::integer_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/ja/docs/features/configure_types/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="configuring types"><meta property="og:description" content="型をカスタマイズする # toml::value は integer_type として std::int64_t を、 table_type として std::unordered_map<key_type, value_type> を使用します。
|
||||
しかし、場合によっては boost::multiprecision::int128_t や、 std::map を使用したい場合もあります。
|
||||
そのため、 toml::value は template 引数を取って格納する型を変えられるように実装されています。
|
||||
std::string が実際には std::basic_string<char, std::char_traits<char>, std::allocator<char>> の エイリアスであるように、 toml::value は実際には toml::basic_value<toml::type_config> のエイリアスです。
|
||||
ここでは、 toml::type_config が持つ型と、異なる config 型を定義する方法を説明します。
|
||||
type_config # type_config は、以下のメンバ型とstaticメンバ関数を持つクラスです。
|
||||
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); }; } toml::basic_value<TypeConfig> は、格納する boolean_type を TypeConfig::boolean_type、 格納する integer_type を TypeConfig::integer_type 、のようにして定義しています。"><meta property="og:locale" content="ja"><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/ja/docs/features/configure_types/><link rel=alternate hreflang=en href=https://toruniina.github.io/toml11/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/ja.search.min.b1a1e3e4be0fdf11fae2bb2370353d99ecd7abea7ccc29273319c021dda76dfd.js integrity="sha256-saHj5L4P3xH64rsjcDU9mezXq+p8zCknMxnAId2nbf0=" 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/ja/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=検索 aria-label=検索 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>
|
||||
日本語</a></label><ul><li><a href=https://toruniina.github.io/toml11/docs/features/configure_types/>English</a></li></ul></li></ul><ul><li><a href=/toml11/ja/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-b4cfb5b55e913a8d853eacf5e8fba05f class=toggle checked>
|
||||
<label for=section-b4cfb5b55e913a8d853eacf5e8fba05f class="flex justify-between"><a href=/toml11/ja/docs/features/>features</a></label><ul><li><a href=/toml11/ja/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/ja/docs/features/value/>getting values</a></li><li><a href=/toml11/ja/docs/features/error_message/>error message</a></li><li><a href=/toml11/ja/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/ja/docs/features/configure_types/ class=active>configuring types</a></li><li><a href=/toml11/ja/docs/features/literal/>toml literal</a></li><li><a href=/toml11/ja/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/ja/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-01b096afc5186aea96713b408b47c967 class=toggle>
|
||||
<label for=section-01b096afc5186aea96713b408b47c967 class="flex justify-between"><a href=/toml11/ja/docs/reference/>reference</a></label><ul><li><a href=/toml11/ja/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/ja/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/ja/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/ja/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/ja/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/ja/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/ja/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/ja/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/ja/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/ja/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/ja/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/ja/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/ja/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/ja/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/ja/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/ja/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/ja/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/ja/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/ja/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/ja/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/ja/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/ja/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/ja/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/ja/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=#型をカスタマイズする>型をカスタマイズする</a><ul><li><a href=#type_config><code>type_config</code></a></li><li><a href=#テーブル内の値の順序を維持する>テーブル内の値の順序を維持する</a></li><li><a href=#コメントを保存しない>コメントを保存しない</a></li><li><a href=#配列にstdvector以外のコンテナを使用する>配列に<code>std::vector</code>以外のコンテナを使用する</a></li><li><a href=#数値型に-boostmultiprecision-を使用する>数値型に <code>boost::multiprecision</code> を使用する</a></li></ul></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=型をカスタマイズする>型をカスタマイズする
|
||||
<a class=anchor href=#%e5%9e%8b%e3%82%92%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%9e%e3%82%a4%e3%82%ba%e3%81%99%e3%82%8b>#</a></h1><p><code>toml::value</code> は <code>integer_type</code> として <code>std::int64_t</code> を、
|
||||
<code>table_type</code> として <code>std::unordered_map<key_type, value_type></code> を使用します。</p><p>しかし、場合によっては <code>boost::multiprecision::int128_t</code> や、 <code>std::map</code> を使用したい場合もあります。</p><p>そのため、 <code>toml::value</code> は <code>template</code> 引数を取って格納する型を変えられるように実装されています。</p><p><code>std::string</code> が実際には <code>std::basic_string<char, std::char_traits<char>, std::allocator<char>></code> の
|
||||
エイリアスであるように、 <code>toml::value</code> は実際には <code>toml::basic_value<toml::type_config></code> のエイリアスです。</p><p>ここでは、 <code>toml::type_config</code> が持つ型と、異なる <code>config</code> 型を定義する方法を説明します。</p><h2 id=type_config><code>type_config</code>
|
||||
<a class=anchor href=#type_config>#</a></h2><p><code>type_config</code> は、以下のメンバ型と<code>static</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></code></pre></div><p><code>toml::basic_value<TypeConfig></code> は、格納する <code>boolean_type</code> を <code>TypeConfig::boolean_type</code>、
|
||||
格納する <code>integer_type</code> を <code>TypeConfig::integer_type</code> 、のようにして定義しています。</p><p>また、 <code>array_type</code> は <code>TypeConfig::array_type<toml::basic_value<TypeConfig>></code> 、
|
||||
<code>table_type</code> は <code>TypeConfig::table_type<key_type, toml::basic_value<TypeConfig>></code> と
|
||||
定義されます。</p><p>これらのメンバ型とメンバ関数を定義したクラスを <code>toml::basic_value</code> に
|
||||
渡すことで、その <code>toml::basic_value</code> が持つ型を変更できます。</p><p><code>parse_int</code> と <code>parse_float</code> は、数値型を独自実装のものに変更した際にパース方法を提供するための関数です。
|
||||
これらの関数には <code>0x</code> などのprefixと桁区切りの <code>_</code> が取り除かれた文字列、
|
||||
例えば <code>123456</code> や <code>DEADBEEF</code> が渡されます。
|
||||
<code>base</code> には <code>10</code>, <code>16</code>, <code>8</code>, <code>2</code> のいずれかが渡されます。
|
||||
これらを使って <code>integer_type</code> と <code>floating_type</code> をパース出来るような関数を渡してください。</p><p>デフォルト実装として、<code>toml::read_int</code> と <code>toml::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>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><code>read_int</code> は <code>istream</code> を使用し、16進と8進の場合は <code>std::hex</code> と
|
||||
<code>std::oct</code> を使用します。2進の場合は掛け算と足し算で実装されています。
|
||||
これらをサポートしている型であれば、 <code>read_int</code> をそのまま使用できます。</p><p><code>read_float</code> は <code>istream</code> を使用します。
|
||||
16進浮動小数点数は <code>double</code> と <code>float</code> の場合しかサポートされておらず、
|
||||
それ以外の型のときに呼ばれると常にパースエラーを返す実装になっているので、
|
||||
もし浮動小数点数型をこれら以外の型にし、かつ <code>hexfloat</code> を使用する場合は、
|
||||
それを実装してください。 <code>hexfloat</code> を使用しないのであれば、実装する必要はありません。</p><h2 id=テーブル内の値の順序を維持する>テーブル内の値の順序を維持する
|
||||
<a class=anchor href=#%e3%83%86%e3%83%bc%e3%83%96%e3%83%ab%e5%86%85%e3%81%ae%e5%80%a4%e3%81%ae%e9%a0%86%e5%ba%8f%e3%82%92%e7%b6%ad%e6%8c%81%e3%81%99%e3%82%8b>#</a></h2><p>デフォルトの <code>toml::type_config</code> の他に、 <code>toml::ordered_type_config</code> が提供されています。
|
||||
これは、 <code>table_type</code> を <a href=https://toruniina.github.io/toml11/ja/docs/reference/ordered_map/>ordered_map</a> に変更したものです。</p><p>これを使用したものを <code>toml::ordered_value</code> 、その配列型とテーブル型のエイリアスを
|
||||
<code>toml::ordered_array</code> と <code>toml::ordered_table</code> と定義しています。</p><p><code>toml::parse(...)</code> を <code>toml::parse<toml::ordered_type_config>(...)</code> として呼び出すことで、
|
||||
<code>toml::ordered_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:#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=コメントを保存しない>コメントを保存しない
|
||||
<a class=anchor href=#%e3%82%b3%e3%83%a1%e3%83%b3%e3%83%88%e3%82%92%e4%bf%9d%e5%ad%98%e3%81%97%e3%81%aa%e3%81%84>#</a></h2><p><code>type_config</code> は <code>comment_type</code> でコメントを保存するコンテナを定義しています。</p><p>コメントに特に情報がなく、パースせずに捨ててしまっていい場合は、 <code>comment_type</code> に
|
||||
<code>toml::discard_comments</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=配列にstdvector以外のコンテナを使用する>配列に<code>std::vector</code>以外のコンテナを使用する
|
||||
<a class=anchor href=#%e9%85%8d%e5%88%97%e3%81%abstdvector%e4%bb%a5%e5%a4%96%e3%81%ae%e3%82%b3%e3%83%b3%e3%83%86%e3%83%8a%e3%82%92%e4%bd%bf%e7%94%a8%e3%81%99%e3%82%8b>#</a></h2><p>TOML配列の実装に<code>vector</code>以外のコンテナ(例:<code>std::deque</code>)を使用するには、
|
||||
<code>array_type</code> を以下のように変更してください。</p><p>また、テーブル型のコンテナに <code>unordered_map</code> 以外のコンテナ(例:<code>std::map</code>)を使用するには、
|
||||
<code>table_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>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=数値型に-boostmultiprecision-を使用する>数値型に <code>boost::multiprecision</code> を使用する
|
||||
<a class=anchor href=#%e6%95%b0%e5%80%a4%e5%9e%8b%e3%81%ab-boostmultiprecision-%e3%82%92%e4%bd%bf%e7%94%a8%e3%81%99%e3%82%8b>#</a></h2><p><code>boost::multiprecision::cpp_int</code> と <code>boost::multiprecision::cpp_bin_float_oct</code>
|
||||
を使用することで、より幅の広い整数型とより精度の良い浮動小数点数型を使用することができます。</p><p>これらの型はストリーム演算子を実装しているため、デフォルト実装の <code>read_int</code> と
|
||||
<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>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=#型をカスタマイズする>型をカスタマイズする</a><ul><li><a href=#type_config><code>type_config</code></a></li><li><a href=#テーブル内の値の順序を維持する>テーブル内の値の順序を維持する</a></li><li><a href=#コメントを保存しない>コメントを保存しない</a></li><li><a href=#配列にstdvector以外のコンテナを使用する>配列に<code>std::vector</code>以外のコンテナを使用する</a></li><li><a href=#数値型に-boostmultiprecision-を使用する>数値型に <code>boost::multiprecision</code> を使用する</a></li></ul></li></ul></nav></div></aside></main></body></html>
|
||||
156
ja/docs/features/error_message/index.html
Normal file
156
ja/docs/features/error_message/index.html
Normal file
@@ -0,0 +1,156 @@
|
||||
<!doctype html><html lang=ja dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
|
||||
エラーメッセージを出力する
|
||||
#
|
||||
|
||||
toml11は toml::parse や toml::get<T>/find<T>, as_integer() などから
|
||||
ファイル内の位置情報を含んだエラーメッセージを出力します。
|
||||
例えば、パース時に整数の文法エラーを発見した場合、
|
||||
[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
|
||||
あるいは実際に格納されている型と異なる型を要求した場合
|
||||
[error] toml::value::as_string(): bad_cast to string
|
||||
--> input.toml
|
||||
|
|
||||
1 | a = 123_456
|
||||
| ^^^^^^^-- the actual type is integer
|
||||
toml11は 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/ja/docs/features/error_message/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="error message"><meta property="og:description" content="エラーメッセージを出力する # toml11は toml::parse や toml::get<T>/find<T>, as_integer() などから ファイル内の位置情報を含んだエラーメッセージを出力します。
|
||||
例えば、パース時に整数の文法エラーを発見した場合、
|
||||
[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 あるいは実際に格納されている型と異なる型を要求した場合
|
||||
[error] toml::value::as_string(): bad_cast to string --> input.toml | 1 | a = 123_456 | ^^^^^^^-- the actual type is integer toml11は toml::value からこのようなエラーメッセージを作成する方法を提供します。"><meta property="og:locale" content="ja"><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/ja/docs/features/error_message/><link rel=alternate hreflang=en href=https://toruniina.github.io/toml11/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/ja.search.min.b1a1e3e4be0fdf11fae2bb2370353d99ecd7abea7ccc29273319c021dda76dfd.js integrity="sha256-saHj5L4P3xH64rsjcDU9mezXq+p8zCknMxnAId2nbf0=" 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/ja/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=検索 aria-label=検索 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>
|
||||
日本語</a></label><ul><li><a href=https://toruniina.github.io/toml11/docs/features/error_message/>English</a></li></ul></li></ul><ul><li><a href=/toml11/ja/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-b4cfb5b55e913a8d853eacf5e8fba05f class=toggle checked>
|
||||
<label for=section-b4cfb5b55e913a8d853eacf5e8fba05f class="flex justify-between"><a href=/toml11/ja/docs/features/>features</a></label><ul><li><a href=/toml11/ja/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/ja/docs/features/value/>getting values</a></li><li><a href=/toml11/ja/docs/features/error_message/ class=active>error message</a></li><li><a href=/toml11/ja/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/ja/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/ja/docs/features/literal/>toml literal</a></li><li><a href=/toml11/ja/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/ja/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-01b096afc5186aea96713b408b47c967 class=toggle>
|
||||
<label for=section-01b096afc5186aea96713b408b47c967 class="flex justify-between"><a href=/toml11/ja/docs/reference/>reference</a></label><ul><li><a href=/toml11/ja/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/ja/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/ja/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/ja/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/ja/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/ja/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/ja/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/ja/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/ja/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/ja/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/ja/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/ja/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/ja/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/ja/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/ja/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/ja/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/ja/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/ja/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/ja/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/ja/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/ja/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/ja/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/ja/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/ja/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=#エラーメッセージを出力する>エラーメッセージを出力する</a><ul><li><a href=#tomlvalue-の位置情報からエラーメッセージを作成する><code>toml::value</code> の位置情報からエラーメッセージを作成する</a></li><li><a href=#文字列に色を付ける>文字列に色を付ける</a></li><li><a href=#エラーメッセージのprefixをerrorから変更する>エラーメッセージのprefixを<code>[error]</code>から変更する</a></li><li><a href=#複数の-tomlvalue-を指すエラーメッセージを作成する>複数の <code>toml::value</code> を指すエラーメッセージを作成する</a></li></ul></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=エラーメッセージを出力する>エラーメッセージを出力する
|
||||
<a class=anchor href=#%e3%82%a8%e3%83%a9%e3%83%bc%e3%83%a1%e3%83%83%e3%82%bb%e3%83%bc%e3%82%b8%e3%82%92%e5%87%ba%e5%8a%9b%e3%81%99%e3%82%8b>#</a></h1><p>toml11は <code>toml::parse</code> や <code>toml::get<T>/find<T></code>, <code>as_integer()</code> などから
|
||||
ファイル内の位置情報を含んだエラーメッセージを出力します。</p><p>例えば、パース時に整数の文法エラーを発見した場合、</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>あるいは実際に格納されている型と異なる型を要求した場合</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>toml11は <code>toml::value</code> からこのようなエラーメッセージを作成する方法を提供します。</p><p>この機能を利用することで、TOMLの文法エラーだけでなく、
|
||||
例えば正の値でなければならないところに負数が現れた場合などの
|
||||
アプリケーション固有のエラーメッセージを、TOMLファイル内の位置を指摘しながら
|
||||
ユーザーに伝えられるということです。</p><h2 id=tomlvalue-の位置情報からエラーメッセージを作成する><code>toml::value</code> の位置情報からエラーメッセージを作成する
|
||||
<a class=anchor href=#tomlvalue-%e3%81%ae%e4%bd%8d%e7%bd%ae%e6%83%85%e5%a0%b1%e3%81%8b%e3%82%89%e3%82%a8%e3%83%a9%e3%83%bc%e3%83%a1%e3%83%83%e3%82%bb%e3%83%bc%e3%82%b8%e3%82%92%e4%bd%9c%e6%88%90%e3%81%99%e3%82%8b>#</a></h2><p><code>toml::value</code> はそれがパースされた位置の情報を持っています。</p><p>その情報は <code>toml::source_location</code> にまとめられ、<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>ファイルを <code>toml::parse</code> でパースした場合、そのTOMLファイル名と行数が保存されています。</p><p><code>toml::parse_str</code> でパースした場合TOMLファイル名はありませんが、代わりに
|
||||
<code>toml::parse_str</code> を呼び出したC++ソースコードのファイル名と行数がTOMLファイル名として保存されています。
|
||||
このページの最初の例は <code>toml::parse_str</code> から出力された例でした。
|
||||
ファイル名の部分に注目してください。</p><p>詳細は <a href=https://toruniina.github.io/toml11/ja/docs/reference/source_location/>reference</a> を参照してください。</p><p><code>toml::source_location</code> または <code>toml::value</code> とそれに付随するエラーメッセージを
|
||||
<code>toml::make_error_info</code> に渡すことで、エラー情報を構築できます。
|
||||
これを<code>toml::format_error</code> に渡すと、エラーメッセージが <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>// エラーのタイトル
|
||||
</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>// 値の横に書くメッセージ
|
||||
</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>これは以下のようになります。</p><pre tabindex=0><code>[error] positive integer is required
|
||||
--> input.toml
|
||||
|
|
||||
1 | a = -123456
|
||||
| ^^^^^^^-- but got negative value
|
||||
</code></pre><p>最後に補足をつけ足すこともできます。これはインデントされません。</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>// エラーのタイトル
|
||||
</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>// 値の横に書くメッセージ
|
||||
</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>// 補足
|
||||
</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><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><code>toml::value</code> からファイル内の行を出力できるのは、
|
||||
パースしたファイルが文字列としてメモリの中に残されているからです。</p><p>パースした文字列はその全体が <code>std::shared_ptr</code> で <code>toml::value</code> に共有されています。
|
||||
コピーしてもファイル文字列全体がコピーされることはありません。
|
||||
また、そのファイルをパースして構築された <code>toml::value</code> が全てデストラクトされた時点で、
|
||||
ファイル情報もメモリ上から解放されます。</p><p>ですので、アプリケーションで使用する際には、 <code>toml::value</code> を直接保存するのではなく
|
||||
読み込み中に必要な値を全て取り出して、変換した値を保存した方がよいでしょう。</p></blockquote><h2 id=文字列に色を付ける>文字列に色を付ける
|
||||
<a class=anchor href=#%e6%96%87%e5%ad%97%e5%88%97%e3%81%ab%e8%89%b2%e3%82%92%e4%bb%98%e3%81%91%e3%82%8b>#</a></h2><p>エラーメッセージにはANSIエスケープコードを使って色を付けることができます。</p><p><code>TOML11_COLORIZE_ERROR_MESSAGE</code> をコンパイル時に定義していれば、
|
||||
toml11の出力するエラーメッセージはデフォルトで色が付くようになります。</p><p>そうでない場合は、 <code>toml::color::enable()</code> を呼び出すことにより、それ以降で出力される
|
||||
エラーメッセージには色が付くようになります。
|
||||
逆に出力先がコンソールではないなどの理由で色をつけたくない場合は、
|
||||
<code>toml::color::disable()</code> を呼び出してください。
|
||||
その時点で色が付くようになっているかどうかは、
|
||||
<code>toml::color::should_color()</code> の返り値で判定できます。</p><p>詳細は <a href=https://toruniina.github.io/toml11/ja/docs/reference/color/>reference</a> を参照してください。</p><p>また、エラーのタイトルやエラーメッセージ、補足にはデフォルトで色が付きませんが、
|
||||
<code>toml::color</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>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>こちらも、詳細は <a href=https://toruniina.github.io/toml11/ja/docs/reference/color/>reference</a> を参照してください。</p><h2 id=エラーメッセージのprefixをerrorから変更する>エラーメッセージのprefixを<code>[error]</code>から変更する
|
||||
<a class=anchor href=#%e3%82%a8%e3%83%a9%e3%83%bc%e3%83%a1%e3%83%83%e3%82%bb%e3%83%bc%e3%82%b8%e3%81%aeprefix%e3%82%92error%e3%81%8b%e3%82%89%e5%a4%89%e6%9b%b4%e3%81%99%e3%82%8b>#</a></h2><p>エラーには種類があり、デフォルトの <code>[error]</code> ではよくない場合もあるでしょう。</p><p><code>toml::format_error</code> では、 <code>toml::error_info</code> の前に <code>std::string</code> を取って、それを
|
||||
<code>[error]</code> の代わりに出力することができます。</p><p>例えば、</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>// エラーのタイトル
|
||||
</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>// 値の横に書くメッセージ
|
||||
</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>このようにすると、 <code>[warn]</code> から始まる警告を出力することができます。</p><p>他にも、<code>toml::format_error</code> に直接 <code>error_info</code> の構成要素を渡すことで、
|
||||
<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>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>// エラーのタイトル
|
||||
</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>// 値の横に書くメッセージ
|
||||
</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=複数の-tomlvalue-を指すエラーメッセージを作成する>複数の <code>toml::value</code> を指すエラーメッセージを作成する
|
||||
<a class=anchor href=#%e8%a4%87%e6%95%b0%e3%81%ae-tomlvalue-%e3%82%92%e6%8c%87%e3%81%99%e3%82%a8%e3%83%a9%e3%83%bc%e3%83%a1%e3%83%83%e3%82%bb%e3%83%bc%e3%82%b8%e3%82%92%e4%bd%9c%e6%88%90%e3%81%99%e3%82%8b>#</a></h2><p>アプリケーションの設定では、先に読み込んだ値によって後に読み込んだ値が取れる範囲が変わることがあるでしょう。</p><p>そのような場合には、エラーの原因となる別の値を同時に出力したいはずです。</p><p><code>toml::format_error</code> と <code>toml::make_error_info</code> は、 <code>toml::value</code> とそれに対応するエラーメッセージ <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>こちらも末尾に補足を追加することができます。</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 value 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><code>toml::value</code> または <code>toml::source_location</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=#エラーメッセージを出力する>エラーメッセージを出力する</a><ul><li><a href=#tomlvalue-の位置情報からエラーメッセージを作成する><code>toml::value</code> の位置情報からエラーメッセージを作成する</a></li><li><a href=#文字列に色を付ける>文字列に色を付ける</a></li><li><a href=#エラーメッセージのprefixをerrorから変更する>エラーメッセージのprefixを<code>[error]</code>から変更する</a></li><li><a href=#複数の-tomlvalue-を指すエラーメッセージを作成する>複数の <code>toml::value</code> を指すエラーメッセージを作成する</a></li></ul></li></ul></nav></div></aside></main></body></html>
|
||||
132
ja/docs/features/extension/index.html
Normal file
132
ja/docs/features/extension/index.html
Normal file
@@ -0,0 +1,132 @@
|
||||
<!doctype html><html lang=ja dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content='
|
||||
TOML言語拡張
|
||||
#
|
||||
|
||||
TOML言語は現在 v1.0.0 が最新版ですが、その後もいくつかの新機能が議論の末マージされ、
|
||||
v1.1.0に向けて議論が続いています。
|
||||
そこで議論された機能の中には、有用なケースが少ないと考えられたものや、
|
||||
提案された際の方向性では導入が難しいもの、導入がされなかったものも多くあります。
|
||||
toml11では、そのような機能のなかからいくつかを選んで、実験的に実装を行っています。
|
||||
これらはtoml11ではサポートされていますが、他のパーサではサポートされておらず、また
|
||||
サポートされる予定もないことに注意してください。
|
||||
また、これらの機能はデフォルトで使用されない設定になっており、
|
||||
使用するためには機能フラグをそれぞれ true にしなければなりません。
|
||||
非標準の機能なので、あえて明示的に書かなければ使えないように設計しています。
|
||||
いくつかの機能は今後TOML言語自体に新機能としてマージされる可能性があります。
|
||||
もし以下の拡張機能を完全に置き換えられる機能が導入された場合、拡張機能は
|
||||
本来の機能の実装後にマイナーバージョンアップで削除される可能性があります。
|
||||
|
||||
null
|
||||
#
|
||||
|
||||
TOMLファイル内で値としてnullを使えるようになります。
|
||||
a = null
|
||||
b = [ 1, 2, 3, null, 5]
|
||||
これを使用するには、 toml::spec の ext_null_value を true にします。
|
||||
パースすると、デフォルト構築した場合と同様の toml::value_t::empty となります。
|
||||
ただし、ファイル内の位置情報は設定されます。
|
||||
null は値の文脈でのみパースされるので、キーに null を使用した際はこれまで通り
|
||||
"null" という文字列のキーとして解釈されます。
|
||||
#include <toml.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
toml::spec spec;
|
||||
spec.ext_null_value = true;
|
||||
|
||||
const auto v = toml::parse_str("a = null", spec);
|
||||
|
||||
assert(v.at("a").is_empty());
|
||||
assert(v.at("a").is(toml::value_t::empty));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
浮動小数点数の16進数フォーマット
|
||||
#
|
||||
|
||||
TOMLファイル内で浮動小数点数に16進数フォーマットを使用できるようになります。'><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/ja/docs/features/extension/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="extension"><meta property="og:description" content='TOML言語拡張 # TOML言語は現在 v1.0.0 が最新版ですが、その後もいくつかの新機能が議論の末マージされ、 v1.1.0に向けて議論が続いています。
|
||||
そこで議論された機能の中には、有用なケースが少ないと考えられたものや、 提案された際の方向性では導入が難しいもの、導入がされなかったものも多くあります。
|
||||
toml11では、そのような機能のなかからいくつかを選んで、実験的に実装を行っています。 これらはtoml11ではサポートされていますが、他のパーサではサポートされておらず、また サポートされる予定もないことに注意してください。
|
||||
また、これらの機能はデフォルトで使用されない設定になっており、 使用するためには機能フラグをそれぞれ true にしなければなりません。 非標準の機能なので、あえて明示的に書かなければ使えないように設計しています。
|
||||
いくつかの機能は今後TOML言語自体に新機能としてマージされる可能性があります。 もし以下の拡張機能を完全に置き換えられる機能が導入された場合、拡張機能は 本来の機能の実装後にマイナーバージョンアップで削除される可能性があります。
|
||||
null # TOMLファイル内で値としてnullを使えるようになります。
|
||||
a = null b = [ 1, 2, 3, null, 5] これを使用するには、 toml::spec の ext_null_value を true にします。
|
||||
パースすると、デフォルト構築した場合と同様の toml::value_t::empty となります。 ただし、ファイル内の位置情報は設定されます。
|
||||
null は値の文脈でのみパースされるので、キーに null を使用した際はこれまで通り "null" という文字列のキーとして解釈されます。
|
||||
#include <toml.hpp> int main() { toml::spec spec; spec.ext_null_value = true; const auto v = toml::parse_str("a = null", spec); assert(v.at("a").is_empty()); assert(v.at("a").is(toml::value_t::empty)); return 0; } 浮動小数点数の16進数フォーマット # TOMLファイル内で浮動小数点数に16進数フォーマットを使用できるようになります。'><meta property="og:locale" content="ja"><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/ja/docs/features/extension/><link rel=alternate hreflang=en href=https://toruniina.github.io/toml11/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/ja.search.min.b1a1e3e4be0fdf11fae2bb2370353d99ecd7abea7ccc29273319c021dda76dfd.js integrity="sha256-saHj5L4P3xH64rsjcDU9mezXq+p8zCknMxnAId2nbf0=" 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/ja/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=検索 aria-label=検索 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>
|
||||
日本語</a></label><ul><li><a href=https://toruniina.github.io/toml11/docs/features/extension/>English</a></li></ul></li></ul><ul><li><a href=/toml11/ja/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-b4cfb5b55e913a8d853eacf5e8fba05f class=toggle checked>
|
||||
<label for=section-b4cfb5b55e913a8d853eacf5e8fba05f class="flex justify-between"><a href=/toml11/ja/docs/features/>features</a></label><ul><li><a href=/toml11/ja/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/ja/docs/features/value/>getting values</a></li><li><a href=/toml11/ja/docs/features/error_message/>error message</a></li><li><a href=/toml11/ja/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/ja/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/ja/docs/features/literal/>toml literal</a></li><li><a href=/toml11/ja/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/ja/docs/features/extension/ class=active>extension</a></li></ul></li><li><input type=checkbox id=section-01b096afc5186aea96713b408b47c967 class=toggle>
|
||||
<label for=section-01b096afc5186aea96713b408b47c967 class="flex justify-between"><a href=/toml11/ja/docs/reference/>reference</a></label><ul><li><a href=/toml11/ja/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/ja/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/ja/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/ja/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/ja/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/ja/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/ja/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/ja/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/ja/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/ja/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/ja/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/ja/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/ja/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/ja/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/ja/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/ja/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/ja/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/ja/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/ja/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/ja/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/ja/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/ja/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/ja/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/ja/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言語拡張>TOML言語拡張</a><ul><li><a href=#null><code>null</code></a></li><li><a href=#浮動小数点数の16進数フォーマット>浮動小数点数の16進数フォーマット</a></li><li><a href=#整数浮動小数点数のsuffix>整数・浮動小数点数のsuffix</a></li></ul></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=toml言語拡張>TOML言語拡張
|
||||
<a class=anchor href=#toml%e8%a8%80%e8%aa%9e%e6%8b%a1%e5%bc%b5>#</a></h1><p>TOML言語は現在 v1.0.0 が最新版ですが、その後もいくつかの新機能が議論の末マージされ、
|
||||
v1.1.0に向けて議論が続いています。</p><p>そこで議論された機能の中には、有用なケースが少ないと考えられたものや、
|
||||
提案された際の方向性では導入が難しいもの、導入がされなかったものも多くあります。</p><p>toml11では、そのような機能のなかからいくつかを選んで、実験的に実装を行っています。
|
||||
これらはtoml11ではサポートされていますが、他のパーサではサポートされておらず、また
|
||||
サポートされる予定もないことに注意してください。</p><p>また、これらの機能はデフォルトで使用されない設定になっており、
|
||||
使用するためには機能フラグをそれぞれ <code>true</code> にしなければなりません。
|
||||
非標準の機能なので、あえて明示的に書かなければ使えないように設計しています。</p><p>いくつかの機能は今後TOML言語自体に新機能としてマージされる可能性があります。
|
||||
もし以下の拡張機能を完全に置き換えられる機能が導入された場合、拡張機能は
|
||||
本来の機能の実装後にマイナーバージョンアップで削除される可能性があります。</p><h2 id=null><code>null</code>
|
||||
<a class=anchor href=#null>#</a></h2><p>TOMLファイル内で値として<code>null</code>を使えるようになります。</p><pre tabindex=0><code>a = null
|
||||
b = [ 1, 2, 3, null, 5]
|
||||
</code></pre><p>これを使用するには、 <code>toml::spec</code> の <code>ext_null_value</code> を <code>true</code> にします。</p><p>パースすると、デフォルト構築した場合と同様の <code>toml::value_t::empty</code> となります。
|
||||
ただし、ファイル内の位置情報は設定されます。</p><p><code>null</code> は値の文脈でのみパースされるので、キーに <code>null</code> を使用した際はこれまで通り
|
||||
<code>"null"</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_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=浮動小数点数の16進数フォーマット>浮動小数点数の16進数フォーマット
|
||||
<a class=anchor href=#%e6%b5%ae%e5%8b%95%e5%b0%8f%e6%95%b0%e7%82%b9%e6%95%b0%e3%81%ae16%e9%80%b2%e6%95%b0%e3%83%95%e3%82%a9%e3%83%bc%e3%83%9e%e3%83%83%e3%83%88>#</a></h2><p>TOMLファイル内で浮動小数点数に16進数フォーマットを使用できるようになります。</p><pre tabindex=0><code>a = 0x1.91eb851eb851fp+1 # 3.14
|
||||
</code></pre><p>これを使用するには、 <code>toml::spec</code> の <code>ext_hex_float</code> を <code>true</code> にします。</p><p>フォーマットは <code>printf</code> で <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=整数浮動小数点数のsuffix>整数・浮動小数点数のsuffix
|
||||
<a class=anchor href=#%e6%95%b4%e6%95%b0%e6%b5%ae%e5%8b%95%e5%b0%8f%e6%95%b0%e7%82%b9%e6%95%b0%e3%81%aesuffix>#</a></h2><p>TOMLファイル内で数値の後ろにsuffixをつけられるようになります。
|
||||
10進数表記の整数と浮動小数点数で使用できます。</p><p>単位を表示するときなどに便利です。</p><pre tabindex=0><code>a = 86_400_sec
|
||||
b = 3.1416_rad
|
||||
c = 10_μm
|
||||
</code></pre><p>ですが、これらはあくまで単なる <code>suffix</code> であり、単位換算は行われません。
|
||||
単位換算が必要な場合は、ユーザーが <code>suffix</code> を参照して実装してください。</p><p>これを使用するには、 <code>toml::spec</code> の <code>ext_num_suffix</code> を <code>true</code> にします。</p><p>数値と接尾辞の間は<code>_</code>で区切られている必要があります。</p><p>数値部分との区別のため、suffixは数値で始まることはできません。</p><pre tabindex=0><code>distance = 100_m # valid
|
||||
distance = 10_0m # invalid
|
||||
distance = 10_0_m # valid
|
||||
</code></pre><p>接尾辞は<code>std::string 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><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言語拡張>TOML言語拡張</a><ul><li><a href=#null><code>null</code></a></li><li><a href=#浮動小数点数の16進数フォーマット>浮動小数点数の16進数フォーマット</a></li><li><a href=#整数浮動小数点数のsuffix>整数・浮動小数点数のsuffix</a></li></ul></li></ul></nav></div></aside></main></body></html>
|
||||
136
ja/docs/features/index.html
Normal file
136
ja/docs/features/index.html
Normal file
@@ -0,0 +1,136 @@
|
||||
<!doctype html><html lang=ja dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
|
||||
features
|
||||
#
|
||||
|
||||
ここでは、toml11が提供する主な機能について、例を挙げながら説明します。
|
||||
|
||||
ファイル・文字列をパースする
|
||||
#
|
||||
|
||||
ファイルや文字列をパースする関数と、それが出力するエラーの扱い方について説明します。
|
||||
以下の内容を含みます。
|
||||
|
||||
ファイルをパースする
|
||||
文字列をパースする
|
||||
バイト列をパースする
|
||||
例外を投げずにファイルをパースする
|
||||
例外を投げずに文字列をパースする
|
||||
例外を投げずにバイト列をパースする
|
||||
|
||||
|
||||
toml::valueから値を取り出す
|
||||
#
|
||||
|
||||
toml::valueが持つデータの型を調べ、取り出す方法、型変換を行う方法について説明します。
|
||||
以下の内容を含みます。
|
||||
|
||||
メンバ関数を使って値の型を調べる
|
||||
メンバ関数を使って値にアクセスする
|
||||
コメントにアクセスする
|
||||
インラインテーブル・ドットキーの取り扱い
|
||||
日付情報の取り扱い
|
||||
toml::get<T>を使って変換する
|
||||
toml::get_orを使って失敗時の値を指定する
|
||||
toml::find<T>を使って検索と変換を行う
|
||||
toml::find_orを使って失敗時の値を指定する
|
||||
ユーザー定義型との変換を定義する
|
||||
toml::visitで関数を適用する
|
||||
toml::valueを構築する
|
||||
|
||||
|
||||
エラーメッセージを作る
|
||||
#
|
||||
|
||||
toml::valueの値を使って、TOMLファイル中の位置情報つきのエラーメッセージを生成する方法について説明します。
|
||||
以下の内容を含みます。
|
||||
|
||||
toml::value の位置情報を取り出す
|
||||
エラーメッセージを構築する
|
||||
出力に色を付ける
|
||||
|
||||
|
||||
TOMLファイルを出力する
|
||||
#
|
||||
|
||||
toml::valueの値をフォーマットする方法と、可能なフォーマット指定について説明します。
|
||||
以下の内容を含みます。
|
||||
|
||||
toml::valueの値ごとにフォーマットを指定する
|
||||
toml::valueをフォーマットして文字列化する
|
||||
|
||||
|
||||
toml::valueの型を変更する
|
||||
#
|
||||
|
||||
toml::valueが格納する型(integer_typeやtable_typeをカスタマイズする方法について説明します。
|
||||
以下の内容を含みます。
|
||||
|
||||
type_configの定義
|
||||
ordered_type_configを使用する
|
||||
コメントを保存しないようにする
|
||||
std::dequeなどの異なるコンテナを使用する
|
||||
boost::multiprecisionなどの異なる数値型を使用する
|
||||
|
||||
|
||||
TOMLリテラル
|
||||
#
|
||||
|
||||
C++内にTOMLファイルを埋め込むための_tomlリテラルについて説明します。
|
||||
以下の内容を含みます。
|
||||
|
||||
TOMLリテラルを使用する
|
||||
|
||||
|
||||
TOML言語バージョン
|
||||
#
|
||||
|
||||
toml11がサポートするTOML言語のバージョン、主にTOML-v1.1.0で追加された言語機能を制御する方法について説明します。
|
||||
以下の内容を含みます。
|
||||
|
||||
TOML言語の1.1.0を使用する
|
||||
TOML言語の1.1.0の一部の機能のみ使用する
|
||||
|
||||
|
||||
TOML言語拡張
|
||||
#
|
||||
|
||||
toml11独自のTOML言語拡張について説明します。
|
||||
以下の内容を含みます。
|
||||
|
||||
null をサポートする
|
||||
浮動小数点数の16進数フォーマットをサポートする
|
||||
数値に単位を付けられるようにする
|
||||
"><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/ja/docs/features/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="features"><meta property="og:description" content="features # ここでは、toml11が提供する主な機能について、例を挙げながら説明します。
|
||||
ファイル・文字列をパースする # ファイルや文字列をパースする関数と、それが出力するエラーの扱い方について説明します。
|
||||
以下の内容を含みます。
|
||||
ファイルをパースする 文字列をパースする バイト列をパースする 例外を投げずにファイルをパースする 例外を投げずに文字列をパースする 例外を投げずにバイト列をパースする toml::valueから値を取り出す # toml::valueが持つデータの型を調べ、取り出す方法、型変換を行う方法について説明します。
|
||||
以下の内容を含みます。
|
||||
メンバ関数を使って値の型を調べる メンバ関数を使って値にアクセスする コメントにアクセスする インラインテーブル・ドットキーの取り扱い 日付情報の取り扱い toml::get<T>を使って変換する toml::get_orを使って失敗時の値を指定する toml::find<T>を使って検索と変換を行う toml::find_orを使って失敗時の値を指定する ユーザー定義型との変換を定義する toml::visitで関数を適用する toml::valueを構築する エラーメッセージを作る # toml::valueの値を使って、TOMLファイル中の位置情報つきのエラーメッセージを生成する方法について説明します。
|
||||
以下の内容を含みます。
|
||||
toml::value の位置情報を取り出す エラーメッセージを構築する 出力に色を付ける TOMLファイルを出力する # toml::valueの値をフォーマットする方法と、可能なフォーマット指定について説明します。
|
||||
以下の内容を含みます。
|
||||
toml::valueの値ごとにフォーマットを指定する toml::valueをフォーマットして文字列化する toml::valueの型を変更する # toml::valueが格納する型(integer_typeやtable_typeをカスタマイズする方法について説明します。
|
||||
以下の内容を含みます。
|
||||
type_configの定義 ordered_type_configを使用する コメントを保存しないようにする std::dequeなどの異なるコンテナを使用する boost::multiprecisionなどの異なる数値型を使用する TOMLリテラル # C++内にTOMLファイルを埋め込むための_tomlリテラルについて説明します。
|
||||
以下の内容を含みます。
|
||||
TOMLリテラルを使用する TOML言語バージョン # toml11がサポートするTOML言語のバージョン、主にTOML-v1.1.0で追加された言語機能を制御する方法について説明します。
|
||||
以下の内容を含みます。
|
||||
TOML言語の1.1.0を使用する TOML言語の1.1.0の一部の機能のみ使用する TOML言語拡張 # toml11独自のTOML言語拡張について説明します。
|
||||
以下の内容を含みます。
|
||||
null をサポートする 浮動小数点数の16進数フォーマットをサポートする 数値に単位を付けられるようにする"><meta property="og:locale" content="ja"><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/ja/docs/features/><link rel=alternate hreflang=en href=https://toruniina.github.io/toml11/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/ja.search.min.b1a1e3e4be0fdf11fae2bb2370353d99ecd7abea7ccc29273319c021dda76dfd.js integrity="sha256-saHj5L4P3xH64rsjcDU9mezXq+p8zCknMxnAId2nbf0=" crossorigin=anonymous></script><link rel=alternate type=application/rss+xml href=https://toruniina.github.io/toml11/ja/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/ja/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=検索 aria-label=検索 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>
|
||||
日本語</a></label><ul><li><a href=https://toruniina.github.io/toml11/docs/features/>English</a></li></ul></li></ul><ul><li><a href=/toml11/ja/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-b4cfb5b55e913a8d853eacf5e8fba05f class=toggle checked>
|
||||
<label for=section-b4cfb5b55e913a8d853eacf5e8fba05f class="flex justify-between"><a href=/toml11/ja/docs/features/ class=active>features</a></label><ul><li><a href=/toml11/ja/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/ja/docs/features/value/>getting values</a></li><li><a href=/toml11/ja/docs/features/error_message/>error message</a></li><li><a href=/toml11/ja/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/ja/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/ja/docs/features/literal/>toml literal</a></li><li><a href=/toml11/ja/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/ja/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-01b096afc5186aea96713b408b47c967 class=toggle>
|
||||
<label for=section-01b096afc5186aea96713b408b47c967 class="flex justify-between"><a href=/toml11/ja/docs/reference/>reference</a></label><ul><li><a href=/toml11/ja/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/ja/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/ja/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/ja/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/ja/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/ja/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/ja/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/ja/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/ja/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/ja/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/ja/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/ja/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/ja/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/ja/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/ja/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/ja/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/ja/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/ja/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/ja/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/ja/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/ja/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/ja/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/ja/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/ja/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=#ファイル文字列をパースする>ファイル・文字列をパースする</a></li><li><a href=#tomlvalue><code>toml::value</code>から値を取り出す</a></li><li><a href=#エラーメッセージを作る>エラーメッセージを作る</a></li><li><a href=#tomlファイルを出力する>TOMLファイルを出力する</a></li><li><a href=#tomlvalue-1><code>toml::value</code>の型を変更する</a></li><li><a href=#tomlリテラル>TOMLリテラル</a></li><li><a href=#toml言語バージョン>TOML言語バージョン</a></li><li><a href=#toml言語拡張>TOML言語拡張</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>ここでは、toml11が提供する主な機能について、例を挙げながら説明します。</p><h2 id=ファイル文字列をパースする><a href=parsing_files>ファイル・文字列をパースする</a>
|
||||
<a class=anchor href=#%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e6%96%87%e5%ad%97%e5%88%97%e3%82%92%e3%83%91%e3%83%bc%e3%82%b9%e3%81%99%e3%82%8b>#</a></h2><p>ファイルや文字列をパースする関数と、それが出力するエラーの扱い方について説明します。</p><p>以下の内容を含みます。</p><ul><li>ファイルをパースする</li><li>文字列をパースする</li><li>バイト列をパースする</li><li>例外を投げずにファイルをパースする</li><li>例外を投げずに文字列をパースする</li><li>例外を投げずにバイト列をパースする</li></ul><h2 id=tomlvalue><a href=value><code>toml::value</code>から値を取り出す</a>
|
||||
<a class=anchor href=#tomlvalue>#</a></h2><p><code>toml::value</code>が持つデータの型を調べ、取り出す方法、型変換を行う方法について説明します。</p><p>以下の内容を含みます。</p><ul><li>メンバ関数を使って値の型を調べる</li><li>メンバ関数を使って値にアクセスする</li><li>コメントにアクセスする</li><li>インラインテーブル・ドットキーの取り扱い</li><li>日付情報の取り扱い</li><li><code>toml::get<T></code>を使って変換する</li><li><code>toml::get_or</code>を使って失敗時の値を指定する</li><li><code>toml::find<T></code>を使って検索と変換を行う</li><li><code>toml::find_or</code>を使って失敗時の値を指定する</li><li>ユーザー定義型との変換を定義する</li><li><code>toml::visit</code>で関数を適用する</li><li><code>toml::value</code>を構築する</li></ul><h2 id=エラーメッセージを作る><a href=error_message>エラーメッセージを作る</a>
|
||||
<a class=anchor href=#%e3%82%a8%e3%83%a9%e3%83%bc%e3%83%a1%e3%83%83%e3%82%bb%e3%83%bc%e3%82%b8%e3%82%92%e4%bd%9c%e3%82%8b>#</a></h2><p><code>toml::value</code>の値を使って、TOMLファイル中の位置情報つきのエラーメッセージを生成する方法について説明します。</p><p>以下の内容を含みます。</p><ul><li><code>toml::value</code> の位置情報を取り出す</li><li>エラーメッセージを構築する</li><li>出力に色を付ける</li></ul><h2 id=tomlファイルを出力する><a href=serialize>TOMLファイルを出力する</a>
|
||||
<a class=anchor href=#toml%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%82%92%e5%87%ba%e5%8a%9b%e3%81%99%e3%82%8b>#</a></h2><p><code>toml::value</code>の値をフォーマットする方法と、可能なフォーマット指定について説明します。</p><p>以下の内容を含みます。</p><ul><li><code>toml::value</code>の値ごとにフォーマットを指定する</li><li><code>toml::value</code>をフォーマットして文字列化する</li></ul><h2 id=tomlvalue-1><a href=configure_types><code>toml::value</code>の型を変更する</a>
|
||||
<a class=anchor href=#tomlvalue-1>#</a></h2><p><code>toml::value</code>が格納する型(<code>integer_type</code>や<code>table_type</code>をカスタマイズする方法について説明します。</p><p>以下の内容を含みます。</p><ul><li><code>type_config</code>の定義</li><li><code>ordered_type_config</code>を使用する</li><li>コメントを保存しないようにする</li><li><code>std::deque</code>などの異なるコンテナを使用する</li><li><code>boost::multiprecision</code>などの異なる数値型を使用する</li></ul><h2 id=tomlリテラル><a href=literal>TOMLリテラル</a>
|
||||
<a class=anchor href=#toml%e3%83%aa%e3%83%86%e3%83%a9%e3%83%ab>#</a></h2><p>C++内にTOMLファイルを埋め込むための<code>_toml</code>リテラルについて説明します。</p><p>以下の内容を含みます。</p><ul><li>TOMLリテラルを使用する</li></ul><h2 id=toml言語バージョン><a href=toml_spec>TOML言語バージョン</a>
|
||||
<a class=anchor href=#toml%e8%a8%80%e8%aa%9e%e3%83%90%e3%83%bc%e3%82%b8%e3%83%a7%e3%83%b3>#</a></h2><p>toml11がサポートするTOML言語のバージョン、主にTOML-v1.1.0で追加された言語機能を制御する方法について説明します。</p><p>以下の内容を含みます。</p><ul><li>TOML言語の1.1.0を使用する</li><li>TOML言語の1.1.0の一部の機能のみ使用する</li></ul><h2 id=toml言語拡張><a href=extension>TOML言語拡張</a>
|
||||
<a class=anchor href=#toml%e8%a8%80%e8%aa%9e%e6%8b%a1%e5%bc%b5>#</a></h2><p>toml11独自のTOML言語拡張について説明します。</p><p>以下の内容を含みます。</p><ul><li><code>null</code> をサポートする</li><li>浮動小数点数の16進数フォーマットをサポートする</li><li>数値に単位を付けられるようにする</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=#ファイル文字列をパースする>ファイル・文字列をパースする</a></li><li><a href=#tomlvalue><code>toml::value</code>から値を取り出す</a></li><li><a href=#エラーメッセージを作る>エラーメッセージを作る</a></li><li><a href=#tomlファイルを出力する>TOMLファイルを出力する</a></li><li><a href=#tomlvalue-1><code>toml::value</code>の型を変更する</a></li><li><a href=#tomlリテラル>TOMLリテラル</a></li><li><a href=#toml言語バージョン>TOML言語バージョン</a></li><li><a href=#toml言語拡張>TOML言語拡張</a></li></ul></li></ul></nav></div></aside></main></body></html>
|
||||
341
ja/docs/features/index.xml
Normal file
341
ja/docs/features/index.xml
Normal file
@@ -0,0 +1,341 @@
|
||||
<?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/ja/docs/features/</link><description>Recent content in features on toml11</description><generator>Hugo</generator><language>ja</language><atom:link href="https://toruniina.github.io/toml11/ja/docs/features/index.xml" rel="self" type="application/rss+xml"/><item><title>parsing files</title><link>https://toruniina.github.io/toml11/ja/docs/features/parsing_files/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/ja/docs/features/parsing_files/</guid><description><h1 id="ファイル文字列をパースする">
|
||||
ファイル・文字列をパースする
|
||||
<a class="anchor" href="#%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e6%96%87%e5%ad%97%e5%88%97%e3%82%92%e3%83%91%e3%83%bc%e3%82%b9%e3%81%99%e3%82%8b">#</a>
|
||||
</h1>
|
||||
<p>toml11では、<code>toml::parse</code> や <code>toml::try_parse</code> を使って、ファイルや文字列、バイト列をパースすることができます。</p>
|
||||
<p>これらは成功時に <code>toml::value</code> を返します。
|
||||
ファイルは常にテーブルになりますが、返り値が <code>toml::table</code> でないことに気を付けてください。
|
||||
<code>toml::value</code> はファイルに関するメタデータを持っており、
|
||||
<code>toml::table</code> は <code>std::unordered_map&lt;std::stirng, toml::value&gt;</code> のエイリアスでしかありません。
|
||||
メタデータを返すために、 <code>toml::table</code> ではなく <code>toml::value</code> を返しています。
|
||||
ファイルのルートに対応する <code>toml::value</code> は常に <code>table_type</code> を持ちます。</p>
|
||||
<h2 id="ファイルをパースする">
|
||||
ファイルをパースする
|
||||
<a class="anchor" href="#%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%82%92%e3%83%91%e3%83%bc%e3%82%b9%e3%81%99%e3%82%8b">#</a>
|
||||
</h2>
|
||||
<p>ファイルをパースする際は、
|
||||
<a href="https://toruniina.github.io/toml11/ja/docs/reference/parser/#parse"><code>toml::parse</code></a>
|
||||
または
|
||||
<a href="https://toruniina.github.io/toml11/ja/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="stdstringでファイル名を指定する">
|
||||
<code>std::string</code>でファイル名を指定する
|
||||
<a class="anchor" href="#stdstring%e3%81%a7%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e5%90%8d%e3%82%92%e6%8c%87%e5%ae%9a%e3%81%99%e3%82%8b">#</a>
|
||||
</h4>
|
||||
<p><a href="https://toruniina.github.io/toml11/ja/docs/reference/parser/#parse"><code>toml::parse</code></a>
|
||||
は、文字列でファイル名を受け取り、そのファイルを開いてパースします。</p>
|
||||
<p>以下のサンプルは、<code>input.toml</code>というファイルをパースし、<code>title</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">&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;iostream&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 input <span style="color:#f92672">=</span> toml<span style="color:#f92672">::</span>parse(<span style="color:#e6db74">&#34;input.toml&#34;</span>);
|
||||
</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>cout <span style="color:#f92672">&lt;&lt;</span> input.at(<span style="color:#e6db74">&#34;title&#34;</span>).as_string() <span style="color:#f92672">&lt;&lt;</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="stdfilesystempathでファイルを指定する">
|
||||
<code>std::filesystem::path</code>でファイルを指定する
|
||||
<a class="anchor" href="#stdfilesystempath%e3%81%a7%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%82%92%e6%8c%87%e5%ae%9a%e3%81%99%e3%82%8b">#</a>
|
||||
</h4>
|
||||
<p><a href="https://toruniina.github.io/toml11/ja/docs/reference/parser/#parse"><code>toml::parse</code></a>
|
||||
には、<code>std::filesystem::path</code>を渡すことも可能です。</p>
|
||||
<p>当然ですが、<code>&lt;filesystem&gt;</code>がサポートされるC++17以降でなければ使用できません。</p>
|
||||
<h4 id="stdistreamで入力ストリームを指定する">
|
||||
<code>std::istream</code>で入力ストリームを指定する
|
||||
<a class="anchor" href="#stdistream%e3%81%a7%e5%85%a5%e5%8a%9b%e3%82%b9%e3%83%88%e3%83%aa%e3%83%bc%e3%83%a0%e3%82%92%e6%8c%87%e5%ae%9a%e3%81%99%e3%82%8b">#</a>
|
||||
</h4>
|
||||
<p><a href="https://toruniina.github.io/toml11/ja/docs/reference/parser/#parse"><code>toml::parse</code></a>
|
||||
には、<code>std::istream</code>を渡すことも可能です。</p></description></item><item><title>getting values</title><link>https://toruniina.github.io/toml11/ja/docs/features/value/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/ja/docs/features/value/</guid><description><h1 id="値を取り出す">
|
||||
値を取り出す
|
||||
<a class="anchor" href="#%e5%80%a4%e3%82%92%e5%8f%96%e3%82%8a%e5%87%ba%e3%81%99">#</a>
|
||||
</h1>
|
||||
<p>ここでは、 <code>toml::value</code> が格納している値にアクセスする方法を説明します。</p>
|
||||
<h2 id="メンバ関数を使って値にアクセスする">
|
||||
メンバ関数を使って値にアクセスする
|
||||
<a class="anchor" href="#%e3%83%a1%e3%83%b3%e3%83%90%e9%96%a2%e6%95%b0%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e5%80%a4%e3%81%ab%e3%82%a2%e3%82%af%e3%82%bb%e3%82%b9%e3%81%99%e3%82%8b">#</a>
|
||||
</h2>
|
||||
<h3 id="is_something-と-as_something">
|
||||
<code>is_something</code> と <code>as_something</code>
|
||||
<a class="anchor" href="#is_something-%e3%81%a8-as_something">#</a>
|
||||
</h3>
|
||||
<p><code>toml::value</code> は <code>is_boolean()</code> や <code>is_integer()</code> などのメンバ関数を持っており、
|
||||
これらを使うと持っている型を調べることができます。</p>
|
||||
<p>また、 <code>as_boolean()</code>, <code>as_integer()</code> などのメンバ関数も持っており、
|
||||
これらを使ってその型にアクセスすることができます。</p>
|
||||
<p>完全なリストは <a href="https://toruniina.github.io/toml11/ja/docs/reference/value/#is_xxx"><code>toml::value</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>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_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">&lt;&lt;</span> v.as_integer() <span style="color:#f92672">&lt;&lt;</span> std<span style="color:#f92672">::</span>endl;
|
||||
</span></span><span style="display:flex;"><span>}
|
||||
</span></span></code></pre></div><p>指定された値と異なる型が格納されていた場合、 <a href="https://toruniina.github.io/toml11/ja/docs/reference/value/#tomltype_error"><code>toml::type_error</code></a> が送出されます。</p>
|
||||
<p>その <code>what()</code> は以下のようなメッセージを含みます。</p>
|
||||
<pre tabindex="0"><code>[error] toml::value::as_string(): bad_cast to string
|
||||
--&gt; 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>型情報は <a href="https://toruniina.github.io/toml11/ja/docs/reference/value_t/"><code>enum class toml::value_t</code></a> で識別できます。</p></description></item><item><title>error message</title><link>https://toruniina.github.io/toml11/ja/docs/features/error_message/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/ja/docs/features/error_message/</guid><description><h1 id="エラーメッセージを出力する">
|
||||
エラーメッセージを出力する
|
||||
<a class="anchor" href="#%e3%82%a8%e3%83%a9%e3%83%bc%e3%83%a1%e3%83%83%e3%82%bb%e3%83%bc%e3%82%b8%e3%82%92%e5%87%ba%e5%8a%9b%e3%81%99%e3%82%8b">#</a>
|
||||
</h1>
|
||||
<p>toml11は <code>toml::parse</code> や <code>toml::get&lt;T&gt;/find&lt;T&gt;</code>, <code>as_integer()</code> などから
|
||||
ファイル内の位置情報を含んだエラーメッセージを出力します。</p>
|
||||
<p>例えば、パース時に整数の文法エラーを発見した場合、</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>あるいは実際に格納されている型と異なる型を要求した場合</p>
|
||||
<pre tabindex="0"><code>[error] toml::value::as_string(): bad_cast to string
|
||||
--&gt; input.toml
|
||||
|
|
||||
1 | a = 123_456
|
||||
| ^^^^^^^-- the actual type is integer
|
||||
</code></pre><p>toml11は <code>toml::value</code> からこのようなエラーメッセージを作成する方法を提供します。</p></description></item><item><title>serializing values</title><link>https://toruniina.github.io/toml11/ja/docs/features/serialize/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/ja/docs/features/serialize/</guid><description><h1 id="tomlファイルを出力する">
|
||||
TOMLファイルを出力する
|
||||
<a class="anchor" href="#toml%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%82%92%e5%87%ba%e5%8a%9b%e3%81%99%e3%82%8b">#</a>
|
||||
</h1>
|
||||
<p><code>toml::format</code> を使うと、 <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:#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><code>table_type</code> を格納している <code>toml::value</code> が渡されると、それがファイルのルートテーブルとして解釈されます。</p>
|
||||
<p>もし <code>table_type</code> 以外を格納している <code>toml::value</code> が渡されると、その値だけがフォーマットされます。</p>
|
||||
<p>一部のフォーマット指定では、キーが渡されていないとフォーマットできないことがあります。
|
||||
例えば、 <code>toml::array_format::array_of_tables</code> は <code>[[array.of.tables]]</code> の形でフォーマットするので、
|
||||
キーへのアクセスを要求します。</p>
|
||||
<p>キーを要求するフォーマット指定の値がキーなしで渡された場合、 <code>toml::serialization_error</code> が送出されます。</p>
|
||||
<p>他にも、フォーマット指定と矛盾する値が含まれる場合には、 <code>toml::serialization_error</code> が送出されます。
|
||||
例えば、 <code>integer_format::hex</code> が指定された整数が負の値を持っている場合や、
|
||||
<code>string_format::literal</code> が指定された文字列が改行を含んでいる場合などです。</p>
|
||||
<p>フォーマットの指定方法は後述します。</p>
|
||||
<h2 id="キーを渡して出力する">
|
||||
キーを渡して出力する
|
||||
<a class="anchor" href="#%e3%82%ad%e3%83%bc%e3%82%92%e6%b8%a1%e3%81%97%e3%81%a6%e5%87%ba%e5%8a%9b%e3%81%99%e3%82%8b">#</a>
|
||||
</h2>
|
||||
<p><code>toml::format</code> には <code>std::string</code> としてキーを渡すことが可能です。</p></description></item><item><title>configuring types</title><link>https://toruniina.github.io/toml11/ja/docs/features/configure_types/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/ja/docs/features/configure_types/</guid><description><h1 id="型をカスタマイズする">
|
||||
型をカスタマイズする
|
||||
<a class="anchor" href="#%e5%9e%8b%e3%82%92%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%9e%e3%82%a4%e3%82%ba%e3%81%99%e3%82%8b">#</a>
|
||||
</h1>
|
||||
<p><code>toml::value</code> は <code>integer_type</code> として <code>std::int64_t</code> を、
|
||||
<code>table_type</code> として <code>std::unordered_map&lt;key_type, value_type&gt;</code> を使用します。</p>
|
||||
<p>しかし、場合によっては <code>boost::multiprecision::int128_t</code> や、 <code>std::map</code> を使用したい場合もあります。</p>
|
||||
<p>そのため、 <code>toml::value</code> は <code>template</code> 引数を取って格納する型を変えられるように実装されています。</p>
|
||||
<p><code>std::string</code> が実際には <code>std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt;</code> の
|
||||
エイリアスであるように、 <code>toml::value</code> は実際には <code>toml::basic_value&lt;toml::type_config&gt;</code> のエイリアスです。</p>
|
||||
<p>ここでは、 <code>toml::type_config</code> が持つ型と、異なる <code>config</code> 型を定義する方法を説明します。</p>
|
||||
<h2 id="type_config">
|
||||
<code>type_config</code>
|
||||
<a class="anchor" href="#type_config">#</a>
|
||||
</h2>
|
||||
<p><code>type_config</code> は、以下のメンバ型と<code>static</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></code></pre></div><p><code>toml::basic_value&lt;TypeConfig&gt;</code> は、格納する <code>boolean_type</code> を <code>TypeConfig::boolean_type</code>、
|
||||
格納する <code>integer_type</code> を <code>TypeConfig::integer_type</code> 、のようにして定義しています。</p></description></item><item><title>toml literal</title><link>https://toruniina.github.io/toml11/ja/docs/features/literal/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/ja/docs/features/literal/</guid><description><h1 id="_tomlリテラル">
|
||||
<code>_toml</code>リテラル
|
||||
<a class="anchor" href="#_toml%e3%83%aa%e3%83%86%e3%83%a9%e3%83%ab">#</a>
|
||||
</h1>
|
||||
<p><code>&quot;&quot;_toml</code>リテラルによって、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">&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>改行を含む場合、生文字列リテラルが便利です。</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>値が単体で書かれていた場合、その値が返されます。</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> a <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;42&#34;</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">&#34;12:34:56&#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> assert(v.at(<span style="color:#e6db74">&#34;b&#34;</span>).as_local_time().hour <span style="color:#f92672">==</span> <span style="color:#ae81ff">12</span>);
|
||||
</span></span><span style="display:flex;"><span> assert(v.at(<span style="color:#e6db74">&#34;b&#34;</span>).as_local_time().minute <span style="color:#f92672">==</span> <span style="color:#ae81ff">34</span>);
|
||||
</span></span><span style="display:flex;"><span> assert(v.at(<span style="color:#e6db74">&#34;b&#34;</span>).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は数値のみからなるキーを許可しています。
|
||||
よって、<code>[1]</code>はテーブル名として合法です。</p></description></item><item><title>toml spec</title><link>https://toruniina.github.io/toml11/ja/docs/features/toml_spec/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/ja/docs/features/toml_spec/</guid><description><h1 id="toml言語バージョン">
|
||||
TOML言語バージョン
|
||||
<a class="anchor" href="#toml%e8%a8%80%e8%aa%9e%e3%83%90%e3%83%bc%e3%82%b8%e3%83%a7%e3%83%b3">#</a>
|
||||
</h1>
|
||||
<p><a href="https://toruniina.github.io/toml11/ja/docs/reference/spec/#tomlspec"><code>toml::spec</code></a>
|
||||
によって、 <code>toml::parse</code> や <code>toml::format</code> で使用するTOML言語のバージョンや、個別の機能フラグを指定することができます。</p>
|
||||
<h2 id="tomlのバージョンを指定する">
|
||||
TOMLのバージョンを指定する
|
||||
<a class="anchor" href="#toml%e3%81%ae%e3%83%90%e3%83%bc%e3%82%b8%e3%83%a7%e3%83%b3%e3%82%92%e6%8c%87%e5%ae%9a%e3%81%99%e3%82%8b">#</a>
|
||||
</h2>
|
||||
<p><a href="https://toruniina.github.io/toml11/ja/docs/reference/spec/#tomlspec"><code>toml::spec</code></a>
|
||||
は
|
||||
<a href="https://toruniina.github.io/toml11/ja/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>ですがこれは長いので、<code>toml::spec::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:#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>特に指定しない場合、デフォルトの値で構築する <code>toml::spec::default_version()</code> が使用されます。</p>
|
||||
<p>デフォルトの値はtoml11のバージョンによって変わりますが、その時点でリリースされているTOML言語の最新バージョンに追従します。</p>
|
||||
<p>v4.4.0現在、TOML v1.1.0はまだリリースされていないため、デフォルトのTOMLバージョンはv1.0.0です。</p>
|
||||
<blockquote class="book-hint warning">
|
||||
<p>TOML v1.1.0の一部の機能にはかなり長い議論が続いており、まだ差し戻される可能性があります。</p>
|
||||
<p>実際に差し戻された場合、toml11はマイナーバージョンアップでそれらの機能を削除、もしくは対応するそれ以降のバージョンに移動します。</p>
|
||||
<p>そのような意味で、将来のバージョンに関する機能は全て不安定なものと考えてください。</p>
|
||||
|
||||
</blockquote>
|
||||
|
||||
<h3 id="バージョン指定でパースする">
|
||||
バージョン指定でパースする
|
||||
<a class="anchor" href="#%e3%83%90%e3%83%bc%e3%82%b8%e3%83%a7%e3%83%b3%e6%8c%87%e5%ae%9a%e3%81%a7%e3%83%91%e3%83%bc%e3%82%b9%e3%81%99%e3%82%8b">#</a>
|
||||
</h3>
|
||||
<p><a href="https://toruniina.github.io/toml11/ja/docs/reference/parser/"><code>toml::parse</code></a>
|
||||
のオーバーロードは、ファイル名に続いて<code>toml::spec</code>を受け取ります。</p>
|
||||
<p>これによって、使用する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">&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>value input <span style="color:#f92672">=</span> toml<span style="color:#f92672">::</span>parse(<span style="color:#e6db74">&#34;input.toml&#34;</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="バージョン指定でシリアライズする">
|
||||
バージョン指定でシリアライズする
|
||||
<a class="anchor" href="#%e3%83%90%e3%83%bc%e3%82%b8%e3%83%a7%e3%83%b3%e6%8c%87%e5%ae%9a%e3%81%a7%e3%82%b7%e3%83%aa%e3%82%a2%e3%83%a9%e3%82%a4%e3%82%ba%e3%81%99%e3%82%8b">#</a>
|
||||
</h3>
|
||||
<p><a href="https://toruniina.github.io/toml11/ja/docs/reference/serializer/"><code>toml::format</code></a>
|
||||
のオーバーロードは、 <code>toml::value</code> に続いて <code>toml::spec</code> を受け取ります。</p></description></item><item><title>extension</title><link>https://toruniina.github.io/toml11/ja/docs/features/extension/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://toruniina.github.io/toml11/ja/docs/features/extension/</guid><description><h1 id="toml言語拡張">
|
||||
TOML言語拡張
|
||||
<a class="anchor" href="#toml%e8%a8%80%e8%aa%9e%e6%8b%a1%e5%bc%b5">#</a>
|
||||
</h1>
|
||||
<p>TOML言語は現在 v1.0.0 が最新版ですが、その後もいくつかの新機能が議論の末マージされ、
|
||||
v1.1.0に向けて議論が続いています。</p>
|
||||
<p>そこで議論された機能の中には、有用なケースが少ないと考えられたものや、
|
||||
提案された際の方向性では導入が難しいもの、導入がされなかったものも多くあります。</p>
|
||||
<p>toml11では、そのような機能のなかからいくつかを選んで、実験的に実装を行っています。
|
||||
これらはtoml11ではサポートされていますが、他のパーサではサポートされておらず、また
|
||||
サポートされる予定もないことに注意してください。</p>
|
||||
<p>また、これらの機能はデフォルトで使用されない設定になっており、
|
||||
使用するためには機能フラグをそれぞれ <code>true</code> にしなければなりません。
|
||||
非標準の機能なので、あえて明示的に書かなければ使えないように設計しています。</p>
|
||||
<p>いくつかの機能は今後TOML言語自体に新機能としてマージされる可能性があります。
|
||||
もし以下の拡張機能を完全に置き換えられる機能が導入された場合、拡張機能は
|
||||
本来の機能の実装後にマイナーバージョンアップで削除される可能性があります。</p>
|
||||
<h2 id="null">
|
||||
<code>null</code>
|
||||
<a class="anchor" href="#null">#</a>
|
||||
</h2>
|
||||
<p>TOMLファイル内で値として<code>null</code>を使えるようになります。</p>
|
||||
<pre tabindex="0"><code>a = null
|
||||
b = [ 1, 2, 3, null, 5]
|
||||
</code></pre><p>これを使用するには、 <code>toml::spec</code> の <code>ext_null_value</code> を <code>true</code> にします。</p>
|
||||
<p>パースすると、デフォルト構築した場合と同様の <code>toml::value_t::empty</code> となります。
|
||||
ただし、ファイル内の位置情報は設定されます。</p>
|
||||
<p><code>null</code> は値の文脈でのみパースされるので、キーに <code>null</code> を使用した際はこれまで通り
|
||||
<code>&quot;null&quot;</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">&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></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">&#34;a = null&#34;</span>, spec);
|
||||
</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>).is_empty());
|
||||
</span></span><span style="display:flex;"><span> assert(v.at(<span style="color:#e6db74">&#34;a&#34;</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="浮動小数点数の16進数フォーマット">
|
||||
浮動小数点数の16進数フォーマット
|
||||
<a class="anchor" href="#%e6%b5%ae%e5%8b%95%e5%b0%8f%e6%95%b0%e7%82%b9%e6%95%b0%e3%81%ae16%e9%80%b2%e6%95%b0%e3%83%95%e3%82%a9%e3%83%bc%e3%83%9e%e3%83%83%e3%83%88">#</a>
|
||||
</h2>
|
||||
<p>TOMLファイル内で浮動小数点数に16進数フォーマットを使用できるようになります。</p></description></item></channel></rss>
|
||||
126
ja/docs/features/literal/index.html
Normal file
126
ja/docs/features/literal/index.html
Normal file
@@ -0,0 +1,126 @@
|
||||
<!doctype html><html lang=ja dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content='
|
||||
_tomlリテラル
|
||||
#
|
||||
|
||||
""_tomlリテラルによって、TOMLファイルをその場でフォーマットできます。
|
||||
#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;
|
||||
}
|
||||
改行を含む場合、生文字列リテラルが便利です。
|
||||
#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;
|
||||
}
|
||||
値が単体で書かれていた場合、その値が返されます。
|
||||
#include <toml.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace toml::literals::toml_literals;
|
||||
|
||||
const auto a = "42"_toml;
|
||||
const auto b = "12:34:56"_toml;
|
||||
|
||||
assert(v.at("a").as_integer() == 42);
|
||||
assert(v.at("b").as_local_time().hour == 12);
|
||||
assert(v.at("b").as_local_time().minute == 34);
|
||||
assert(v.at("b").as_local_time().second == 56);
|
||||
|
||||
return 0;
|
||||
}
|
||||
TOMLは数値のみからなるキーを許可しています。
|
||||
よって、[1]はテーブル名として合法です。'><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/ja/docs/features/literal/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="toml literal"><meta property="og:description" content='_tomlリテラル # ""_tomlリテラルによって、TOMLファイルをその場でフォーマットできます。
|
||||
#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; } 改行を含む場合、生文字列リテラルが便利です。
|
||||
#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; } 値が単体で書かれていた場合、その値が返されます。
|
||||
#include <toml.hpp> int main() { using namespace toml::literals::toml_literals; const auto a = "42"_toml; const auto b = "12:34:56"_toml; assert(v.at("a").as_integer() == 42); assert(v.at("b").as_local_time().hour == 12); assert(v.at("b").as_local_time().minute == 34); assert(v.at("b").as_local_time().second == 56); return 0; } TOMLは数値のみからなるキーを許可しています。 よって、[1]はテーブル名として合法です。'><meta property="og:locale" content="ja"><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/ja/docs/features/literal/><link rel=alternate hreflang=en href=https://toruniina.github.io/toml11/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/ja.search.min.b1a1e3e4be0fdf11fae2bb2370353d99ecd7abea7ccc29273319c021dda76dfd.js integrity="sha256-saHj5L4P3xH64rsjcDU9mezXq+p8zCknMxnAId2nbf0=" 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/ja/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=検索 aria-label=検索 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>
|
||||
日本語</a></label><ul><li><a href=https://toruniina.github.io/toml11/docs/features/literal/>English</a></li></ul></li></ul><ul><li><a href=/toml11/ja/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-b4cfb5b55e913a8d853eacf5e8fba05f class=toggle checked>
|
||||
<label for=section-b4cfb5b55e913a8d853eacf5e8fba05f class="flex justify-between"><a href=/toml11/ja/docs/features/>features</a></label><ul><li><a href=/toml11/ja/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/ja/docs/features/value/>getting values</a></li><li><a href=/toml11/ja/docs/features/error_message/>error message</a></li><li><a href=/toml11/ja/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/ja/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/ja/docs/features/literal/ class=active>toml literal</a></li><li><a href=/toml11/ja/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/ja/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-01b096afc5186aea96713b408b47c967 class=toggle>
|
||||
<label for=section-01b096afc5186aea96713b408b47c967 class="flex justify-between"><a href=/toml11/ja/docs/reference/>reference</a></label><ul><li><a href=/toml11/ja/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/ja/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/ja/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/ja/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/ja/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/ja/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/ja/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/ja/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/ja/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/ja/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/ja/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/ja/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/ja/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/ja/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/ja/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/ja/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/ja/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/ja/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/ja/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/ja/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/ja/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/ja/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/ja/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/ja/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リテラル><code>_toml</code>リテラル</a></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=_tomlリテラル><code>_toml</code>リテラル
|
||||
<a class=anchor href=#_toml%e3%83%aa%e3%83%86%e3%83%a9%e3%83%ab>#</a></h1><p><code>""_toml</code>リテラルによって、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> <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>改行を含む場合、生文字列リテラルが便利です。</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>値が単体で書かれていた場合、その値が返されます。</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(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_local_time().hour <span style=color:#f92672>==</span> <span style=color:#ae81ff>12</span>);
|
||||
</span></span><span style=display:flex><span> assert(v.at(<span style=color:#e6db74>"b"</span>).as_local_time().minute <span style=color:#f92672>==</span> <span style=color:#ae81ff>34</span>);
|
||||
</span></span><span style=display:flex><span> assert(v.at(<span style=color:#e6db74>"b"</span>).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は数値のみからなるキーを許可しています。
|
||||
よって、<code>[1]</code>はテーブル名として合法です。</p><p><code>[1]</code>のようにテーブル定義と配列の区別がつかない場合、テーブル定義が優先されます。</p><p>配列として解釈させるには、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リテラル><code>_toml</code>リテラル</a></li></ul></nav></div></aside></main></body></html>
|
||||
232
ja/docs/features/parsing_files/index.html
Normal file
232
ja/docs/features/parsing_files/index.html
Normal file
@@ -0,0 +1,232 @@
|
||||
<!doctype html><html lang=ja dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content='
|
||||
ファイル・文字列をパースする
|
||||
#
|
||||
|
||||
toml11では、toml::parse や toml::try_parse を使って、ファイルや文字列、バイト列をパースすることができます。
|
||||
これらは成功時に toml::value を返します。
|
||||
ファイルは常にテーブルになりますが、返り値が toml::table でないことに気を付けてください。
|
||||
toml::value はファイルに関するメタデータを持っており、
|
||||
toml::table は std::unordered_map<std::stirng, toml::value> のエイリアスでしかありません。
|
||||
メタデータを返すために、 toml::table ではなく toml::value を返しています。
|
||||
ファイルのルートに対応する toml::value は常に table_type を持ちます。
|
||||
|
||||
ファイルをパースする
|
||||
#
|
||||
|
||||
ファイルをパースする際は、
|
||||
toml::parse
|
||||
または
|
||||
toml::try_parse
|
||||
を使います。
|
||||
|
||||
toml::parse
|
||||
#
|
||||
|
||||
|
||||
std::stringでファイル名を指定する
|
||||
#
|
||||
|
||||
toml::parse
|
||||
は、文字列でファイル名を受け取り、そのファイルを開いてパースします。
|
||||
以下のサンプルは、input.tomlというファイルをパースし、titleという変数を文字列として取り出し、出力するコードです。
|
||||
#include <toml.hpp>
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
const toml::value input = toml::parse("input.toml");
|
||||
std::cout << input.at("title").as_string() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::filesystem::pathでファイルを指定する
|
||||
#
|
||||
|
||||
toml::parse
|
||||
には、std::filesystem::pathを渡すことも可能です。
|
||||
当然ですが、<filesystem>がサポートされるC++17以降でなければ使用できません。
|
||||
|
||||
std::istreamで入力ストリームを指定する
|
||||
#
|
||||
|
||||
toml::parse
|
||||
には、std::istreamを渡すことも可能です。'><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/ja/docs/features/parsing_files/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="parsing files"><meta property="og:description" content='ファイル・文字列をパースする # toml11では、toml::parse や toml::try_parse を使って、ファイルや文字列、バイト列をパースすることができます。
|
||||
これらは成功時に toml::value を返します。 ファイルは常にテーブルになりますが、返り値が toml::table でないことに気を付けてください。 toml::value はファイルに関するメタデータを持っており、 toml::table は std::unordered_map<std::stirng, toml::value> のエイリアスでしかありません。 メタデータを返すために、 toml::table ではなく toml::value を返しています。 ファイルのルートに対応する toml::value は常に table_type を持ちます。
|
||||
ファイルをパースする # ファイルをパースする際は、 toml::parse または toml::try_parse を使います。
|
||||
toml::parse # std::stringでファイル名を指定する # toml::parse は、文字列でファイル名を受け取り、そのファイルを開いてパースします。
|
||||
以下のサンプルは、input.tomlというファイルをパースし、titleという変数を文字列として取り出し、出力するコードです。
|
||||
#include <toml.hpp> #include <iostream> int main() { const toml::value input = toml::parse("input.toml"); std::cout << input.at("title").as_string() << std::endl; return 0; } std::filesystem::pathでファイルを指定する # toml::parse には、std::filesystem::pathを渡すことも可能です。
|
||||
当然ですが、<filesystem>がサポートされるC++17以降でなければ使用できません。
|
||||
std::istreamで入力ストリームを指定する # toml::parse には、std::istreamを渡すことも可能です。'><meta property="og:locale" content="ja"><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/ja/docs/features/parsing_files/><link rel=alternate hreflang=en href=https://toruniina.github.io/toml11/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/ja.search.min.b1a1e3e4be0fdf11fae2bb2370353d99ecd7abea7ccc29273319c021dda76dfd.js integrity="sha256-saHj5L4P3xH64rsjcDU9mezXq+p8zCknMxnAId2nbf0=" 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/ja/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=検索 aria-label=検索 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>
|
||||
日本語</a></label><ul><li><a href=https://toruniina.github.io/toml11/docs/features/parsing_files/>English</a></li></ul></li></ul><ul><li><a href=/toml11/ja/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-b4cfb5b55e913a8d853eacf5e8fba05f class=toggle checked>
|
||||
<label for=section-b4cfb5b55e913a8d853eacf5e8fba05f class="flex justify-between"><a href=/toml11/ja/docs/features/>features</a></label><ul><li><a href=/toml11/ja/docs/features/parsing_files/ class=active>parsing files</a></li><li><a href=/toml11/ja/docs/features/value/>getting values</a></li><li><a href=/toml11/ja/docs/features/error_message/>error message</a></li><li><a href=/toml11/ja/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/ja/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/ja/docs/features/literal/>toml literal</a></li><li><a href=/toml11/ja/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/ja/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-01b096afc5186aea96713b408b47c967 class=toggle>
|
||||
<label for=section-01b096afc5186aea96713b408b47c967 class="flex justify-between"><a href=/toml11/ja/docs/reference/>reference</a></label><ul><li><a href=/toml11/ja/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/ja/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/ja/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/ja/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/ja/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/ja/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/ja/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/ja/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/ja/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/ja/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/ja/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/ja/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/ja/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/ja/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/ja/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/ja/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/ja/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/ja/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/ja/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/ja/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/ja/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/ja/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/ja/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/ja/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=#ファイル文字列をパースする>ファイル・文字列をパースする</a><ul><li><a href=#ファイルをパースする>ファイルをパースする</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=#文字列をパースする>文字列をパースする</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=#バイト列をパースする>バイト列をパースする</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=ファイル文字列をパースする>ファイル・文字列をパースする
|
||||
<a class=anchor href=#%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e6%96%87%e5%ad%97%e5%88%97%e3%82%92%e3%83%91%e3%83%bc%e3%82%b9%e3%81%99%e3%82%8b>#</a></h1><p>toml11では、<code>toml::parse</code> や <code>toml::try_parse</code> を使って、ファイルや文字列、バイト列をパースすることができます。</p><p>これらは成功時に <code>toml::value</code> を返します。
|
||||
ファイルは常にテーブルになりますが、返り値が <code>toml::table</code> でないことに気を付けてください。
|
||||
<code>toml::value</code> はファイルに関するメタデータを持っており、
|
||||
<code>toml::table</code> は <code>std::unordered_map<std::stirng, toml::value></code> のエイリアスでしかありません。
|
||||
メタデータを返すために、 <code>toml::table</code> ではなく <code>toml::value</code> を返しています。
|
||||
ファイルのルートに対応する <code>toml::value</code> は常に <code>table_type</code> を持ちます。</p><h2 id=ファイルをパースする>ファイルをパースする
|
||||
<a class=anchor href=#%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%82%92%e3%83%91%e3%83%bc%e3%82%b9%e3%81%99%e3%82%8b>#</a></h2><p>ファイルをパースする際は、
|
||||
<a href=https://toruniina.github.io/toml11/ja/docs/reference/parser/#parse><code>toml::parse</code></a>
|
||||
または
|
||||
<a href=https://toruniina.github.io/toml11/ja/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=stdstringでファイル名を指定する><code>std::string</code>でファイル名を指定する
|
||||
<a class=anchor href=#stdstring%e3%81%a7%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e5%90%8d%e3%82%92%e6%8c%87%e5%ae%9a%e3%81%99%e3%82%8b>#</a></h4><p><a href=https://toruniina.github.io/toml11/ja/docs/reference/parser/#parse><code>toml::parse</code></a>
|
||||
は、文字列でファイル名を受け取り、そのファイルを開いてパースします。</p><p>以下のサンプルは、<code>input.toml</code>というファイルをパースし、<code>title</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><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=stdfilesystempathでファイルを指定する><code>std::filesystem::path</code>でファイルを指定する
|
||||
<a class=anchor href=#stdfilesystempath%e3%81%a7%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%82%92%e6%8c%87%e5%ae%9a%e3%81%99%e3%82%8b>#</a></h4><p><a href=https://toruniina.github.io/toml11/ja/docs/reference/parser/#parse><code>toml::parse</code></a>
|
||||
には、<code>std::filesystem::path</code>を渡すことも可能です。</p><p>当然ですが、<code><filesystem></code>がサポートされるC++17以降でなければ使用できません。</p><h4 id=stdistreamで入力ストリームを指定する><code>std::istream</code>で入力ストリームを指定する
|
||||
<a class=anchor href=#stdistream%e3%81%a7%e5%85%a5%e5%8a%9b%e3%82%b9%e3%83%88%e3%83%aa%e3%83%bc%e3%83%a0%e3%82%92%e6%8c%87%e5%ae%9a%e3%81%99%e3%82%8b>#</a></h4><p><a href=https://toruniina.github.io/toml11/ja/docs/reference/parser/#parse><code>toml::parse</code></a>
|
||||
には、<code>std::istream</code>を渡すことも可能です。</p><p>標準ライブラリが改行文字を自動変換することによるファイルサイズと文字数との不整合を避けるため、
|
||||
<code>std::ios::binary</code>を使ってバイナリモードで開いてください。</p><p>その際、ファイル名の情報がなくなるため、エラーメッセージ中では <code>"unknown file"</code> となります。</p><p>これを避けるため、 <code>std::istream</code> を取る場合は第二引数に <code>std::string</code> でファイル名を取ることもできます。</p><p><code>std::ifstream</code> 以外にも、 <code>std::istringstream</code> 等の別の<code>istream</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><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=fileでファイルを指定する><code>FILE*</code>でファイルを指定する
|
||||
<a class=anchor href=#file%e3%81%a7%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%82%92%e6%8c%87%e5%ae%9a%e3%81%99%e3%82%8b>#</a></h4><p><a href=https://toruniina.github.io/toml11/ja/docs/reference/parser/#parse><code>toml::parse</code></a>
|
||||
には、<code>FILE*</code>を渡すことも可能です。</p><p>標準ライブラリによる改行文字の自動変換によるファイルサイズと文字数との不整合を避けるため、
|
||||
<code>fopen("example.toml", "rb")</code>のようにしてバイナリモードで開いてください。</p><p>この場合も、<code>std::istream</code>のときと同様に、第二引数に文字列でファイル名を与える必要があります。</p><p><code>FILE*</code>を渡した場合、ファイルの読み込みに失敗した際には<code>errno</code>が報告されます。</p><h4 id=エラー時の挙動>エラー時の挙動
|
||||
<a class=anchor href=#%e3%82%a8%e3%83%a9%e3%83%bc%e6%99%82%e3%81%ae%e6%8c%99%e5%8b%95>#</a></h4><p><a href=https://toruniina.github.io/toml11/ja/docs/reference/parser/#parse><code>toml::parse</code></a>
|
||||
は、文法エラーを発見した場合
|
||||
<a href=https://toruniina.github.io/toml11/ja/docs/reference/parser/#syntax_error><code>toml::syntax_error</code></a>
|
||||
を送出します。</p><p><a href=https://toruniina.github.io/toml11/ja/docs/reference/parser/#syntax_error><code>toml::syntax_error</code></a>
|
||||
は、
|
||||
<a href=https://toruniina.github.io/toml11/ja/docs/reference/exception/><code>toml::exception</code></a>
|
||||
から派生しており、またそれは<code>std::exception</code>から派生します。</p><p>よって、
|
||||
<a href=https://toruniina.github.io/toml11/ja/docs/reference/parser/#syntax_error><code>toml::syntax_error</code></a>
|
||||
からは <code>what()</code> メンバ関数を使ってエラーメッセージを取り出すことができます。</p><p>また、
|
||||
<a href=https://toruniina.github.io/toml11/ja/docs/reference/parser/#syntax_error><code>toml::syntax_error</code></a>
|
||||
は
|
||||
<a href=https://toruniina.github.io/toml11/ja/docs/reference/error_info/><code>std::vector<toml::error_info></code></a>
|
||||
を持っており、<code>errors()</code>メンバ関数を使ってそれにアクセスすることもできます。</p><p><code>toml::parse</code> はごく簡単なエラーならスキップして復帰し、複数のエラーを報告しようと努めます。
|
||||
数値のフォーマットエラー程度なら復帰できることが多いですが、
|
||||
配列やテーブルの中のエラーは復帰できずに似たようなエラーを複数回報告することもあります。
|
||||
冗長であると感じた場合は、 <code>std::vector<toml::error_info></code> の <code>front()</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:#75715e>// parse
|
||||
</span></span></span><span style=display:flex><span><span style=color:#75715e></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>// 全てのエラーを報告
|
||||
</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>// 最初のエラーのみ報告
|
||||
</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><code>toml::parse</code> は失敗時に例外を送出しますが、 <code>toml::try_parse</code> は失敗時に例外を投げません。</p><p>その代わり、返り値が <code>toml::value</code> ではなく <a href=https://toruniina.github.io/toml11/ja/docs/reference/result/#result><code>toml::result<toml::value, std::vector<toml::error_info>></code></a> になります。</p><p><a href=https://toruniina.github.io/toml11/ja/docs/reference/result/#result><code>result</code></a> 型は成功値または失敗値のどちらかを持つ型です。
|
||||
Rustの <code>Result</code> やHaskellの <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><a href=https://toruniina.github.io/toml11/ja/docs/reference/result/#result><code>result</code></a> 型がどちらの値を保持しているかは
|
||||
<code>is_ok()</code>, <code>is_err()</code> 関数を使って確認できます。
|
||||
また、 <code>unwrap()</code>, <code>unwrap_err()</code> によって成功値、失敗値をそれぞれ取り出せます。
|
||||
<code>unwrap</code> が失敗した場合は、 <code>bad_result_access</code> 例外が送出されます。
|
||||
<code>as_ok()</code> と <code>as_err()</code> 関数を使用すると、失敗時には例外が送出されず、未定義動作となります。</p><blockquote class="book-hint warning"><p><code>try_parse</code> は <code>syntax_error</code> や <code>file_io_error</code> を投げず、同じ <code>toml::error_info</code> を
|
||||
<code>result</code> の失敗型として返しますが、絶対に例外を投げないわけではありません。</p><p>標準ライブラリ内部でエラーが発生した場合、例えばメモリ不足の際に <code>vector</code> の
|
||||
<code>allocate</code> が失敗した場合などには <code>std::bad_alloc</code> が送出されますが、
|
||||
<code>toml::try_parse</code> はこれが送出された場合は <code>catch</code> せずに通します。
|
||||
そのため、それらのような標準ライブラリの内部で発生する例外は送出される恐れがあります。</p></blockquote><h2 id=文字列をパースする>文字列をパースする
|
||||
<a class=anchor href=#%e6%96%87%e5%ad%97%e5%88%97%e3%82%92%e3%83%91%e3%83%bc%e3%82%b9%e3%81%99%e3%82%8b>#</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/ja/docs/reference/parser/#parse_str><code>toml::parse_str</code></a>
|
||||
は、ファイル名ではなくパースする文字列そのものを受け取ります。</p><p>また、エラーメッセージのTOMLファイルの名前に相当する部分には、<code>std::source_location</code>
|
||||
相当のコンパイラ拡張機能が使用できる場合、 <code>parse_str</code> を呼び出したC++ファイルの名前と行数が代わりに使用されます。</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/ja/docs/reference/parser/#try_parse_str><code>toml::try_parse_str</code></a>
|
||||
は、 <code>parse_str</code> と同じくパースする文字列そのものを受け取り、
|
||||
<code>try_parse</code> と同じくエラーの報告に
|
||||
<a href=https://toruniina.github.io/toml11/ja/docs/reference/result/#result><code>toml::result</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>#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=バイト列をパースする>バイト列をパースする
|
||||
<a class=anchor href=#%e3%83%90%e3%82%a4%e3%83%88%e5%88%97%e3%82%92%e3%83%91%e3%83%bc%e3%82%b9%e3%81%99%e3%82%8b>#</a></h2><p>ファイルではなくバイト列をパースすることも可能です。</p><p>UTF-8でエンコードされている必要があるため、<code>unsigned char</code>を使っています。</p><h3 id=tomlparsestdvectorunsigned-char><code>toml::parse(std::vector<unsigned char>)</code>
|
||||
<a class=anchor href=#tomlparsestdvectorunsigned-char>#</a></h3><p>挙動は <a href=https://toruniina.github.io/toml11/ja/docs/reference/parser/#parse><code>toml::parse</code></a> と同一です。</p><p>バイト列をパースする際は、 <code>filename</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><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>挙動は <a href=https://toruniina.github.io/toml11/ja/docs/reference/parser/#try_parse><code>toml::try_parse</code></a> と同一です。</p><p>バイト列をパースする際は、 <code>filename</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><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=#ファイル文字列をパースする>ファイル・文字列をパースする</a><ul><li><a href=#ファイルをパースする>ファイルをパースする</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=#文字列をパースする>文字列をパースする</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=#バイト列をパースする>バイト列をパースする</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>
|
||||
175
ja/docs/features/serialize/index.html
Normal file
175
ja/docs/features/serialize/index.html
Normal file
@@ -0,0 +1,175 @@
|
||||
<!doctype html><html lang=ja dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content='
|
||||
TOMLファイルを出力する
|
||||
#
|
||||
|
||||
toml::format を使うと、 toml::value を文字列にすることができます。
|
||||
#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;
|
||||
}
|
||||
table_type を格納している toml::value が渡されると、それがファイルのルートテーブルとして解釈されます。
|
||||
もし table_type 以外を格納している toml::value が渡されると、その値だけがフォーマットされます。
|
||||
一部のフォーマット指定では、キーが渡されていないとフォーマットできないことがあります。
|
||||
例えば、 toml::array_format::array_of_tables は [[array.of.tables]] の形でフォーマットするので、
|
||||
キーへのアクセスを要求します。
|
||||
キーを要求するフォーマット指定の値がキーなしで渡された場合、 toml::serialization_error が送出されます。
|
||||
他にも、フォーマット指定と矛盾する値が含まれる場合には、 toml::serialization_error が送出されます。
|
||||
例えば、 integer_format::hex が指定された整数が負の値を持っている場合や、
|
||||
string_format::literal が指定された文字列が改行を含んでいる場合などです。
|
||||
フォーマットの指定方法は後述します。
|
||||
|
||||
キーを渡して出力する
|
||||
#
|
||||
|
||||
toml::format には std::string としてキーを渡すことが可能です。'><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/ja/docs/features/serialize/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="serializing values"><meta property="og:description" content='TOMLファイルを出力する # toml::format を使うと、 toml::value を文字列にすることができます。
|
||||
#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; } table_type を格納している toml::value が渡されると、それがファイルのルートテーブルとして解釈されます。
|
||||
もし table_type 以外を格納している toml::value が渡されると、その値だけがフォーマットされます。
|
||||
一部のフォーマット指定では、キーが渡されていないとフォーマットできないことがあります。 例えば、 toml::array_format::array_of_tables は [[array.of.tables]] の形でフォーマットするので、 キーへのアクセスを要求します。
|
||||
キーを要求するフォーマット指定の値がキーなしで渡された場合、 toml::serialization_error が送出されます。
|
||||
他にも、フォーマット指定と矛盾する値が含まれる場合には、 toml::serialization_error が送出されます。 例えば、 integer_format::hex が指定された整数が負の値を持っている場合や、 string_format::literal が指定された文字列が改行を含んでいる場合などです。
|
||||
フォーマットの指定方法は後述します。
|
||||
キーを渡して出力する # toml::format には std::string としてキーを渡すことが可能です。'><meta property="og:locale" content="ja"><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/ja/docs/features/serialize/><link rel=alternate hreflang=en href=https://toruniina.github.io/toml11/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/ja.search.min.b1a1e3e4be0fdf11fae2bb2370353d99ecd7abea7ccc29273319c021dda76dfd.js integrity="sha256-saHj5L4P3xH64rsjcDU9mezXq+p8zCknMxnAId2nbf0=" 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/ja/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=検索 aria-label=検索 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>
|
||||
日本語</a></label><ul><li><a href=https://toruniina.github.io/toml11/docs/features/serialize/>English</a></li></ul></li></ul><ul><li><a href=/toml11/ja/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-b4cfb5b55e913a8d853eacf5e8fba05f class=toggle checked>
|
||||
<label for=section-b4cfb5b55e913a8d853eacf5e8fba05f class="flex justify-between"><a href=/toml11/ja/docs/features/>features</a></label><ul><li><a href=/toml11/ja/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/ja/docs/features/value/>getting values</a></li><li><a href=/toml11/ja/docs/features/error_message/>error message</a></li><li><a href=/toml11/ja/docs/features/serialize/ class=active>serializing values</a></li><li><a href=/toml11/ja/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/ja/docs/features/literal/>toml literal</a></li><li><a href=/toml11/ja/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/ja/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-01b096afc5186aea96713b408b47c967 class=toggle>
|
||||
<label for=section-01b096afc5186aea96713b408b47c967 class="flex justify-between"><a href=/toml11/ja/docs/reference/>reference</a></label><ul><li><a href=/toml11/ja/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/ja/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/ja/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/ja/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/ja/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/ja/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/ja/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/ja/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/ja/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/ja/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/ja/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/ja/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/ja/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/ja/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/ja/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/ja/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/ja/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/ja/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/ja/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/ja/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/ja/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/ja/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/ja/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/ja/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=#tomlファイルを出力する>TOMLファイルを出力する</a><ul><li><a href=#キーを渡して出力する>キーを渡して出力する</a></li><li><a href=#フォーマットを指定する>フォーマットを指定する</a><ul><li><a href=#整数のフォーマットを指定する>整数のフォーマットを指定する</a></li><li><a href=#配列を単一行複数行にする>配列を単一行・複数行にする</a></li><li><a href=#テーブルをインラインテーブルにする>テーブルをインラインテーブルにする</a></li></ul></li><li><a href=#toml言語バージョンを指定して出力する>TOML言語バージョンを指定して出力する</a></li></ul></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=tomlファイルを出力する>TOMLファイルを出力する
|
||||
<a class=anchor href=#toml%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%82%92%e5%87%ba%e5%8a%9b%e3%81%99%e3%82%8b>#</a></h1><p><code>toml::format</code> を使うと、 <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:#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><code>table_type</code> を格納している <code>toml::value</code> が渡されると、それがファイルのルートテーブルとして解釈されます。</p><p>もし <code>table_type</code> 以外を格納している <code>toml::value</code> が渡されると、その値だけがフォーマットされます。</p><p>一部のフォーマット指定では、キーが渡されていないとフォーマットできないことがあります。
|
||||
例えば、 <code>toml::array_format::array_of_tables</code> は <code>[[array.of.tables]]</code> の形でフォーマットするので、
|
||||
キーへのアクセスを要求します。</p><p>キーを要求するフォーマット指定の値がキーなしで渡された場合、 <code>toml::serialization_error</code> が送出されます。</p><p>他にも、フォーマット指定と矛盾する値が含まれる場合には、 <code>toml::serialization_error</code> が送出されます。
|
||||
例えば、 <code>integer_format::hex</code> が指定された整数が負の値を持っている場合や、
|
||||
<code>string_format::literal</code> が指定された文字列が改行を含んでいる場合などです。</p><p>フォーマットの指定方法は後述します。</p><h2 id=キーを渡して出力する>キーを渡して出力する
|
||||
<a class=anchor href=#%e3%82%ad%e3%83%bc%e3%82%92%e6%b8%a1%e3%81%97%e3%81%a6%e5%87%ba%e5%8a%9b%e3%81%99%e3%82%8b>#</a></h2><p><code>toml::format</code> には <code>std::string</code> としてキーを渡すことが可能です。</p><p>その場合、ルートテーブルの下にそのキーがあり、渡した値はそのキーに対応すると解釈されます。</p><p>キーが複数段になる場合、 <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=フォーマットを指定する>フォーマットを指定する
|
||||
<a class=anchor href=#%e3%83%95%e3%82%a9%e3%83%bc%e3%83%9e%e3%83%83%e3%83%88%e3%82%92%e6%8c%87%e5%ae%9a%e3%81%99%e3%82%8b>#</a></h2><p><code>toml::value</code> のそれぞれの型には、対応するフォーマット情報型があります。</p><p><code>toml::value::integer_type</code> には <code>toml::integer_format_info</code> が、
|
||||
<code>toml::value::table_type</code> には <code>toml::table_format_info</code> があります。</p><p>これらは、パースした際に設定され、型が変わらない限り値を変更しても引き継がれます。</p><p>また、 <code>as_integer_fmt()</code> や <code>as_table_fmt()</code> といったメンバ関数によってアクセスすることができ、
|
||||
直接編集することが可能です。</p><p>以下ではいくつかの例を挙げて使い方を説明します。</p><p>フォーマットへのアクセス方法は
|
||||
<a href=https://toruniina.github.io/toml11/ja/docs/reference/value/><code>toml::value</code>のリファレンス</a>を、
|
||||
フォーマット情報クラスの完全なリストと詳細は
|
||||
<a href=https://toruniina.github.io/toml11/ja/docs/reference/format/>formatのリファレンス</a>を
|
||||
参照してください。</p><h3 id=整数のフォーマットを指定する>整数のフォーマットを指定する
|
||||
<a class=anchor href=#%e6%95%b4%e6%95%b0%e3%81%ae%e3%83%95%e3%82%a9%e3%83%bc%e3%83%9e%e3%83%83%e3%83%88%e3%82%92%e6%8c%87%e5%ae%9a%e3%81%99%e3%82%8b>#</a></h3><p>整数は、基数と幅、そして <code>_</code> の位置を指定することができます。</p><p><code>hex</code>, <code>oct</code>, <code>bin</code> のとき、指定された幅に達するまでゼロで埋められます。
|
||||
<code>dec</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>value v(<span style=color:#ae81ff>0x00C0'FFEE</span>);
|
||||
</span></span><span style=display:flex><span> v.as_integer_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> v.as_integer_fmt().width <span style=color:#f92672>=</span> <span style=color:#ae81ff>8</span>;
|
||||
</span></span><span style=display:flex><span> v.as_integer_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> <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>stirng s <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>format(v);
|
||||
</span></span><span style=display:flex><span> assert(s <span style=color:#f92672>==</span> <span style=color:#e6db74>"0x00C0_FFEE"</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>詳細は、<a href=https://toruniina.github.io/toml11/ja/docs/reference/format/#integer_format>reference</a> を参照してください。</p><h3 id=配列を単一行複数行にする>配列を単一行・複数行にする
|
||||
<a class=anchor href=#%e9%85%8d%e5%88%97%e3%82%92%e5%8d%98%e4%b8%80%e8%a1%8c%e8%a4%87%e6%95%b0%e8%a1%8c%e3%81%ab%e3%81%99%e3%82%8b>#</a></h3><p>配列には、 <code>toml::array_format::oneline</code> や <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><code>multiline</code> のときは、インデントを指定できます。
|
||||
各要素は <code>body_indent</code> の分だけインデントされ、閉じ括弧 <code>]</code> は <code>closing_indent</code> の分だけインデントされます。</p><p>文字種は <code>indent_type</code> で指定され、 <code>toml::indent_char::space</code> または <code>toml::indent_char::tab</code> が選択できます。</p><blockquote class="book-hint warning"><p>インデントに使用する文字種は統一してください。</p><p>一つのファイル内でインデントに異なる文字種が指定された場合、結果は未規定になります。
|
||||
何らかのインデントがされますが、全ての箇所で文字種やインデントの深さは不定となります。</p></blockquote><p>また、 <code>array</code> の要素が全て <code>table_type</code> を持つ場合、
|
||||
<code>toml::array_format::array_of_tables</code> が指定できます。</p><p><code>array_of_tables</code> を指定せずに <code>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># 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>デフォルトでは、 <code>toml::array_format::default_format</code> が指定されます。
|
||||
これは適したフォーマットを自動的に選択します。</p><p>例えば、 <code>default_format</code> で全要素が <code>table_type</code> だった場合、 <code>array_of_tables</code> が選択されます。
|
||||
また、十分短い配列は <code>oneline</code> に、長い配列またはネストされた配列などの複雑な配列は <code>multiline</code> になります。</p><p>詳細は、<a href=https://toruniina.github.io/toml11/ja/docs/reference/format/#array_format>reference</a> を参照してください。</p><h3 id=テーブルをインラインテーブルにする>テーブルをインラインテーブルにする
|
||||
<a class=anchor href=#%e3%83%86%e3%83%bc%e3%83%96%e3%83%ab%e3%82%92%e3%82%a4%e3%83%b3%e3%83%a9%e3%82%a4%e3%83%b3%e3%83%86%e3%83%bc%e3%83%96%e3%83%ab%e3%81%ab%e3%81%99%e3%82%8b>#</a></h3><p>テーブルをインラインテーブルにする際は <code>toml::table_format::oneline</code> を指定します。
|
||||
通常のテーブルにする際は、 <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>TOML v1.1.0ではインラインテーブル内での改行が許可されますが、その場合は
|
||||
<code>toml::table_format::multiline_oneline</code> とします。
|
||||
これは、後述するTOMLバージョン指定で対応する機能フラグが<code>true</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>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>詳細は、<a href=https://toruniina.github.io/toml11/ja/docs/reference/format/#table_format>reference</a> を参照してください。</p><h2 id=toml言語バージョンを指定して出力する>TOML言語バージョンを指定して出力する
|
||||
<a class=anchor href=#toml%e8%a8%80%e8%aa%9e%e3%83%90%e3%83%bc%e3%82%b8%e3%83%a7%e3%83%b3%e3%82%92%e6%8c%87%e5%ae%9a%e3%81%97%e3%81%a6%e5%87%ba%e5%8a%9b%e3%81%99%e3%82%8b>#</a></h2><p>TOML v1.1.0で許可されたインラインテーブル内の改行や<code>\x</code>エスケープシーケンスのように、
|
||||
TOMLバージョンによって使用できない言語機能があります。</p><p><code>toml::format</code> は最後の引数に <code>toml::spec</code> を取ることができます。</p><p>これにより、シリアライズ時に使用するTOMLのバージョンを指定することができます。</p><p>特に、 <code>toml::parse</code> で <code>toml::spec</code> を使用して新機能を使用した場合は、
|
||||
パースした値がそのバージョンでしか使えないフォーマット情報を持つ場合があるので、
|
||||
<code>toml::format</code> にも同じ <code>toml::spec</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><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></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ファイルを出力する>TOMLファイルを出力する</a><ul><li><a href=#キーを渡して出力する>キーを渡して出力する</a></li><li><a href=#フォーマットを指定する>フォーマットを指定する</a><ul><li><a href=#整数のフォーマットを指定する>整数のフォーマットを指定する</a></li><li><a href=#配列を単一行複数行にする>配列を単一行・複数行にする</a></li><li><a href=#テーブルをインラインテーブルにする>テーブルをインラインテーブルにする</a></li></ul></li><li><a href=#toml言語バージョンを指定して出力する>TOML言語バージョンを指定して出力する</a></li></ul></li></ul></nav></div></aside></main></body></html>
|
||||
132
ja/docs/features/toml_spec/index.html
Normal file
132
ja/docs/features/toml_spec/index.html
Normal file
@@ -0,0 +1,132 @@
|
||||
<!doctype html><html lang=ja dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content='
|
||||
TOML言語バージョン
|
||||
#
|
||||
|
||||
toml::spec
|
||||
によって、 toml::parse や toml::format で使用するTOML言語のバージョンや、個別の機能フラグを指定することができます。
|
||||
|
||||
TOMLのバージョンを指定する
|
||||
#
|
||||
|
||||
toml::spec
|
||||
は
|
||||
toml::semantic_version
|
||||
から構築できます。
|
||||
#include <toml.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
toml::spec spec(toml::semantic_version(1, 1, 0));
|
||||
return 0;
|
||||
}
|
||||
ですがこれは長いので、toml::spec::v()関数が用意されています。
|
||||
#include <toml.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
toml::spec spec = toml::spec::v(1, 1, 0);
|
||||
return 0;
|
||||
}
|
||||
特に指定しない場合、デフォルトの値で構築する toml::spec::default_version() が使用されます。
|
||||
デフォルトの値はtoml11のバージョンによって変わりますが、その時点でリリースされているTOML言語の最新バージョンに追従します。
|
||||
v4.4.0現在、TOML v1.1.0はまだリリースされていないため、デフォルトのTOMLバージョンはv1.0.0です。
|
||||
|
||||
TOML v1.1.0の一部の機能にはかなり長い議論が続いており、まだ差し戻される可能性があります。
|
||||
実際に差し戻された場合、toml11はマイナーバージョンアップでそれらの機能を削除、もしくは対応するそれ以降のバージョンに移動します。
|
||||
そのような意味で、将来のバージョンに関する機能は全て不安定なものと考えてください。
|
||||
|
||||
|
||||
|
||||
|
||||
バージョン指定でパースする
|
||||
#
|
||||
|
||||
toml::parse
|
||||
のオーバーロードは、ファイル名に続いてtoml::specを受け取ります。
|
||||
これによって、使用するTOMLバージョンを変更できます。
|
||||
#include <toml.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
toml::value input = toml::parse("input.toml", toml::spec::v(1, 1, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
バージョン指定でシリアライズする
|
||||
#
|
||||
|
||||
toml::format
|
||||
のオーバーロードは、 toml::value に続いて toml::spec を受け取ります。'><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/ja/docs/features/toml_spec/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="toml spec"><meta property="og:description" content='TOML言語バージョン # toml::spec によって、 toml::parse や toml::format で使用するTOML言語のバージョンや、個別の機能フラグを指定することができます。
|
||||
TOMLのバージョンを指定する # toml::spec は toml::semantic_version から構築できます。
|
||||
#include <toml.hpp> int main() { toml::spec spec(toml::semantic_version(1, 1, 0)); return 0; } ですがこれは長いので、toml::spec::v()関数が用意されています。
|
||||
#include <toml.hpp> int main() { toml::spec spec = toml::spec::v(1, 1, 0); return 0; } 特に指定しない場合、デフォルトの値で構築する toml::spec::default_version() が使用されます。
|
||||
デフォルトの値はtoml11のバージョンによって変わりますが、その時点でリリースされているTOML言語の最新バージョンに追従します。
|
||||
v4.4.0現在、TOML v1.1.0はまだリリースされていないため、デフォルトのTOMLバージョンはv1.0.0です。
|
||||
TOML v1.1.0の一部の機能にはかなり長い議論が続いており、まだ差し戻される可能性があります。
|
||||
実際に差し戻された場合、toml11はマイナーバージョンアップでそれらの機能を削除、もしくは対応するそれ以降のバージョンに移動します。
|
||||
そのような意味で、将来のバージョンに関する機能は全て不安定なものと考えてください。
|
||||
バージョン指定でパースする # toml::parse のオーバーロードは、ファイル名に続いてtoml::specを受け取ります。
|
||||
これによって、使用するTOMLバージョンを変更できます。
|
||||
#include <toml.hpp> int main() { toml::value input = toml::parse("input.toml", toml::spec::v(1, 1, 0)); return 0; } バージョン指定でシリアライズする # toml::format のオーバーロードは、 toml::value に続いて toml::spec を受け取ります。'><meta property="og:locale" content="ja"><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/ja/docs/features/toml_spec/><link rel=alternate hreflang=en href=https://toruniina.github.io/toml11/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/ja.search.min.b1a1e3e4be0fdf11fae2bb2370353d99ecd7abea7ccc29273319c021dda76dfd.js integrity="sha256-saHj5L4P3xH64rsjcDU9mezXq+p8zCknMxnAId2nbf0=" 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/ja/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=検索 aria-label=検索 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>
|
||||
日本語</a></label><ul><li><a href=https://toruniina.github.io/toml11/docs/features/toml_spec/>English</a></li></ul></li></ul><ul><li><a href=/toml11/ja/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-b4cfb5b55e913a8d853eacf5e8fba05f class=toggle checked>
|
||||
<label for=section-b4cfb5b55e913a8d853eacf5e8fba05f class="flex justify-between"><a href=/toml11/ja/docs/features/>features</a></label><ul><li><a href=/toml11/ja/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/ja/docs/features/value/>getting values</a></li><li><a href=/toml11/ja/docs/features/error_message/>error message</a></li><li><a href=/toml11/ja/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/ja/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/ja/docs/features/literal/>toml literal</a></li><li><a href=/toml11/ja/docs/features/toml_spec/ class=active>toml spec</a></li><li><a href=/toml11/ja/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-01b096afc5186aea96713b408b47c967 class=toggle>
|
||||
<label for=section-01b096afc5186aea96713b408b47c967 class="flex justify-between"><a href=/toml11/ja/docs/reference/>reference</a></label><ul><li><a href=/toml11/ja/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/ja/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/ja/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/ja/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/ja/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/ja/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/ja/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/ja/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/ja/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/ja/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/ja/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/ja/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/ja/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/ja/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/ja/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/ja/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/ja/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/ja/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/ja/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/ja/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/ja/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/ja/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/ja/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/ja/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言語バージョン>TOML言語バージョン</a><ul><li><a href=#tomlのバージョンを指定する>TOMLのバージョンを指定する</a><ul><li><a href=#バージョン指定でパースする>バージョン指定でパースする</a></li><li><a href=#バージョン指定でシリアライズする>バージョン指定でシリアライズする</a></li></ul></li><li><a href=#tomlに追加された新機能を個別に指定する>TOMLに追加された新機能を個別に指定する</a></li></ul></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=toml言語バージョン>TOML言語バージョン
|
||||
<a class=anchor href=#toml%e8%a8%80%e8%aa%9e%e3%83%90%e3%83%bc%e3%82%b8%e3%83%a7%e3%83%b3>#</a></h1><p><a href=https://toruniina.github.io/toml11/ja/docs/reference/spec/#tomlspec><code>toml::spec</code></a>
|
||||
によって、 <code>toml::parse</code> や <code>toml::format</code> で使用するTOML言語のバージョンや、個別の機能フラグを指定することができます。</p><h2 id=tomlのバージョンを指定する>TOMLのバージョンを指定する
|
||||
<a class=anchor href=#toml%e3%81%ae%e3%83%90%e3%83%bc%e3%82%b8%e3%83%a7%e3%83%b3%e3%82%92%e6%8c%87%e5%ae%9a%e3%81%99%e3%82%8b>#</a></h2><p><a href=https://toruniina.github.io/toml11/ja/docs/reference/spec/#tomlspec><code>toml::spec</code></a>
|
||||
は
|
||||
<a href=https://toruniina.github.io/toml11/ja/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>ですがこれは長いので、<code>toml::spec::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:#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>特に指定しない場合、デフォルトの値で構築する <code>toml::spec::default_version()</code> が使用されます。</p><p>デフォルトの値はtoml11のバージョンによって変わりますが、その時点でリリースされているTOML言語の最新バージョンに追従します。</p><p>v4.4.0現在、TOML v1.1.0はまだリリースされていないため、デフォルトのTOMLバージョンはv1.0.0です。</p><blockquote class="book-hint warning"><p>TOML v1.1.0の一部の機能にはかなり長い議論が続いており、まだ差し戻される可能性があります。</p><p>実際に差し戻された場合、toml11はマイナーバージョンアップでそれらの機能を削除、もしくは対応するそれ以降のバージョンに移動します。</p><p>そのような意味で、将来のバージョンに関する機能は全て不安定なものと考えてください。</p></blockquote><h3 id=バージョン指定でパースする>バージョン指定でパースする
|
||||
<a class=anchor href=#%e3%83%90%e3%83%bc%e3%82%b8%e3%83%a7%e3%83%b3%e6%8c%87%e5%ae%9a%e3%81%a7%e3%83%91%e3%83%bc%e3%82%b9%e3%81%99%e3%82%8b>#</a></h3><p><a href=https://toruniina.github.io/toml11/ja/docs/reference/parser/><code>toml::parse</code></a>
|
||||
のオーバーロードは、ファイル名に続いて<code>toml::spec</code>を受け取ります。</p><p>これによって、使用する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>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=バージョン指定でシリアライズする>バージョン指定でシリアライズする
|
||||
<a class=anchor href=#%e3%83%90%e3%83%bc%e3%82%b8%e3%83%a7%e3%83%b3%e6%8c%87%e5%ae%9a%e3%81%a7%e3%82%b7%e3%83%aa%e3%82%a2%e3%83%a9%e3%82%a4%e3%82%ba%e3%81%99%e3%82%8b>#</a></h3><p><a href=https://toruniina.github.io/toml11/ja/docs/reference/serializer/><code>toml::format</code></a>
|
||||
のオーバーロードは、 <code>toml::value</code> に続いて <code>toml::spec</code> を受け取ります。</p><p>これによって、使用する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>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>もしフォーマット変数などによって指定されているフォーマットが渡された <code>toml::spec</code>
|
||||
では許可されていないものだった場合、指定は無視されて他のフォーマットにフォールバックされます。</p><h2 id=tomlに追加された新機能を個別に指定する>TOMLに追加された新機能を個別に指定する
|
||||
<a class=anchor href=#toml%e3%81%ab%e8%bf%bd%e5%8a%a0%e3%81%95%e3%82%8c%e3%81%9f%e6%96%b0%e6%a9%9f%e8%83%bd%e3%82%92%e5%80%8b%e5%88%a5%e3%81%ab%e6%8c%87%e5%ae%9a%e3%81%99%e3%82%8b>#</a></h2><p>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 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>// インラインテーブル内での改行を許可
|
||||
</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>全てのフラグのリストは、
|
||||
<a href=https://toruniina.github.io/toml11/ja/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言語バージョン>TOML言語バージョン</a><ul><li><a href=#tomlのバージョンを指定する>TOMLのバージョンを指定する</a><ul><li><a href=#バージョン指定でパースする>バージョン指定でパースする</a></li><li><a href=#バージョン指定でシリアライズする>バージョン指定でシリアライズする</a></li></ul></li><li><a href=#tomlに追加された新機能を個別に指定する>TOMLに追加された新機能を個別に指定する</a></li></ul></li></ul></nav></div></aside></main></body></html>
|
||||
483
ja/docs/features/value/index.html
Normal file
483
ja/docs/features/value/index.html
Normal file
@@ -0,0 +1,483 @@
|
||||
<!doctype html><html lang=ja dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
|
||||
値を取り出す
|
||||
#
|
||||
|
||||
ここでは、 toml::value が格納している値にアクセスする方法を説明します。
|
||||
|
||||
メンバ関数を使って値にアクセスする
|
||||
#
|
||||
|
||||
|
||||
is_something と as_something
|
||||
#
|
||||
|
||||
toml::value は is_boolean() や is_integer() などのメンバ関数を持っており、
|
||||
これらを使うと持っている型を調べることができます。
|
||||
また、 as_boolean(), as_integer() などのメンバ関数も持っており、
|
||||
これらを使ってその型にアクセスすることができます。
|
||||
完全なリストは toml::value のリファレンス を参照してください。
|
||||
toml::value v = /* ... */;
|
||||
if(v.is_integer())
|
||||
{
|
||||
std::cout << v.as_integer() << std::endl;
|
||||
}
|
||||
指定された値と異なる型が格納されていた場合、 toml::type_error が送出されます。
|
||||
その what() は以下のようなメッセージを含みます。
|
||||
[error] toml::value::as_string(): bad_cast to string
|
||||
--> input.toml
|
||||
|
|
||||
1 | a = 123_456
|
||||
| ^^^^^^^-- the actual type is integer
|
||||
|
||||
toml::value_t
|
||||
#
|
||||
|
||||
型情報は enum class toml::value_t で識別できます。"><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/ja/docs/features/value/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="getting values"><meta property="og:description" content="値を取り出す # ここでは、 toml::value が格納している値にアクセスする方法を説明します。
|
||||
メンバ関数を使って値にアクセスする # is_something と as_something # toml::value は is_boolean() や is_integer() などのメンバ関数を持っており、 これらを使うと持っている型を調べることができます。
|
||||
また、 as_boolean(), as_integer() などのメンバ関数も持っており、 これらを使ってその型にアクセスすることができます。
|
||||
完全なリストは toml::value のリファレンス を参照してください。
|
||||
toml::value v = /* ... */; if(v.is_integer()) { std::cout << v.as_integer() << std::endl; } 指定された値と異なる型が格納されていた場合、 toml::type_error が送出されます。
|
||||
その what() は以下のようなメッセージを含みます。
|
||||
[error] toml::value::as_string(): bad_cast to string --> input.toml | 1 | a = 123_456 | ^^^^^^^-- the actual type is integer toml::value_t # 型情報は enum class toml::value_t で識別できます。"><meta property="og:locale" content="ja"><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/ja/docs/features/value/><link rel=alternate hreflang=en href=https://toruniina.github.io/toml11/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/ja.search.min.b1a1e3e4be0fdf11fae2bb2370353d99ecd7abea7ccc29273319c021dda76dfd.js integrity="sha256-saHj5L4P3xH64rsjcDU9mezXq+p8zCknMxnAId2nbf0=" 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/ja/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=検索 aria-label=検索 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>
|
||||
日本語</a></label><ul><li><a href=https://toruniina.github.io/toml11/docs/features/value/>English</a></li></ul></li></ul><ul><li><a href=/toml11/ja/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-b4cfb5b55e913a8d853eacf5e8fba05f class=toggle checked>
|
||||
<label for=section-b4cfb5b55e913a8d853eacf5e8fba05f class="flex justify-between"><a href=/toml11/ja/docs/features/>features</a></label><ul><li><a href=/toml11/ja/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/ja/docs/features/value/ class=active>getting values</a></li><li><a href=/toml11/ja/docs/features/error_message/>error message</a></li><li><a href=/toml11/ja/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/ja/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/ja/docs/features/literal/>toml literal</a></li><li><a href=/toml11/ja/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/ja/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-01b096afc5186aea96713b408b47c967 class=toggle>
|
||||
<label for=section-01b096afc5186aea96713b408b47c967 class="flex justify-between"><a href=/toml11/ja/docs/reference/>reference</a></label><ul><li><a href=/toml11/ja/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/ja/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/ja/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/ja/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/ja/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/ja/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/ja/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/ja/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/ja/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/ja/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/ja/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/ja/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/ja/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/ja/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/ja/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/ja/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/ja/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/ja/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/ja/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/ja/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/ja/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/ja/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/ja/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/ja/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=#値を取り出す>値を取り出す</a><ul><li><a href=#メンバ関数を使って値にアクセスする>メンバ関数を使って値にアクセスする</a><ul><li><a href=#is_something-と-as_something><code>is_something</code> と <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=#コメントにアクセスする>コメントにアクセスする</a></li><li><a href=#インラインテーブルドットキーの取り扱い>インラインテーブル・ドットキーの取り扱い</a></li><li><a href=#日付情報の取り扱い>日付情報の取り扱い</a></li><li><a href=#tomlgettを使って変換する><code>toml::get<T></code>を使って変換する</a><ul><li><a href=#単純な変換>単純な変換</a></li><li><a href=#参照を取得できる条件>参照を取得できる条件</a></li><li><a href=#配列をstlコンテナに>配列をSTLコンテナに</a></li><li><a href=#配列を-stdpair-stdtuple-に>配列を <code>std::pair</code>, <code>std::tuple</code> に</a></li><li><a href=#ネストされた配列の変換>ネストされた配列の変換</a></li><li><a href=#テーブルを-stdmap-に変換>テーブルを <code>std::map</code> に変換</a></li></ul></li><li><a href=#tomlget_orを使って失敗時の値を指定する><code>toml::get_or</code>を使って失敗時の値を指定する</a></li><li><a href=#tomlfindtを使って検索と変換を同時に行う><code>toml::find<T></code>を使って検索と変換を同時に行う</a></li><li><a href=#tomlfind_orを使って失敗時の値を指定する><code>toml::find_or</code>を使って失敗時の値を指定する</a></li><li><a href=#tomlfind_or_defaultを使って失敗時の値を指定する><code>toml::find_or_default</code>を使って失敗時の値を指定する</a></li><li><a href=#tomlfindstdoptionalt><code>toml::find<std::optional<T>></code></a></li><li><a href=#ユーザー定義型との変換を定義する>ユーザー定義型との変換を定義する</a><ul><li><a href=#tomlfrom-の定義><code>toml::from</code> の定義</a></li><li><a href=#from_toml-メンバ関数の定義><code>from_toml</code> メンバ関数の定義</a></li><li><a href=#tomlvalue-を受け取るコンストラクタ><code>toml::value</code> を受け取るコンストラクタ</a></li></ul></li><li><a href=#tomlvisitで関数を適用する><code>toml::visit</code>で関数を適用する</a></li><li><a href=#tomlvalue-を構築する><code>toml::value</code> を構築する</a></li><li><a href=#tomlvalue-に変換する><code>toml::value</code> に変換する</a><ul><li><a href=#tomlintoを定義する><code>toml::into</code>を定義する</a></li><li><a href=#into_toml-メンバ関数を定義する><code>into_toml</code> メンバ関数を定義する</a></li></ul></li></ul></li><li><a href=#値がアクセス済みかどうかチェックする>値がアクセス済みかどうかチェックする</a></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=値を取り出す>値を取り出す
|
||||
<a class=anchor href=#%e5%80%a4%e3%82%92%e5%8f%96%e3%82%8a%e5%87%ba%e3%81%99>#</a></h1><p>ここでは、 <code>toml::value</code> が格納している値にアクセスする方法を説明します。</p><h2 id=メンバ関数を使って値にアクセスする>メンバ関数を使って値にアクセスする
|
||||
<a class=anchor href=#%e3%83%a1%e3%83%b3%e3%83%90%e9%96%a2%e6%95%b0%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e5%80%a4%e3%81%ab%e3%82%a2%e3%82%af%e3%82%bb%e3%82%b9%e3%81%99%e3%82%8b>#</a></h2><h3 id=is_something-と-as_something><code>is_something</code> と <code>as_something</code>
|
||||
<a class=anchor href=#is_something-%e3%81%a8-as_something>#</a></h3><p><code>toml::value</code> は <code>is_boolean()</code> や <code>is_integer()</code> などのメンバ関数を持っており、
|
||||
これらを使うと持っている型を調べることができます。</p><p>また、 <code>as_boolean()</code>, <code>as_integer()</code> などのメンバ関数も持っており、
|
||||
これらを使ってその型にアクセスすることができます。</p><p>完全なリストは <a href=https://toruniina.github.io/toml11/ja/docs/reference/value/#is_xxx><code>toml::value</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>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_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><p>指定された値と異なる型が格納されていた場合、 <a href=https://toruniina.github.io/toml11/ja/docs/reference/value/#tomltype_error><code>toml::type_error</code></a> が送出されます。</p><p>その <code>what()</code> は以下のようなメッセージを含みます。</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>型情報は <a href=https://toruniina.github.io/toml11/ja/docs/reference/value_t/><code>enum class toml::value_t</code></a> で識別できます。</p><p><a href=https://toruniina.github.io/toml11/ja/docs/reference/value/#type><code>type()</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>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><a href=https://toruniina.github.io/toml11/ja/docs/reference/value/#istomlvalue_t><code>is(toml::value_t)</code></a> メンバ関数は、渡された <code>value_t</code> と同じ型の値を格納している場合 <code>true</code> を、
|
||||
それ以外の場合 <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> も提供しています。</p><p>これらは、内部で <code>toml::value</code> を対応する型に変換し、そのメンバ関数を呼び出します。</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><code>as_array().at(i)</code>, <code>as_array()[i]</code> と同等です。</p><p><code>toml::value</code> はデフォルトで <code>std::vector<toml::value></code> を <code>array_type</code> に使うので、
|
||||
エラーが発生した際には <code>at</code> は <code>std::out_of_range</code> を送出し、<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>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>格納している型が <code>array_type</code> ではなかった場合、 <code>type_error</code> を送出します。</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><code>as_table().at(key)</code>, <code>as_table()[key]</code> と同等です。</p><p><code>toml::value</code> はデフォルトで <code>std::unordered_map<std::string, toml::value></code> を <code>table_type</code> に使うので、
|
||||
対応する値が存在しない場合は <code>at</code> は <code>std::out_of_range</code> を送出し、 <code>operator[]</code> は新しく <code>toml::value</code> を構築してそれへの参照を返します。
|
||||
そのため、<code>operator[]</code> に <code>const</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>格納している型が <code>table_type</code> ではなかった場合、 <code>type_error</code> を送出します。</p><h4 id=size><code>size()</code>
|
||||
<a class=anchor href=#size>#</a></h4><p>長さを返します。</p><p><code>array_type</code> または <code>table_type</code> の場合は要素数、 <code>string_type</code> の場合は文字数を返します。</p><p>格納している型がどれでもなかった場合、 <code>type_error</code> を送出します。</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><code>as_array().push_back()</code>, <code>as_array().emplace_back()</code> と同一です。</p><p>格納している型が <code>array_type</code> ではなかった場合、 <code>type_error</code> を送出します。</p><h2 id=コメントにアクセスする>コメントにアクセスする
|
||||
<a class=anchor href=#%e3%82%b3%e3%83%a1%e3%83%b3%e3%83%88%e3%81%ab%e3%82%a2%e3%82%af%e3%82%bb%e3%82%b9%e3%81%99%e3%82%8b>#</a></h2><p>toml11では、デフォルトでコメントがパースされ、対応する値に行ごとに保存されます。</p><p>対応する値は、連続するコメント行の直後に来る値か、もしくはそのコメントと同じ行に描かれている値です。</p><p>直前または直後に値がなければ、そのコメントはどこにも紐づけられず、無視されます。</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># これは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># これはbに関するコメントです。</span>
|
||||
</span></span><span style=display:flex><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><span style=color:#75715e># これは1番目のcに関するコメントです。</span>
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e># これは2番目の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># これは最後のcに関するコメントです。</span>
|
||||
</span></span></code></pre></div><p>値に対応するコメントには、<code>toml::value</code> の <code>comments()</code> メンバ関数を使ってアクセスします。</p><p><code>comments()</code> は <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>"# これは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>"# これは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>"# これは1番目の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>"# これは2番目の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>"# これは最後のcに関するコメントです。"</span>);
|
||||
</span></span></code></pre></div><p>ファイル全体に対応するルートテーブルに関するコメントは、ファイルの先頭に書きます。</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># ルートテーブルに関するコメントです。</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><span style=color:#75715e># これは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>ただし、もしファイルの先頭のコメントの直後に値が来た場合、
|
||||
そのコメントはその値に関するコメントと解釈され、ルートテーブルのコメントはなくなります。</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># これはaに関するコメントです。</span>
|
||||
</span></span><span style=display:flex><span><span style=color:#75715e># これも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=インラインテーブルドットキーの取り扱い>インラインテーブル・ドットキーの取り扱い
|
||||
<a class=anchor href=#%e3%82%a4%e3%83%b3%e3%83%a9%e3%82%a4%e3%83%b3%e3%83%86%e3%83%bc%e3%83%96%e3%83%ab%e3%83%89%e3%83%83%e3%83%88%e3%82%ad%e3%83%bc%e3%81%ae%e5%8f%96%e3%82%8a%e6%89%b1%e3%81%84>#</a></h2><p>インラインテーブルは単にテーブルで、C++コード上で他のテーブルと異なる点はありません。</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>ドットキーも単にテーブルで、C++コード上で他のテーブルと異なる点はありません。</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>これらは以下のファイルと全く同じ構造を持ちます。</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>なので、どの記法でも以下の全く同一のコードで処理できます。</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>ただし、フォーマット情報によって区別することは可能です。</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>このフォーマット情報は後述するシリアライズの際も考慮されます。</p><h2 id=日付情報の取り扱い>日付情報の取り扱い
|
||||
<a class=anchor href=#%e6%97%a5%e4%bb%98%e6%83%85%e5%a0%b1%e3%81%ae%e5%8f%96%e3%82%8a%e6%89%b1%e3%81%84>#</a></h2><p><a href=https://toruniina.github.io/toml11/ja/docs/reference/datetime/#local_date><code>local_date</code></a>,
|
||||
<a href=https://toruniina.github.io/toml11/ja/docs/reference/datetime/#local_time><code>local_time</code></a>,
|
||||
<a href=https://toruniina.github.io/toml11/ja/docs/reference/datetime/#local_datetime><code>local_datetime</code></a>, そして
|
||||
<a href=https://toruniina.github.io/toml11/ja/docs/reference/datetime/#offset_datetime><code>offset_datetime</code></a> は、
|
||||
toml11では対応するメンバ変数を持つ専用の構造体にパースされます。</p><p>使用する際は、直接値を取り出す他にも、後述する <code>toml::get</code> や <code>toml::find</code> を使用して、
|
||||
<code>std::chrono::system_clock::time_point</code> や <code>std::tm</code> 等の型に変換することができます。</p><h2 id=tomlgettを使って変換する><code>toml::get<T></code>を使って変換する
|
||||
<a class=anchor href=#tomlgett%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e5%a4%89%e6%8f%9b%e3%81%99%e3%82%8b>#</a></h2><p><code>toml::get<T></code> は、 <code>toml::value</code> の持つ値を変換して取り出す関数です。
|
||||
<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>後述する <code>toml::find<T></code> も、型変換の部分は同一の機能を持ちます。</p><p>格納されている型のそれぞれについて、
|
||||
変換ができない型が指定された場合、 <code>toml::type_error</code> が送出されます。</p><h3 id=単純な変換>単純な変換
|
||||
<a class=anchor href=#%e5%8d%98%e7%b4%94%e3%81%aa%e5%a4%89%e6%8f%9b>#</a></h3><h4 id=boolean_type>boolean_type
|
||||
<a class=anchor href=#boolean_type>#</a></h4><p><code>boolean_type</code> から変換が可能なのは、 <code>bool</code> のみです。</p><h4 id=integer_type>integer_type
|
||||
<a class=anchor href=#integer_type>#</a></h4><p><code>bool</code> 以外で <code>std::is_integral<T></code> が <code>true</code> になる型は、 <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><code>std::is_floating_point<T></code> が <code>true</code> になる型は、<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> からは <code>std::string</code> へ変換できます。
|
||||
また、C++17以降では、<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/ja/docs/reference/datetime/#local_date><code>local_date</code></a>,
|
||||
<a href=https://toruniina.github.io/toml11/ja/docs/reference/datetime/#local_datetime><code>local_datetime</code></a>,
|
||||
<a href=https://toruniina.github.io/toml11/ja/docs/reference/datetime/#offset_datetime><code>offset_datetime</code></a> は
|
||||
ある日付と時刻を指しているため、
|
||||
<code>std::chrono::system_clock::time_point</code> への変換が可能です。</p><p>ただし、<a href=https://toruniina.github.io/toml11/ja/docs/reference/datetime/#local_time><code>local_time</code></a> は
|
||||
日付の情報がないため、0時0分からの経過時刻として <code>std::chrono::duration</code> への
|
||||
変換をサポートします。</p><p>また、 <code>local_date</code> と <code>local_datetime</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>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=参照を取得できる条件>参照を取得できる条件
|
||||
<a class=anchor href=#%e5%8f%82%e7%85%a7%e3%82%92%e5%8f%96%e5%be%97%e3%81%a7%e3%81%8d%e3%82%8b%e6%9d%a1%e4%bb%b6>#</a></h3><p><code>toml::get<T></code> は、 <code>T</code> が <code>toml::value</code> が格納する型そのものだった場合、参照を返すことができます。</p><p>逆に、変換が必要な場合( <code>std::int64_t</code> で格納されている整数を <code>std::uint32_t</code> で取り出そうとした場合)は、
|
||||
変換後の型への参照を返すことは不可能です。</p><p>変換が必要ない型の場合、返された参照を経由して値を書き換えることも可能です。</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=配列をstlコンテナに>配列をSTLコンテナに
|
||||
<a class=anchor href=#%e9%85%8d%e5%88%97%e3%82%92stl%e3%82%b3%e3%83%b3%e3%83%86%e3%83%8a%e3%81%ab>#</a></h3><p>配列の要素型が全て同じ場合、要素型が <code>T</code> に変換可能であれば、 <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>他のSTLコンテナにも変換可能です。</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><code>std::array</code> に変換する場合、要素数が一致している必要があります。
|
||||
もし要素数が一致しなかった場合、 <code>std::out_of_range</code> が送出されます。</p><p>STL以外のコンテナであっても、デフォルトコンストラクタと <code>push_back</code> を持っている場合、
|
||||
<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=配列を-stdpair-stdtuple-に>配列を <code>std::pair</code>, <code>std::tuple</code> に
|
||||
<a class=anchor href=#%e9%85%8d%e5%88%97%e3%82%92-stdpair-stdtuple-%e3%81%ab>#</a></h3><p>配列の要素型が異なる場合、 <code>std::pair</code> や <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><code>std::array</code> の場合と同様に、配列の長さは <code>std::pair</code>, <code>std::tuple</code> の要素数と一致している必要があります。
|
||||
もし要素数が一致しなかった場合、 <code>std::out_of_range</code> が送出されます。</p><p>また、各要素は対応する要素に変換できる必要があります。
|
||||
変換できない場合、 <code>toml::type_error</code> が送出されます。</p><h3 id=ネストされた配列の変換>ネストされた配列の変換
|
||||
<a class=anchor href=#%e3%83%8d%e3%82%b9%e3%83%88%e3%81%95%e3%82%8c%e3%81%9f%e9%85%8d%e5%88%97%e3%81%ae%e5%a4%89%e6%8f%9b>#</a></h3><p>ネストされた配列は、ネストされたコンテナに変換可能です。</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>型が異なる場合には、 <code>std::pair/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:#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=テーブルを-stdmap-に変換>テーブルを <code>std::map</code> に変換
|
||||
<a class=anchor href=#%e3%83%86%e3%83%bc%e3%83%96%e3%83%ab%e3%82%92-stdmap-%e3%81%ab%e5%a4%89%e6%8f%9b>#</a></h3><p>テーブルに含まれる値の型が全て同じであれば、 <code>std::map</code> や <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>STL以外のコンテナであっても、デフォルトコンストラクタと <code>emplace(key, mapped)</code> を持っている場合、
|
||||
<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>要素型の変換に失敗した場合は <code>toml::type_error</code> が送出されます。</p><h2 id=tomlget_orを使って失敗時の値を指定する><code>toml::get_or</code>を使って失敗時の値を指定する
|
||||
<a class=anchor href=#tomlget_or%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e5%a4%b1%e6%95%97%e6%99%82%e3%81%ae%e5%80%a4%e3%82%92%e6%8c%87%e5%ae%9a%e3%81%99%e3%82%8b>#</a></h2><p><code>toml::get</code> は変換に失敗した際に <code>toml::type_error</code> 例外を送出します。</p><p><code>toml::get_or</code> を使用することで、変換に失敗した際に例外ではなくデフォルト値を返せるようになります。</p><p><code>toml::get<T></code> とは異なり、 <code>get_or</code> は引数から変換先の型を推論するため、 <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>変換可能な型は <code>toml::get</code> と同様です。</p><p><code>toml::value::xxx_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<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=tomlfindtを使って検索と変換を同時に行う><code>toml::find<T></code>を使って検索と変換を同時に行う
|
||||
<a class=anchor href=#tomlfindt%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e6%a4%9c%e7%b4%a2%e3%81%a8%e5%a4%89%e6%8f%9b%e3%82%92%e5%90%8c%e6%99%82%e3%81%ab%e8%a1%8c%e3%81%86>#</a></h2><p><code>toml::find<T></code> は、テーブルを持つ <code>toml::value</code> から値を検索し、同時に
|
||||
<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>// const auto a = toml::get<int>(input.at("a")); と同じ
|
||||
</span></span></span></code></pre></div><p><code>toml::find<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> 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>// const auto a2 = toml::get<int>(input.at("a").at(2)); と同じ
|
||||
</span></span></span></code></pre></div><p>型変換の際にエラーが起きた場合、 <code>toml::get</code> と同じ <code>toml::type_error</code> を
|
||||
送出します。
|
||||
キーが見つからなかった場合またはインデックスが存在しない場合は、
|
||||
<code>std::out_of_range</code> を送出します。</p><p>型を指定しなかった場合、型変換を行わず <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>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>// const auto a = input.at("a"); と同じ
|
||||
</span></span></span></code></pre></div><p><code>toml::find<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:#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>// const auto a = toml::get<int>(input.at("a").at("b").at("c")); と同じ
|
||||
</span></span></span></code></pre></div><p>このとき、キーとインデックスを混ぜることができます。</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>// 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はquoted keyという機能を持っています。</p><p>これは、 <code>""</code> や <code>''</code> を使うことで通常許可されない文字をキーに使えるというもので、
|
||||
この中では <code>.</code> はテーブルを導入<strong>しません</strong>。</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>この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:#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>このような場合にも違和感なく対応するため、toml11ではキーに <code>.</code> が含まれていても
|
||||
自動で分割はしません。</p><p>テーブルの階層構造を陽に指定することが、適切な入力ファイルの構造化に資すると考えているからです。</p><p>参考: <a href=https://toml.io/ja/v1.0.0#%E3%82%AD%E3%83%BC>toml.io キー</a></p></blockquote><h2 id=tomlfind_orを使って失敗時の値を指定する><code>toml::find_or</code>を使って失敗時の値を指定する
|
||||
<a class=anchor href=#tomlfind_or%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e5%a4%b1%e6%95%97%e6%99%82%e3%81%ae%e5%80%a4%e3%82%92%e6%8c%87%e5%ae%9a%e3%81%99%e3%82%8b>#</a></h2><p><code>toml::find_or</code> は、 <code>toml::get_or</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_or(input, <span style=color:#e6db74>"a"</span>, <span style=color:#ae81ff>42</span>);
|
||||
</span></span></code></pre></div><p>型変換の失敗だけでなく、キーが見つからなかった場合もデフォルト値を返します。</p><h2 id=tomlfind_or_defaultを使って失敗時の値を指定する><code>toml::find_or_default</code>を使って失敗時の値を指定する
|
||||
<a class=anchor href=#tomlfind_or_default%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e5%a4%b1%e6%95%97%e6%99%82%e3%81%ae%e5%80%a4%e3%82%92%e6%8c%87%e5%ae%9a%e3%81%99%e3%82%8b>#</a></h2><p><code>toml::find_or_default</code> は、 <code>toml::find_or</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_or(input, <span style=color:#e6db74>"a"</span>, expensive()); <span style=color:#75715e>// 関数呼出前にコンストラクタ呼出
|
||||
</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>// 失敗時にのみコンストラクタ呼出
|
||||
</span></span></span></code></pre></div><p>型変換の失敗だけでなく、キーが見つからなかった場合もデフォルトコンストラクタの結果を返します。</p><h2 id=tomlfindstdoptionalt><code>toml::find<std::optional<T>></code>
|
||||
<a class=anchor href=#tomlfindstdoptionalt>#</a></h2><p>C++17以降の場合、<code>std::optional</code>を<code>toml::find</code>に指定することができます。</p><p><code>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><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>キーが存在しなかった場合、例外は投げられず、<code>std::nullopt</code>が返却されます。</p><p>ただし、型変換が失敗した場合や、テーブルではない値にキーでアクセスしようとした場合、配列でない値にインデックスでアクセス仕様とした場合は、<code>toml::type_error</code>が送出されます。</p><h2 id=ユーザー定義型との変換を定義する>ユーザー定義型との変換を定義する
|
||||
<a class=anchor href=#%e3%83%a6%e3%83%bc%e3%82%b6%e3%83%bc%e5%ae%9a%e7%be%a9%e5%9e%8b%e3%81%a8%e3%81%ae%e5%a4%89%e6%8f%9b%e3%82%92%e5%ae%9a%e7%be%a9%e3%81%99%e3%82%8b>#</a></h2><p><code>toml::get</code> や <code>toml::find</code> では、以下のどれかの方法を使うことで
|
||||
ユーザー定義型を使用することができます。</p><h3 id=tomlfrom-の定義><code>toml::from</code> の定義
|
||||
<a class=anchor href=#tomlfrom-%e3%81%ae%e5%ae%9a%e7%be%a9>#</a></h3><p>toml11には <code>toml::from</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>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>後述する型設定を変更した <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> 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>この定義は、 <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>あるいは、リフレクションライブラリを使用することもできます。
|
||||
<code>example</code> の <code>boost-ext/reflect</code> を使用したサンプルも参照してください。</p><h3 id=from_toml-メンバ関数の定義><code>from_toml</code> メンバ関数の定義
|
||||
<a class=anchor href=#from_toml-%e3%83%a1%e3%83%b3%e3%83%90%e9%96%a2%e6%95%b0%e3%81%ae%e5%ae%9a%e7%be%a9>#</a></h3><p><code>from_toml</code> メンバ関数を定義することによっても変換を定義することができます。</p><p>これを使用する場合、デフォルトコンストラクタが必要です。</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>両方が定義されていた場合、 <code>toml::from</code> が優先されます。</p><h3 id=tomlvalue-を受け取るコンストラクタ><code>toml::value</code> を受け取るコンストラクタ
|
||||
<a class=anchor href=#tomlvalue-%e3%82%92%e5%8f%97%e3%81%91%e5%8f%96%e3%82%8b%e3%82%b3%e3%83%b3%e3%82%b9%e3%83%88%e3%83%a9%e3%82%af%e3%82%bf>#</a></h3><p><code>toml::value</code> を受け取るコンストラクタがあれば、 <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>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>両方が定義されていた場合、<code>toml::from</code> と <code>from_toml</code> が優先されます。</p><h2 id=tomlvisitで関数を適用する><code>toml::visit</code>で関数を適用する
|
||||
<a class=anchor href=#tomlvisit%e3%81%a7%e9%96%a2%e6%95%b0%e3%82%92%e9%81%a9%e7%94%a8%e3%81%99%e3%82%8b>#</a></h2><p><code>toml::value</code> が格納する型すべてに適用できる関数オブジェクトがあれば、
|
||||
<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=tomlvalue-を構築する><code>toml::value</code> を構築する
|
||||
<a class=anchor href=#tomlvalue-%e3%82%92%e6%a7%8b%e7%af%89%e3%81%99%e3%82%8b>#</a></h2><p><code>toml::value</code> はパーサの内部だけでなく、ユーザーコードで構築することも可能です。</p><p><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>配列の場合、 <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>配列の場合、 <code>std::vector</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> 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>このコンテナには、 <code>toml::get</code> で変換可能なコンテナが使用できます。</p><p>テーブルの場合も同様に、 <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><code>std::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-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>コンストラクタには、 <code>format_info</code> と コメントを渡すことができます。</p><p>コメントの型は <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>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=tomlvalue-に変換する><code>toml::value</code> に変換する
|
||||
<a class=anchor href=#tomlvalue-%e3%81%ab%e5%a4%89%e6%8f%9b%e3%81%99%e3%82%8b>#</a></h2><p>ユーザー定義型から <code>toml::value</code> を構築する際に、 <code>toml::into</code> や <code>into_toml</code> を
|
||||
定義することで、その挙動をカスタマイズできます。</p><p>特に、別のライブラリの型などを変換する際に <code>toml::into</code> が便利です。</p><h3 id=tomlintoを定義する><code>toml::into</code>を定義する
|
||||
<a class=anchor href=#tomlinto%e3%82%92%e5%ae%9a%e7%be%a9%e3%81%99%e3%82%8b>#</a></h3><p><code>toml::into</code> を特殊化することで <code>toml::value</code> への変換が可能になります。</p><p><code>toml::value</code> への変換が用意されていない外部ライブラリの型などに対して有効です。</p><p><code>toml::value</code> が変換時に <code>type_config</code> を渡すため、<code>basic_value</code> の <code>template</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=into_toml-メンバ関数を定義する><code>into_toml</code> メンバ関数を定義する
|
||||
<a class=anchor href=#into_toml-%e3%83%a1%e3%83%b3%e3%83%90%e9%96%a2%e6%95%b0%e3%82%92%e5%ae%9a%e7%be%a9%e3%81%99%e3%82%8b>#</a></h3><p><code>from_toml</code> と同様、メンバ関数によっても変換を定義することができます。</p><p><code>toml::into</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>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> toml<span style=color:#f92672>::</span>value 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>value(toml<span style=color:#f92672>::</span>table{{<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></code></pre></div><h1 id=値がアクセス済みかどうかチェックする>値がアクセス済みかどうかチェックする
|
||||
<a class=anchor href=#%e5%80%a4%e3%81%8c%e3%82%a2%e3%82%af%e3%82%bb%e3%82%b9%e6%b8%88%e3%81%bf%e3%81%8b%e3%81%a9%e3%81%86%e3%81%8b%e3%83%81%e3%82%a7%e3%83%83%e3%82%af%e3%81%99%e3%82%8b>#</a></h1><p><code>TOML11_ENABLE_ACCESS_CHECK</code>マクロを定義してコンパイルすると、<code>toml::value</code>に<code>bool accessed() const</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>$ 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><div class=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><div class=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>この機能によって、テーブル内に定義されているものの使用されなかった値についての警告を表示することが可能になります。</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> v)
|
||||
</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>// yours
|
||||
</span></span></span></code></pre></div><p>この機能は、必要な場合のみ定義されるような値を、名称を間違えて定義してしまった際に役に立つでしょう。
|
||||
例えば、</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># 正しくは 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># 名前が違うので読み込めない</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>このファイルを上記のコードで読んだ場合、<code>read_your_config</code>は<code>reactions</code>を探し、定義されていなかったので空の配列として処理するでしょう。
|
||||
その場合、<code>reaction</code>は<code>accessed()</code>が<code>true</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=#値を取り出す>値を取り出す</a><ul><li><a href=#メンバ関数を使って値にアクセスする>メンバ関数を使って値にアクセスする</a><ul><li><a href=#is_something-と-as_something><code>is_something</code> と <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=#コメントにアクセスする>コメントにアクセスする</a></li><li><a href=#インラインテーブルドットキーの取り扱い>インラインテーブル・ドットキーの取り扱い</a></li><li><a href=#日付情報の取り扱い>日付情報の取り扱い</a></li><li><a href=#tomlgettを使って変換する><code>toml::get<T></code>を使って変換する</a><ul><li><a href=#単純な変換>単純な変換</a></li><li><a href=#参照を取得できる条件>参照を取得できる条件</a></li><li><a href=#配列をstlコンテナに>配列をSTLコンテナに</a></li><li><a href=#配列を-stdpair-stdtuple-に>配列を <code>std::pair</code>, <code>std::tuple</code> に</a></li><li><a href=#ネストされた配列の変換>ネストされた配列の変換</a></li><li><a href=#テーブルを-stdmap-に変換>テーブルを <code>std::map</code> に変換</a></li></ul></li><li><a href=#tomlget_orを使って失敗時の値を指定する><code>toml::get_or</code>を使って失敗時の値を指定する</a></li><li><a href=#tomlfindtを使って検索と変換を同時に行う><code>toml::find<T></code>を使って検索と変換を同時に行う</a></li><li><a href=#tomlfind_orを使って失敗時の値を指定する><code>toml::find_or</code>を使って失敗時の値を指定する</a></li><li><a href=#tomlfind_or_defaultを使って失敗時の値を指定する><code>toml::find_or_default</code>を使って失敗時の値を指定する</a></li><li><a href=#tomlfindstdoptionalt><code>toml::find<std::optional<T>></code></a></li><li><a href=#ユーザー定義型との変換を定義する>ユーザー定義型との変換を定義する</a><ul><li><a href=#tomlfrom-の定義><code>toml::from</code> の定義</a></li><li><a href=#from_toml-メンバ関数の定義><code>from_toml</code> メンバ関数の定義</a></li><li><a href=#tomlvalue-を受け取るコンストラクタ><code>toml::value</code> を受け取るコンストラクタ</a></li></ul></li><li><a href=#tomlvisitで関数を適用する><code>toml::visit</code>で関数を適用する</a></li><li><a href=#tomlvalue-を構築する><code>toml::value</code> を構築する</a></li><li><a href=#tomlvalue-に変換する><code>toml::value</code> に変換する</a><ul><li><a href=#tomlintoを定義する><code>toml::into</code>を定義する</a></li><li><a href=#into_toml-メンバ関数を定義する><code>into_toml</code> メンバ関数を定義する</a></li></ul></li></ul></li><li><a href=#値がアクセス済みかどうかチェックする>値がアクセス済みかどうかチェックする</a></li></ul></nav></div></aside></main></body></html>
|
||||
8
ja/docs/index.html
Normal file
8
ja/docs/index.html
Normal file
@@ -0,0 +1,8 @@
|
||||
<!doctype html><html lang=ja 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/ja/docs/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="Docs"><meta property="og:locale" content="ja"><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/ja/docs/><link rel=alternate hreflang=en href=https://toruniina.github.io/toml11/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/ja.search.min.b1a1e3e4be0fdf11fae2bb2370353d99ecd7abea7ccc29273319c021dda76dfd.js integrity="sha256-saHj5L4P3xH64rsjcDU9mezXq+p8zCknMxnAId2nbf0=" crossorigin=anonymous></script><link rel=alternate type=application/rss+xml href=https://toruniina.github.io/toml11/ja/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/ja/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=検索 aria-label=検索 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>
|
||||
日本語</a></label><ul><li><a href=https://toruniina.github.io/toml11/docs/>English</a></li></ul></li></ul><ul><li><a href=/toml11/ja/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-b4cfb5b55e913a8d853eacf5e8fba05f class=toggle>
|
||||
<label for=section-b4cfb5b55e913a8d853eacf5e8fba05f class="flex justify-between"><a href=/toml11/ja/docs/features/>features</a></label><ul><li><a href=/toml11/ja/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/ja/docs/features/value/>getting values</a></li><li><a href=/toml11/ja/docs/features/error_message/>error message</a></li><li><a href=/toml11/ja/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/ja/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/ja/docs/features/literal/>toml literal</a></li><li><a href=/toml11/ja/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/ja/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-01b096afc5186aea96713b408b47c967 class=toggle>
|
||||
<label for=section-01b096afc5186aea96713b408b47c967 class="flex justify-between"><a href=/toml11/ja/docs/reference/>reference</a></label><ul><li><a href=/toml11/ja/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/ja/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/ja/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/ja/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/ja/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/ja/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/ja/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/ja/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/ja/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/ja/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/ja/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/ja/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/ja/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/ja/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/ja/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/ja/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/ja/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/ja/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/ja/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/ja/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/ja/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/ja/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/ja/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/ja/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
ja/docs/index.xml
Normal file
1
ja/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/ja/docs/</link><description>Recent content in Docs on toml11</description><generator>Hugo</generator><language>ja</language><atom:link href="https://toruniina.github.io/toml11/ja/docs/index.xml" rel="self" type="application/rss+xml"/></channel></rss>
|
||||
145
ja/docs/installation/index.html
Normal file
145
ja/docs/installation/index.html
Normal file
@@ -0,0 +1,145 @@
|
||||
<!doctype html><html lang=ja dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content='
|
||||
installation
|
||||
#
|
||||
|
||||
|
||||
single_includeを使用する
|
||||
#
|
||||
|
||||
single_include/toml.hppは、toml11が持つ全ての機能を単一のファイルにまとめたシングルファイル・ヘッダオンリーライブラリです。
|
||||
これをINCLUDE_PATHが通っている箇所にコピーして#include <toml.hpp>とするのが最も単純な使用方法です。
|
||||
MITライセンスの許諾表示はコメントとtoml:license_notice()関数の両方に含まれます。
|
||||
ソースコードを公開せずに再頒布する場合は、toml11のライセンスファイルをコピーして同梱するか、この関数を呼び出せるようにしておいてください。
|
||||
|
||||
toml11をクローンし、cmakeを使って使用する
|
||||
#
|
||||
|
||||
toml11をgit submoduleなどによって自身のレポジトリ下に配置した場合、cmakeを使用している場合はadd_subdirectory(toml11)のようにすることで使用可能になります。
|
||||
add_subdirectory(toml11)
|
||||
add_executable(main main.cpp)
|
||||
target_link_libraries(main PUBLIC toml11::toml11)
|
||||
toml11は自身がルートプロジェクトのときのみ、テストとインストールを行います。
|
||||
|
||||
CMake FetchContent
|
||||
#
|
||||
|
||||
CMakeの FetchContentを使用することで、buildディレクトリに自動でダウンロードすることができます。
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
toml11
|
||||
GIT_REPOSITORY https://github.com/ToruNiina/toml11.git
|
||||
GIT_TAG v4.4.0
|
||||
)
|
||||
FetchContent_MakeAvailable(toml11)
|
||||
|
||||
add_executable(main main.cpp)
|
||||
target_link_libraries(main PRIVATE toml11::toml11)
|
||||
|
||||
CMake Package Manager (CPM)
|
||||
#
|
||||
|
||||
CMake package managerを導入すると、以下のようにして使用することができます。
|
||||
include(cmake/CPM.cmake)
|
||||
|
||||
CPMAddPackage("gh:ToruNiina/toml11@4.4.0")
|
||||
|
||||
# OR
|
||||
|
||||
CPMAddPackage(
|
||||
NAME toml11
|
||||
GITHUB_REPOSITORY "ToruNiina/toml11"
|
||||
VERSION 4.4.0
|
||||
OPTIONS
|
||||
"TOML11_PRECOMPILE ON" # to pre-compile
|
||||
"TOML11_ENABLE_ACCESS_CHECK ON" # to use value.accessed()
|
||||
)
|
||||
|
||||
add_executable(main main.cpp)
|
||||
target_link_libraries(main PUBLIC toml11::toml11)
|
||||
|
||||
cmakeを使用してインストールする
|
||||
#
|
||||
|
||||
toml11をクローンしたのち、cmakeを使ってインストールすることができます。'><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/ja/docs/installation/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="installation"><meta property="og:description" content='installation # single_includeを使用する # single_include/toml.hppは、toml11が持つ全ての機能を単一のファイルにまとめたシングルファイル・ヘッダオンリーライブラリです。
|
||||
これをINCLUDE_PATHが通っている箇所にコピーして#include <toml.hpp>とするのが最も単純な使用方法です。
|
||||
MITライセンスの許諾表示はコメントとtoml:license_notice()関数の両方に含まれます。 ソースコードを公開せずに再頒布する場合は、toml11のライセンスファイルをコピーして同梱するか、この関数を呼び出せるようにしておいてください。
|
||||
toml11をクローンし、cmakeを使って使用する # toml11をgit submoduleなどによって自身のレポジトリ下に配置した場合、cmakeを使用している場合はadd_subdirectory(toml11)のようにすることで使用可能になります。
|
||||
add_subdirectory(toml11) add_executable(main main.cpp) target_link_libraries(main PUBLIC toml11::toml11) toml11は自身がルートプロジェクトのときのみ、テストとインストールを行います。
|
||||
CMake FetchContent # CMakeの FetchContentを使用することで、buildディレクトリに自動でダウンロードすることができます。
|
||||
include(FetchContent) FetchContent_Declare( toml11 GIT_REPOSITORY https://github.com/ToruNiina/toml11.git GIT_TAG v4.4.0 ) FetchContent_MakeAvailable(toml11) add_executable(main main.cpp) target_link_libraries(main PRIVATE toml11::toml11) CMake Package Manager (CPM) # CMake package managerを導入すると、以下のようにして使用することができます。
|
||||
include(cmake/CPM.cmake) CPMAddPackage("gh:ToruNiina/toml11@4.4.0") # OR CPMAddPackage( NAME toml11 GITHUB_REPOSITORY "ToruNiina/toml11" VERSION 4.4.0 OPTIONS "TOML11_PRECOMPILE ON" # to pre-compile "TOML11_ENABLE_ACCESS_CHECK ON" # to use value.accessed() ) add_executable(main main.cpp) target_link_libraries(main PUBLIC toml11::toml11) cmakeを使用してインストールする # toml11をクローンしたのち、cmakeを使ってインストールすることができます。'><meta property="og:locale" content="ja"><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/ja/docs/installation/><link rel=alternate hreflang=en href=https://toruniina.github.io/toml11/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/ja.search.min.b1a1e3e4be0fdf11fae2bb2370353d99ecd7abea7ccc29273319c021dda76dfd.js integrity="sha256-saHj5L4P3xH64rsjcDU9mezXq+p8zCknMxnAId2nbf0=" crossorigin=anonymous></script><link rel=alternate type=application/rss+xml href=https://toruniina.github.io/toml11/ja/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/ja/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=検索 aria-label=検索 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>
|
||||
日本語</a></label><ul><li><a href=https://toruniina.github.io/toml11/docs/installation/>English</a></li></ul></li></ul><ul><li><a href=/toml11/ja/docs/installation/ class=active>installation</a><ul></ul></li><li><input type=checkbox id=section-b4cfb5b55e913a8d853eacf5e8fba05f class=toggle>
|
||||
<label for=section-b4cfb5b55e913a8d853eacf5e8fba05f class="flex justify-between"><a href=/toml11/ja/docs/features/>features</a></label><ul><li><a href=/toml11/ja/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/ja/docs/features/value/>getting values</a></li><li><a href=/toml11/ja/docs/features/error_message/>error message</a></li><li><a href=/toml11/ja/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/ja/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/ja/docs/features/literal/>toml literal</a></li><li><a href=/toml11/ja/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/ja/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-01b096afc5186aea96713b408b47c967 class=toggle>
|
||||
<label for=section-01b096afc5186aea96713b408b47c967 class="flex justify-between"><a href=/toml11/ja/docs/reference/>reference</a></label><ul><li><a href=/toml11/ja/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/ja/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/ja/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/ja/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/ja/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/ja/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/ja/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/ja/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/ja/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/ja/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/ja/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/ja/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/ja/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/ja/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/ja/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/ja/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/ja/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/ja/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/ja/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/ja/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/ja/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/ja/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/ja/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/ja/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=#single_includeを使用する><code>single_include</code>を使用する</a></li><li><a href=#toml11をクローンしcmakeを使って使用する>toml11をクローンし、<code>cmake</code>を使って使用する</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=#cmakeを使用してインストールする><code>cmake</code>を使用してインストールする</a></li><li><a href=#cmakeを使用してコンパイルし静的ライブラリを作成する><code>cmake</code>を使用してコンパイルし、静的ライブラリを作成する</a></li><li><a href=#examplesをコンパイルする>examplesをコンパイルする</a></li><li><a href=#テストを実行する>テストを実行する</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=single_includeを使用する><code>single_include</code>を使用する
|
||||
<a class=anchor href=#single_include%e3%82%92%e4%bd%bf%e7%94%a8%e3%81%99%e3%82%8b>#</a></h2><p><code>single_include/toml.hpp</code>は、<code>toml11</code>が持つ全ての機能を単一のファイルにまとめたシングルファイル・ヘッダオンリーライブラリです。</p><p>これを<code>INCLUDE_PATH</code>が通っている箇所にコピーして<code>#include <toml.hpp></code>とするのが最も単純な使用方法です。</p><p>MITライセンスの許諾表示はコメントと<code>toml:license_notice()</code>関数の両方に含まれます。
|
||||
ソースコードを公開せずに再頒布する場合は、toml11のライセンスファイルをコピーして同梱するか、この関数を呼び出せるようにしておいてください。</p><h2 id=toml11をクローンしcmakeを使って使用する>toml11をクローンし、<code>cmake</code>を使って使用する
|
||||
<a class=anchor href=#toml11%e3%82%92%e3%82%af%e3%83%ad%e3%83%bc%e3%83%b3%e3%81%97cmake%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e4%bd%bf%e7%94%a8%e3%81%99%e3%82%8b>#</a></h2><p><code>toml11</code>を<code>git submodule</code>などによって自身のレポジトリ下に配置した場合、<code>cmake</code>を使用している場合は<code>add_subdirectory(toml11)</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><code>toml11</code>は自身がルートプロジェクトのときのみ、テストとインストールを行います。</p><h3 id=cmake-fetchcontent>CMake <code>FetchContent</code>
|
||||
<a class=anchor href=#cmake-fetchcontent>#</a></h3><p>CMakeの <code>FetchContent</code>を使用することで、<code>build</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>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><a href=https://github.com/cpm-cmake/CPM.cmake>CMake package manager</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-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=cmakeを使用してインストールする><code>cmake</code>を使用してインストールする
|
||||
<a class=anchor href=#cmake%e3%82%92%e4%bd%bf%e7%94%a8%e3%81%97%e3%81%a6%e3%82%a4%e3%83%b3%e3%82%b9%e3%83%88%e3%83%bc%e3%83%ab%e3%81%99%e3%82%8b>#</a></h2><p><code>toml11</code>をクローンしたのち、<code>cmake</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_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>インストールの前にテストプログラムを実行する際は、最初に<code>-DTOML11_BUILD_TESTS=ON</code>を設定してください。</p><p>インストールが完了すれば、以下のようにして使用できます。</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=cmakeを使用してコンパイルし静的ライブラリを作成する><code>cmake</code>を使用してコンパイルし、静的ライブラリを作成する
|
||||
<a class=anchor href=#cmake%e3%82%92%e4%bd%bf%e7%94%a8%e3%81%97%e3%81%a6%e3%82%b3%e3%83%b3%e3%83%91%e3%82%a4%e3%83%ab%e3%81%97%e9%9d%99%e7%9a%84%e3%83%a9%e3%82%a4%e3%83%96%e3%83%a9%e3%83%aa%e3%82%92%e4%bd%9c%e6%88%90%e3%81%99%e3%82%8b>#</a></h2><p><code>cmake</code>の実行時に<code>-DTOML11_PRECOMPILE=ON</code>を定義することで、<code>toml11</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_PRECOMPILE<span style=color:#f92672>=</span>ON
|
||||
</span></span></code></pre></div><p>ライブラリをリンクする場合は、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>とするか、ヘッダ内の関数の<code>inline</code>化を避けるためにコンパイラに<code>-DTOML11_COMPILE_SOURCES</code>を渡してください。</p><p>ただし、toml11は複数のC++バージョンに対応するため、<code>__cplusplus</code>の値などによって型を切り替えることがあります。
|
||||
そのため、ビルドした際のバージョンと使用時のバージョンが異なる場合、リンクに失敗する可能性があります。
|
||||
問題が生じた場合は<code>CMAKE_CXX_STANDARD</code>によって必要なバージョンを設定してコンパイルしてください。
|
||||
それが難しい場合は、通常通りヘッダオンリーライブラリとして使用してください。</p><p><code>find_package(toml11)</code>によって<code>TOML11_INCLUDE_DIR</code>が定義されます。
|
||||
コンパイル済みライブラリとしてインストールした場合でも、 <code>TOML11_INCLUDE_DIR</code> を
|
||||
<code>include_directories</code> に追加した上で <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># インクルードのみ可能にし、リンクを行わない
|
||||
</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=examplesをコンパイルする>examplesをコンパイルする
|
||||
<a class=anchor href=#examples%e3%82%92%e3%82%b3%e3%83%b3%e3%83%91%e3%82%a4%e3%83%ab%e3%81%99%e3%82%8b>#</a></h2><p><code>-DTOML11_BUILD_EXAMPLES=ON</code>とすることで、<code>examples/</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><code>examples</code>の実行バイナリは<code>examples/</code>に生成されます。</p><h2 id=テストを実行する>テストを実行する
|
||||
<a class=anchor href=#%e3%83%86%e3%82%b9%e3%83%88%e3%82%92%e5%ae%9f%e8%a1%8c%e3%81%99%e3%82%8b>#</a></h2><p>テストをビルドするためには、<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>toml-lang/toml-testsを実行するには、<code>-DTOML11_BUILD_TOML_TESTS=ON</code>とします。
|
||||
すると、<code>tests/</code>に<code>toml11_decoder</code>と<code>toml11_encoder</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_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=#single_includeを使用する><code>single_include</code>を使用する</a></li><li><a href=#toml11をクローンしcmakeを使って使用する>toml11をクローンし、<code>cmake</code>を使って使用する</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=#cmakeを使用してインストールする><code>cmake</code>を使用してインストールする</a></li><li><a href=#cmakeを使用してコンパイルし静的ライブラリを作成する><code>cmake</code>を使用してコンパイルし、静的ライブラリを作成する</a></li><li><a href=#examplesをコンパイルする>examplesをコンパイルする</a></li><li><a href=#テストを実行する>テストを実行する</a></li></ul></li></ul></nav></div></aside></main></body></html>
|
||||
1
ja/docs/installation/index.xml
Normal file
1
ja/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/ja/docs/installation/</link><description>Recent content in installation on toml11</description><generator>Hugo</generator><language>ja</language><atom:link href="https://toruniina.github.io/toml11/ja/docs/installation/index.xml" rel="self" type="application/rss+xml"/></channel></rss>
|
||||
167
ja/docs/reference/color/index.html
Normal file
167
ja/docs/reference/color/index.html
Normal file
@@ -0,0 +1,167 @@
|
||||
<!doctype html><html lang=ja dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content='
|
||||
color.hpp
|
||||
#
|
||||
|
||||
color.hppでは、エラーメッセージの色付けに関する関数が定義されます。
|
||||
色はANSIエスケープシーケンスによって指定されます。
|
||||
ANSIエスケープシーケンスをサポートしていないターミナルやその他の出力先では、読みにくくなる可能性があります。
|
||||
|
||||
マクロ
|
||||
#
|
||||
|
||||
|
||||
TOML11_COLORIZE_ERROR_MESSAGE
|
||||
#
|
||||
|
||||
コンパイル時にこのマクロが定義されていた場合(-DTOML11_COLORIZE_ERROR_MESASGE)、
|
||||
デフォルトでエラーメッセージに色が付きます。
|
||||
定義されていなかった場合、デフォルトでは色は付きません。以下の toml::color::enable() を
|
||||
使用して指定する必要があります。
|
||||
|
||||
TOML11_USE_THREAD_LOCAL_COLORIZATION
|
||||
#
|
||||
|
||||
コンパイル時にこのマクロが定義されていた場合(-DTOML11_COLORIZE_ERROR_MESASGE)、
|
||||
toml::color::enableの設定がthread_localになります。
|
||||
この場合、toml::color::enable()やtoml::color::disable()は、それを呼び出したスレッドでの設定しか変更しません。
|
||||
つまり、新しいスレッドを起動した際にデフォルトと異なる設定にしたい場合は、再度設定が必要になります。
|
||||
その代わり、toml::color::enable()やtoml::color::disable()はスレッドセーフになります。
|
||||
デフォルトでは設定はグローバルです。
|
||||
グローバルの場合、一つのスレッドがtoml::color::enable()を実行した場合、すべてのスレッドで色が付きます。
|
||||
ただし、あるスレッドがenable()またはdisable()を実行している間に別のスレッドがenable()、disable()、should_color()を実行した場合、その結果は未定義です。
|
||||
|
||||
関数
|
||||
#
|
||||
|
||||
|
||||
enable()
|
||||
#
|
||||
|
||||
namespace toml {
|
||||
namespace color {
|
||||
void enable();
|
||||
} // color
|
||||
} // toml
|
||||
ANSIエスケープシーケンスによる色付けを行うよう設定します。
|
||||
|
||||
例
|
||||
#
|
||||
|
||||
#include <toml.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
toml::color::enable(); // この後の全てのエラーがカラーになります。
|
||||
const auto input = toml::parse("input.toml");
|
||||
return 0;
|
||||
}
|
||||
|
||||
disable()
|
||||
#
|
||||
|
||||
namespace toml {
|
||||
namespace color {
|
||||
void disable();
|
||||
} // color
|
||||
} // toml
|
||||
ANSIエスケープシーケンスによる色付けを行わないよう設定します。'><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/ja/docs/reference/color/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="color.hpp"><meta property="og:description" content='color.hpp # color.hppでは、エラーメッセージの色付けに関する関数が定義されます。
|
||||
色はANSIエスケープシーケンスによって指定されます。 ANSIエスケープシーケンスをサポートしていないターミナルやその他の出力先では、読みにくくなる可能性があります。
|
||||
マクロ # TOML11_COLORIZE_ERROR_MESSAGE # コンパイル時にこのマクロが定義されていた場合(-DTOML11_COLORIZE_ERROR_MESASGE)、 デフォルトでエラーメッセージに色が付きます。
|
||||
定義されていなかった場合、デフォルトでは色は付きません。以下の toml::color::enable() を 使用して指定する必要があります。
|
||||
TOML11_USE_THREAD_LOCAL_COLORIZATION # コンパイル時にこのマクロが定義されていた場合(-DTOML11_COLORIZE_ERROR_MESASGE)、 toml::color::enableの設定がthread_localになります。 この場合、toml::color::enable()やtoml::color::disable()は、それを呼び出したスレッドでの設定しか変更しません。 つまり、新しいスレッドを起動した際にデフォルトと異なる設定にしたい場合は、再度設定が必要になります。 その代わり、toml::color::enable()やtoml::color::disable()はスレッドセーフになります。
|
||||
デフォルトでは設定はグローバルです。 グローバルの場合、一つのスレッドがtoml::color::enable()を実行した場合、すべてのスレッドで色が付きます。 ただし、あるスレッドがenable()またはdisable()を実行している間に別のスレッドがenable()、disable()、should_color()を実行した場合、その結果は未定義です。
|
||||
関数 # enable() # namespace toml { namespace color { void enable(); } // color } // toml ANSIエスケープシーケンスによる色付けを行うよう設定します。
|
||||
例 # #include <toml.hpp> int main() { toml::color::enable(); // この後の全てのエラーがカラーになります。 const auto input = toml::parse("input.toml"); return 0; } disable() # namespace toml { namespace color { void disable(); } // color } // toml ANSIエスケープシーケンスによる色付けを行わないよう設定します。'><meta property="og:locale" content="ja"><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/ja/docs/reference/color/><link rel=alternate hreflang=en href=https://toruniina.github.io/toml11/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/ja.search.min.b1a1e3e4be0fdf11fae2bb2370353d99ecd7abea7ccc29273319c021dda76dfd.js integrity="sha256-saHj5L4P3xH64rsjcDU9mezXq+p8zCknMxnAId2nbf0=" 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/ja/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=検索 aria-label=検索 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>
|
||||
日本語</a></label><ul><li><a href=https://toruniina.github.io/toml11/docs/reference/color/>English</a></li></ul></li></ul><ul><li><a href=/toml11/ja/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-b4cfb5b55e913a8d853eacf5e8fba05f class=toggle>
|
||||
<label for=section-b4cfb5b55e913a8d853eacf5e8fba05f class="flex justify-between"><a href=/toml11/ja/docs/features/>features</a></label><ul><li><a href=/toml11/ja/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/ja/docs/features/value/>getting values</a></li><li><a href=/toml11/ja/docs/features/error_message/>error message</a></li><li><a href=/toml11/ja/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/ja/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/ja/docs/features/literal/>toml literal</a></li><li><a href=/toml11/ja/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/ja/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-01b096afc5186aea96713b408b47c967 class=toggle checked>
|
||||
<label for=section-01b096afc5186aea96713b408b47c967 class="flex justify-between"><a href=/toml11/ja/docs/reference/>reference</a></label><ul><li><a href=/toml11/ja/docs/reference/color/ class=active>color.hpp</a></li><li><a href=/toml11/ja/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/ja/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/ja/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/ja/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/ja/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/ja/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/ja/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/ja/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/ja/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/ja/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/ja/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/ja/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/ja/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/ja/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/ja/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/ja/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/ja/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/ja/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/ja/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/ja/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/ja/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/ja/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/ja/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=#マクロ>マクロ</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=#関数>関数</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=#マニピュレータ>マニピュレータ</a><ul><li></li></ul></li></ul></li><li><a href=#関連項目>関連項目</a></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=colorhpp>color.hpp
|
||||
<a class=anchor href=#colorhpp>#</a></h1><p><code>color.hpp</code>では、エラーメッセージの色付けに関する関数が定義されます。</p><p>色はANSIエスケープシーケンスによって指定されます。
|
||||
ANSIエスケープシーケンスをサポートしていないターミナルやその他の出力先では、読みにくくなる可能性があります。</p><h2 id=マクロ>マクロ
|
||||
<a class=anchor href=#%e3%83%9e%e3%82%af%e3%83%ad>#</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>コンパイル時にこのマクロが定義されていた場合(<code>-DTOML11_COLORIZE_ERROR_MESASGE</code>)、
|
||||
デフォルトでエラーメッセージに色が付きます。</p><p>定義されていなかった場合、デフォルトでは色は付きません。以下の <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>コンパイル時にこのマクロが定義されていた場合(<code>-DTOML11_COLORIZE_ERROR_MESASGE</code>)、
|
||||
<code>toml::color::enable</code>の設定が<code>thread_local</code>になります。
|
||||
この場合、<code>toml::color::enable()</code>や<code>toml::color::disable()</code>は、それを呼び出したスレッドでの設定しか変更しません。
|
||||
つまり、新しいスレッドを起動した際にデフォルトと異なる設定にしたい場合は、再度設定が必要になります。
|
||||
その代わり、<code>toml::color::enable()</code>や<code>toml::color::disable()</code>はスレッドセーフになります。</p><p>デフォルトでは設定はグローバルです。
|
||||
グローバルの場合、一つのスレッドが<code>toml::color::enable()</code>を実行した場合、すべてのスレッドで色が付きます。
|
||||
ただし、あるスレッドが<code>enable()</code>または<code>disable()</code>を実行している間に別のスレッドが<code>enable()</code>、<code>disable()</code>、<code>should_color()</code>を実行した場合、その結果は未定義です。</p><h2 id=関数>関数
|
||||
<a class=anchor href=#%e9%96%a2%e6%95%b0>#</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>ANSIエスケープシーケンスによる色付けを行うよう設定します。</p><h4 id=例>例
|
||||
<a class=anchor href=#%e4%be%8b>#</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>// この後の全てのエラーがカラーになります。
|
||||
</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>ANSIエスケープシーケンスによる色付けを行わないよう設定します。</p><h4 id=例-1>例
|
||||
<a class=anchor href=#%e4%be%8b-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>enable(); <span style=color:#75715e>// この後の全てのエラーがカラーになります。
|
||||
</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>色付けを行う設定になっている場合<code>true</code>が、そうでない場合<code>false</code>が返されます。</p><h4 id=例-2>例
|
||||
<a class=anchor href=#%e4%be%8b-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=マニピュレータ>マニピュレータ
|
||||
<a class=anchor href=#%e3%83%9e%e3%83%8b%e3%83%94%e3%83%a5%e3%83%ac%e3%83%bc%e3%82%bf>#</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>ANSIエスケープシーケンスによって、<code>fg</code>を色付けします。</p><h4 id=例-3>例
|
||||
<a class=anchor href=#%e4%be%8b-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> 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=関連項目>関連項目
|
||||
<a class=anchor href=#%e9%96%a2%e9%80%a3%e9%a0%85%e7%9b%ae>#</a></h1><ul><li><a href=https://toruniina.github.io/toml11/ja/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=#マクロ>マクロ</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=#関数>関数</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=#マニピュレータ>マニピュレータ</a><ul><li></li></ul></li></ul></li><li><a href=#関連項目>関連項目</a></li></ul></nav></div></aside></main></body></html>
|
||||
359
ja/docs/reference/comments/index.html
Normal file
359
ja/docs/reference/comments/index.html
Normal file
File diff suppressed because one or more lines are too long
52
ja/docs/reference/conversion/index.html
Normal file
52
ja/docs/reference/conversion/index.html
Normal file
@@ -0,0 +1,52 @@
|
||||
<!doctype html><html lang=ja dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
|
||||
conversion.hpp
|
||||
#
|
||||
|
||||
toml::getやtoml::findでユーザー定義型をサポートするための変換関数を自動定義するマクロを提供します。
|
||||
TOML11_DEFINE_CONVERSION_NON_INTRUSIVE(NAME, ...)
|
||||
|
||||
例
|
||||
#
|
||||
|
||||
namespace foo
|
||||
{
|
||||
struct Foo
|
||||
{
|
||||
std::string s;
|
||||
double d;
|
||||
int i;
|
||||
};
|
||||
} // foo
|
||||
|
||||
TOML11_DEFINE_CONVERSION_NON_INTRUSIVE(foo::Foo, s, d, i)
|
||||
|
||||
関連項目
|
||||
#
|
||||
|
||||
|
||||
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/ja/docs/reference/conversion/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="conversion.hpp"><meta property="og:description" content="conversion.hpp # toml::getやtoml::findでユーザー定義型をサポートするための変換関数を自動定義するマクロを提供します。
|
||||
TOML11_DEFINE_CONVERSION_NON_INTRUSIVE(NAME, ...) 例 # namespace foo { struct Foo { std::string s; double d; int i; }; } // foo TOML11_DEFINE_CONVERSION_NON_INTRUSIVE(foo::Foo, s, d, i) 関連項目 # from.hpp into.hpp"><meta property="og:locale" content="ja"><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/ja/docs/reference/conversion/><link rel=alternate hreflang=en href=https://toruniina.github.io/toml11/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/ja.search.min.b1a1e3e4be0fdf11fae2bb2370353d99ecd7abea7ccc29273319c021dda76dfd.js integrity="sha256-saHj5L4P3xH64rsjcDU9mezXq+p8zCknMxnAId2nbf0=" 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/ja/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=検索 aria-label=検索 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>
|
||||
日本語</a></label><ul><li><a href=https://toruniina.github.io/toml11/docs/reference/conversion/>English</a></li></ul></li></ul><ul><li><a href=/toml11/ja/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-b4cfb5b55e913a8d853eacf5e8fba05f class=toggle>
|
||||
<label for=section-b4cfb5b55e913a8d853eacf5e8fba05f class="flex justify-between"><a href=/toml11/ja/docs/features/>features</a></label><ul><li><a href=/toml11/ja/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/ja/docs/features/value/>getting values</a></li><li><a href=/toml11/ja/docs/features/error_message/>error message</a></li><li><a href=/toml11/ja/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/ja/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/ja/docs/features/literal/>toml literal</a></li><li><a href=/toml11/ja/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/ja/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-01b096afc5186aea96713b408b47c967 class=toggle checked>
|
||||
<label for=section-01b096afc5186aea96713b408b47c967 class="flex justify-between"><a href=/toml11/ja/docs/reference/>reference</a></label><ul><li><a href=/toml11/ja/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/ja/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/ja/docs/reference/conversion/ class=active>conversion.hpp</a></li><li><a href=/toml11/ja/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/ja/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/ja/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/ja/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/ja/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/ja/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/ja/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/ja/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/ja/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/ja/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/ja/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/ja/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/ja/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/ja/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/ja/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/ja/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/ja/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/ja/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/ja/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/ja/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/ja/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=#例>例</a></li></ul></li><li><a href=#関連項目>関連項目</a></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=conversionhpp>conversion.hpp
|
||||
<a class=anchor href=#conversionhpp>#</a></h1><p><code>toml::get</code>や<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=例>例
|
||||
<a class=anchor href=#%e4%be%8b>#</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=関連項目>関連項目
|
||||
<a class=anchor href=#%e9%96%a2%e9%80%a3%e9%a0%85%e7%9b%ae>#</a></h1><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/reference/from/>from.hpp</a></li><li><a href=https://toruniina.github.io/toml11/ja/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=#例>例</a></li></ul></li><li><a href=#関連項目>関連項目</a></li></ul></nav></div></aside></main></body></html>
|
||||
443
ja/docs/reference/datetime/index.html
Normal file
443
ja/docs/reference/datetime/index.html
Normal file
File diff suppressed because one or more lines are too long
123
ja/docs/reference/error_info/index.html
Normal file
123
ja/docs/reference/error_info/index.html
Normal file
@@ -0,0 +1,123 @@
|
||||
<!doctype html><html lang=ja dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content='
|
||||
error_info.hpp
|
||||
#
|
||||
|
||||
error_info.hppでは、error_infoと、それをフォーマットする関数が定義されます。
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
メンバ関数
|
||||
#
|
||||
|
||||
|
||||
コンストラクタ(title, loc, msg, suffix)
|
||||
#
|
||||
|
||||
指定されたタイトル、位置情報、メッセージ、suffixからerror_infoを構築します。'><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/ja/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 # error_info.hppでは、error_infoと、それをフォーマットする関数が定義されます。
|
||||
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); } メンバ関数 # コンストラクタ(title, loc, msg, suffix) # 指定されたタイトル、位置情報、メッセージ、suffixからerror_infoを構築します。'><meta property="og:locale" content="ja"><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/ja/docs/reference/error_info/><link rel=alternate hreflang=en href=https://toruniina.github.io/toml11/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/ja.search.min.b1a1e3e4be0fdf11fae2bb2370353d99ecd7abea7ccc29273319c021dda76dfd.js integrity="sha256-saHj5L4P3xH64rsjcDU9mezXq+p8zCknMxnAId2nbf0=" 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/ja/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=検索 aria-label=検索 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>
|
||||
日本語</a></label><ul><li><a href=https://toruniina.github.io/toml11/docs/reference/error_info/>English</a></li></ul></li></ul><ul><li><a href=/toml11/ja/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-b4cfb5b55e913a8d853eacf5e8fba05f class=toggle>
|
||||
<label for=section-b4cfb5b55e913a8d853eacf5e8fba05f class="flex justify-between"><a href=/toml11/ja/docs/features/>features</a></label><ul><li><a href=/toml11/ja/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/ja/docs/features/value/>getting values</a></li><li><a href=/toml11/ja/docs/features/error_message/>error message</a></li><li><a href=/toml11/ja/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/ja/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/ja/docs/features/literal/>toml literal</a></li><li><a href=/toml11/ja/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/ja/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-01b096afc5186aea96713b408b47c967 class=toggle checked>
|
||||
<label for=section-01b096afc5186aea96713b408b47c967 class="flex justify-between"><a href=/toml11/ja/docs/reference/>reference</a></label><ul><li><a href=/toml11/ja/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/ja/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/ja/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/ja/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/ja/docs/reference/error_info/ class=active>error_info.hpp</a></li><li><a href=/toml11/ja/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/ja/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/ja/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/ja/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/ja/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/ja/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/ja/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/ja/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/ja/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/ja/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/ja/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/ja/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/ja/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/ja/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/ja/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/ja/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/ja/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/ja/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/ja/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=#メンバ関数>メンバ関数</a><ul><li><a href=#コンストラクタtitle-loc-msg-suffix>コンストラクタ(<code>title, loc, msg, suffix</code>)</a></li><li><a href=#コンストラクタtitle-loc-msg--suffix>コンストラクタ(<code>title, [{loc, msg}, ...], suffix</code>)</a></li></ul></li><li><a href=#メンバ関数-1>メンバ関数</a><ul><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=#非メンバ関数>非メンバ関数</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=#ストリーム演算子>ストリーム演算子</a></li></ul></li></ul></li><li><a href=#関連項目>関連項目</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><code>error_info.hpp</code>では、<code>error_info</code>と、それをフォーマットする関数が定義されます。</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=メンバ関数>メンバ関数
|
||||
<a class=anchor href=#%e3%83%a1%e3%83%b3%e3%83%90%e9%96%a2%e6%95%b0>#</a></h2><h3 id=コンストラクタtitle-loc-msg-suffix>コンストラクタ(<code>title, loc, msg, suffix</code>)
|
||||
<a class=anchor href=#%e3%82%b3%e3%83%b3%e3%82%b9%e3%83%88%e3%83%a9%e3%82%af%e3%82%bftitle-loc-msg-suffix>#</a></h3><p>指定されたタイトル、位置情報、メッセージ、suffixから<code>error_info</code>を構築します。</p><p><code>suffix</code>はデフォルトで空です。</p><h3 id=コンストラクタtitle-loc-msg--suffix>コンストラクタ(<code>title, [{loc, msg}, ...], suffix</code>)
|
||||
<a class=anchor href=#%e3%82%b3%e3%83%b3%e3%82%b9%e3%83%88%e3%83%a9%e3%82%af%e3%82%bftitle-loc-msg--suffix>#</a></h3><p>指定されたタイトル、位置情報とメッセージの配列、そして<code>suffix</code>から<code>error_info</code>を構築します。</p><p><code>suffix</code>はデフォルトで空です。</p><h2 id=メンバ関数-1>メンバ関数
|
||||
<a class=anchor href=#%e3%83%a1%e3%83%b3%e3%83%90%e9%96%a2%e6%95%b0-1>#</a></h2><h3 id=stdstring-title><code>std::string title()</code>
|
||||
<a class=anchor href=#stdstring-title>#</a></h3><p>エラーメッセージのタイトルです。</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>エラーの発生した位置とそれに関するメッセージです。</p><p>複数指定可能です。</p><h3 id=stdstring-suffix><code>std::string suffix()</code>
|
||||
<a class=anchor href=#stdstring-suffix>#</a></h3><p>最後に表示するメッセージです。ヒントや補足を表示します。</p><h2 id=非メンバ関数>非メンバ関数
|
||||
<a class=anchor href=#%e9%9d%9e%e3%83%a1%e3%83%b3%e3%83%90%e9%96%a2%e6%95%b0>#</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>新しく<code>error_info</code>を構築します。</p><p><code>source_location</code>または<code>basic_value</code>の後には、それに関する<code>msg</code>が続かなければなりません。</p><p><a href=https://toruniina.github.io/toml11/ja/docs/reference/value/#tomlmake_error_info><code>value.hpp</code></a>
|
||||
では、 <code>source_location</code> の代わりに <code>toml::basic_value</code> を渡した際のオーバーロードが追加されます。</p><p>末尾には<code>suffix</code>を渡すことが可能です。</p><h3 id=format_error><code>format_error</code>
|
||||
<a class=anchor href=#format_error>#</a></h3><p><code>error_info</code> を以下のようにフォーマットします。</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>二つの <code>source_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>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><code>error_info</code>をフォーマットします。</p><p><code>errkind</code>が与えられなかった場合、赤色太字の<code>[error]</code>が<code>title</code>の前につけ足されます。</p><p><code>errkind</code>が与えられた場合(空文字列の場合も含みます)、それが<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><code>make_error_info</code> を使って作成した <code>error_info</code> を <code>format_error</code> でフォーマットした文字列を返します。</p><p><a href=https://toruniina.github.io/toml11/ja/docs/reference/value/#tomlformat_error><code>value.hpp</code></a>
|
||||
では、 <code>source_location</code> の代わりに <code>toml::basic_value</code> を渡した際のオーバーロードが追加されます。</p><h3 id=ストリーム演算子>ストリーム演算子
|
||||
<a class=anchor href=#%e3%82%b9%e3%83%88%e3%83%aa%e3%83%bc%e3%83%a0%e6%bc%94%e7%ae%97%e5%ad%90>#</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><code>format_error(e)</code>を呼び出し、それを出力します。</p><h1 id=関連項目>関連項目
|
||||
<a class=anchor href=#%e9%96%a2%e9%80%a3%e9%a0%85%e7%9b%ae>#</a></h1><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/reference/color/>color.hpp</a></li><li><a href=https://toruniina.github.io/toml11/ja/docs/reference/parser/>parser.hpp</a></li><li><a href=https://toruniina.github.io/toml11/ja/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=#メンバ関数>メンバ関数</a><ul><li><a href=#コンストラクタtitle-loc-msg-suffix>コンストラクタ(<code>title, loc, msg, suffix</code>)</a></li><li><a href=#コンストラクタtitle-loc-msg--suffix>コンストラクタ(<code>title, [{loc, msg}, ...], suffix</code>)</a></li></ul></li><li><a href=#メンバ関数-1>メンバ関数</a><ul><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=#非メンバ関数>非メンバ関数</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=#ストリーム演算子>ストリーム演算子</a></li></ul></li></ul></li><li><a href=#関連項目>関連項目</a></li></ul></nav></div></aside></main></body></html>
|
||||
59
ja/docs/reference/exception/index.html
Normal file
59
ja/docs/reference/exception/index.html
Normal file
@@ -0,0 +1,59 @@
|
||||
<!doctype html><html lang=ja 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
|
||||
#
|
||||
|
||||
toml11で定義される例外型の基底クラスです。
|
||||
namespace toml
|
||||
{
|
||||
struct exception : public std::exception
|
||||
{
|
||||
public:
|
||||
virtual ~exception() noexcept override = default;
|
||||
virtual const char* what() const noexcept override {return "";}
|
||||
};
|
||||
} // toml
|
||||
|
||||
メンバ関数
|
||||
#
|
||||
|
||||
|
||||
デストラクタ
|
||||
#
|
||||
|
||||
virtual ~exception() noexcept override = default;
|
||||
派生する際に上書きします。
|
||||
|
||||
what
|
||||
#
|
||||
|
||||
virtual const char* what() const noexcept override {return "";}
|
||||
エラーメッセージを返します。派生する際に上書きします。'><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/ja/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 # toml11で定義される例外型の基底クラスです。
|
||||
namespace toml { struct exception : public std::exception { public: virtual ~exception() noexcept override = default; virtual const char* what() const noexcept override {return "";} }; } // toml メンバ関数 # デストラクタ # virtual ~exception() noexcept override = default; 派生する際に上書きします。
|
||||
what # virtual const char* what() const noexcept override {return "";} エラーメッセージを返します。派生する際に上書きします。'><meta property="og:locale" content="ja"><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/ja/docs/reference/exception/><link rel=alternate hreflang=en href=https://toruniina.github.io/toml11/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/ja.search.min.b1a1e3e4be0fdf11fae2bb2370353d99ecd7abea7ccc29273319c021dda76dfd.js integrity="sha256-saHj5L4P3xH64rsjcDU9mezXq+p8zCknMxnAId2nbf0=" 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/ja/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=検索 aria-label=検索 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>
|
||||
日本語</a></label><ul><li><a href=https://toruniina.github.io/toml11/docs/reference/exception/>English</a></li></ul></li></ul><ul><li><a href=/toml11/ja/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-b4cfb5b55e913a8d853eacf5e8fba05f class=toggle>
|
||||
<label for=section-b4cfb5b55e913a8d853eacf5e8fba05f class="flex justify-between"><a href=/toml11/ja/docs/features/>features</a></label><ul><li><a href=/toml11/ja/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/ja/docs/features/value/>getting values</a></li><li><a href=/toml11/ja/docs/features/error_message/>error message</a></li><li><a href=/toml11/ja/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/ja/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/ja/docs/features/literal/>toml literal</a></li><li><a href=/toml11/ja/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/ja/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-01b096afc5186aea96713b408b47c967 class=toggle checked>
|
||||
<label for=section-01b096afc5186aea96713b408b47c967 class="flex justify-between"><a href=/toml11/ja/docs/reference/>reference</a></label><ul><li><a href=/toml11/ja/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/ja/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/ja/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/ja/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/ja/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/ja/docs/reference/exception/ class=active>exception.hpp</a></li><li><a href=/toml11/ja/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/ja/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/ja/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/ja/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/ja/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/ja/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/ja/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/ja/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/ja/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/ja/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/ja/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/ja/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/ja/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/ja/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/ja/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/ja/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/ja/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/ja/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=#メンバ関数>メンバ関数</a><ul><li><a href=#デストラクタ>デストラクタ</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>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=メンバ関数>メンバ関数
|
||||
<a class=anchor href=#%e3%83%a1%e3%83%b3%e3%83%90%e9%96%a2%e6%95%b0>#</a></h2><h3 id=デストラクタ>デストラクタ
|
||||
<a class=anchor href=#%e3%83%87%e3%82%b9%e3%83%88%e3%83%a9%e3%82%af%e3%82%bf>#</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>派生する際に上書きします。</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>エラーメッセージを返します。派生する際に上書きします。</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=#メンバ関数>メンバ関数</a><ul><li><a href=#デストラクタ>デストラクタ</a></li><li><a href=#what><code>what</code></a></li></ul></li></ul></li></ul></nav></div></aside></main></body></html>
|
||||
158
ja/docs/reference/find/index.html
Normal file
158
ja/docs/reference/find/index.html
Normal file
@@ -0,0 +1,158 @@
|
||||
<!doctype html><html lang=ja dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content='
|
||||
find.hpp
|
||||
#
|
||||
|
||||
toml::valueから値を検索し、同時に(必要な場合)型変換を行う関数です。
|
||||
|
||||
toml::value は格納する型を変更でき、toml::findはそれらに対応しているので、
|
||||
厳密には全て toml::basic_value<TC> が使われています。ただしこれでは冗長なので、
|
||||
関数の宣言と特に区別しなければならない場合を除いて、簡単のため説明文では toml::value と書きます。
|
||||
説明文では、テンプレートパラメータTCを変更して型が変更されていれば
|
||||
toml::value::integer_type などの型は追従して変更されると解釈してください。
|
||||
|
||||
|
||||
|
||||
toml::find
|
||||
#
|
||||
|
||||
|
||||
概要
|
||||
#
|
||||
|
||||
toml::findには、取り出したい型をテンプレート引数で、検索したい値のキーを引数で与えます。
|
||||
template<typename T, typename TC, typename ... Keys>
|
||||
T find(const basic_value<TC>& v, Keys ... keys);
|
||||
サポートされている T の種類と変換の挙動に関しては、 toml::get と同様です。
|
||||
T が指定されなかった場合、 toml::value が返されます。
|
||||
キーは、 toml::value::key_type または std::size_t です。
|
||||
複数個のキーが与えられた場合は、サブテーブルや配列に対して再帰的に検索が行われます。
|
||||
toml::value::key_type が与えられた場合は toml::table として、 std::size_t が与えられた場合は toml::array として解釈されます。
|
||||
|
||||
再帰的な検索に関しての注意
|
||||
#
|
||||
|
||||
TOMLには通常の bare key の他に、 " や ' で囲まれた quoted key というものがあります。
|
||||
quoted key を使うと、 "foo.bar" = "baz" というようなキーを書くことができ、この場合はサブテーブルは構築されず、キーは foo.barとなります。
|
||||
このようなパターンに対応するため、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/ja/docs/reference/find/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="find.hpp"><meta property="og:description" content='find.hpp # toml::valueから値を検索し、同時に(必要な場合)型変換を行う関数です。
|
||||
toml::value は格納する型を変更でき、toml::findはそれらに対応しているので、 厳密には全て toml::basic_value<TC> が使われています。ただしこれでは冗長なので、 関数の宣言と特に区別しなければならない場合を除いて、簡単のため説明文では toml::value と書きます。 説明文では、テンプレートパラメータTCを変更して型が変更されていれば toml::value::integer_type などの型は追従して変更されると解釈してください。 toml::find # 概要 # toml::findには、取り出したい型をテンプレート引数で、検索したい値のキーを引数で与えます。
|
||||
template<typename T, typename TC, typename ... Keys> T find(const basic_value<TC>& v, Keys ... keys); サポートされている T の種類と変換の挙動に関しては、 toml::get と同様です。
|
||||
T が指定されなかった場合、 toml::value が返されます。
|
||||
キーは、 toml::value::key_type または std::size_t です。 複数個のキーが与えられた場合は、サブテーブルや配列に対して再帰的に検索が行われます。 toml::value::key_type が与えられた場合は toml::table として、 std::size_t が与えられた場合は toml::array として解釈されます。
|
||||
再帰的な検索に関しての注意 # TOMLには通常の bare key の他に、 " や ' で囲まれた quoted key というものがあります。 quoted key を使うと、 "foo.bar" = "baz" というようなキーを書くことができ、この場合はサブテーブルは構築されず、キーは foo.barとなります。 このようなパターンに対応するため、toml11ではキーの中に.が含まれていても分割は行わず、そのままの文字列で検索を行います。'><meta property="og:locale" content="ja"><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/ja/docs/reference/find/><link rel=alternate hreflang=en href=https://toruniina.github.io/toml11/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/ja.search.min.b1a1e3e4be0fdf11fae2bb2370353d99ecd7abea7ccc29273319c021dda76dfd.js integrity="sha256-saHj5L4P3xH64rsjcDU9mezXq+p8zCknMxnAId2nbf0=" 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/ja/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=検索 aria-label=検索 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>
|
||||
日本語</a></label><ul><li><a href=https://toruniina.github.io/toml11/docs/reference/find/>English</a></li></ul></li></ul><ul><li><a href=/toml11/ja/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-b4cfb5b55e913a8d853eacf5e8fba05f class=toggle>
|
||||
<label for=section-b4cfb5b55e913a8d853eacf5e8fba05f class="flex justify-between"><a href=/toml11/ja/docs/features/>features</a></label><ul><li><a href=/toml11/ja/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/ja/docs/features/value/>getting values</a></li><li><a href=/toml11/ja/docs/features/error_message/>error message</a></li><li><a href=/toml11/ja/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/ja/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/ja/docs/features/literal/>toml literal</a></li><li><a href=/toml11/ja/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/ja/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-01b096afc5186aea96713b408b47c967 class=toggle checked>
|
||||
<label for=section-01b096afc5186aea96713b408b47c967 class="flex justify-between"><a href=/toml11/ja/docs/reference/>reference</a></label><ul><li><a href=/toml11/ja/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/ja/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/ja/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/ja/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/ja/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/ja/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/ja/docs/reference/find/ class=active>find.hpp</a></li><li><a href=/toml11/ja/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/ja/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/ja/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/ja/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/ja/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/ja/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/ja/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/ja/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/ja/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/ja/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/ja/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/ja/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/ja/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/ja/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/ja/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/ja/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/ja/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=#概要>概要</a><ul><li><a href=#再帰的な検索に関しての注意>再帰的な検索に関しての注意</a></li></ul></li><li><a href=#tomlfindvalue-key><code>toml::find(value, key)</code></a><ul><li><a href=#例外>例外</a></li></ul></li><li><a href=#tomlfindvalue-index><code>toml::find(value, index)</code></a><ul><li><a href=#例外-1>例外</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=#tがbasic_valueである場合><code>T</code>が<code>basic_value</code>である場合</a></li><li><a href=#tがtomlvaluesome_typeである場合><code>T</code>が<code>toml::value::{some_type}</code>である場合</a></li><li><a href=#tがconst-charである場合><code>T</code>が<code>const char*</code>である場合</a></li><li><a href=#tがその他の型である場合><code>T</code>がその他の型である場合</a></li><li><a href=#複数のキーが与えられた場合>複数のキーが与えられた場合</a></li></ul></li><li><a href=#関連項目>関連項目</a></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=findhpp>find.hpp
|
||||
<a class=anchor href=#findhpp>#</a></h1><p><code>toml::value</code>から値を検索し、同時に(必要な場合)型変換を行う関数です。</p><blockquote class="book-hint info"><code>toml::value</code> は格納する型を変更でき、<code>toml::find</code>はそれらに対応しているので、
|
||||
厳密には全て <code>toml::basic_value<TC></code> が使われています。ただしこれでは冗長なので、
|
||||
関数の宣言と特に区別しなければならない場合を除いて、簡単のため説明文では <code>toml::value</code> と書きます。
|
||||
説明文では、テンプレートパラメータ<code>TC</code>を変更して型が変更されていれば
|
||||
<code>toml::value::integer_type</code> などの型は追従して変更されると解釈してください。</blockquote><h1 id=tomlfind><code>toml::find</code>
|
||||
<a class=anchor href=#tomlfind>#</a></h1><h2 id=概要>概要
|
||||
<a class=anchor href=#%e6%a6%82%e8%a6%81>#</a></h2><p><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><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>サポートされている <code>T</code> の種類と変換の挙動に関しては、 <code>toml::get</code> と同様です。</p><p><code>T</code> が指定されなかった場合、 <code>toml::value</code> が返されます。</p><p>キーは、 <code>toml::value::key_type</code> または <code>std::size_t</code> です。
|
||||
複数個のキーが与えられた場合は、サブテーブルや配列に対して再帰的に検索が行われます。
|
||||
<code>toml::value::key_type</code> が与えられた場合は <code>toml::table</code> として、 <code>std::size_t</code> が与えられた場合は <code>toml::array</code> として解釈されます。</p><h3 id=再帰的な検索に関しての注意>再帰的な検索に関しての注意
|
||||
<a class=anchor href=#%e5%86%8d%e5%b8%b0%e7%9a%84%e3%81%aa%e6%a4%9c%e7%b4%a2%e3%81%ab%e9%96%a2%e3%81%97%e3%81%a6%e3%81%ae%e6%b3%a8%e6%84%8f>#</a></h3><p>TOMLには通常の bare key の他に、 <code>"</code> や <code>'</code> で囲まれた quoted key というものがあります。
|
||||
quoted key を使うと、 <code>"foo.bar" = "baz"</code> というようなキーを書くことができ、この場合はサブテーブルは構築されず、キーは <code>foo.bar</code>となります。
|
||||
このようなパターンに対応するため、toml11ではキーの中に<code>.</code>が含まれていても分割は行わず、そのままの文字列で検索を行います。</p><p>以下の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-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>これに対応する<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><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>参考:<a href=https://toml.io/ja/v1.0.0#%E3%82%AD%E3%83%BC>toml.io/ja/v1.0.0#キー</a></p><h2 id=tomlfindvalue-key><code>toml::find(value, key)</code>
|
||||
<a class=anchor href=#tomlfindvalue-key>#</a></h2><p><code>value</code> を <code>toml::table</code> として <code>key</code> を検索したあと、 <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>/* 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>/* 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>/* 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><code>T</code>が指定されない場合は、変換を行わず<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>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=例外>例外
|
||||
<a class=anchor href=#%e4%be%8b%e5%a4%96>#</a></h3><p><code>toml::value</code> が <code>table</code> を保持していなかった場合、 <code>toml::type_error</code> が送出されます。</p><p>格納している <code>table</code> が指定された要素を持っていなかった場合、 <code>std::out_of_range</code> が送出されます。</p><p>指定された要素が <code>T</code> に変換できない場合 ( <code>toml::get</code> が変換に失敗する場合) 、
|
||||
<code>toml::type_error</code> が送出されます。</p><h2 id=tomlfindvalue-index><code>toml::find(value, index)</code>
|
||||
<a class=anchor href=#tomlfindvalue-index>#</a></h2><p><code>value</code> を <code>toml::array</code> として <code>index</code> 番目にアクセスし、 <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>/* 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>/* 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>/* 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><code>T</code>が指定されない場合は、変換を行わず<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>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=例外-1>例外
|
||||
<a class=anchor href=#%e4%be%8b%e5%a4%96-1>#</a></h3><p><code>toml::value</code> が <code>array</code> を保持していなかった場合、 <code>toml::type_error</code> が送出されます。</p><p>格納している <code>array</code> が指定された数の要素を持っていなかった場合、<code>std::out_of_range</code>が送出されます。</p><p>指定された要素が <code>T</code> に変換できない場合 ( <code>toml::get</code> が変換に失敗する場合) 、
|
||||
<code>toml::type_error</code> が送出されます。</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>/* 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>/* 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>/* 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>再帰的に<code>toml::find</code>が呼び出されます。</p><p>失敗する条件とその際に送出される例外は <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><code>find_or</code> は失敗した際のためのデフォルト値を受け取ることで、失敗時に例外を投げないようにします。</p><p>このデフォルト値は受け取る型<code>T</code>と同じ型でなければなりません。
|
||||
よって、 <code>toml::find<T></code> とは違って、 <code>find_or</code> では <code>T</code> を指定せずとも推論されます。</p><p><code>find_or<T></code>のように <code>T</code> を指定することもできますが、その場合は常に新規な値が返されます。
|
||||
参照を取得したい場合は、 <code>T</code> を指定しないでください。</p><h2 id=tがbasic_valueである場合><code>T</code>が<code>basic_value</code>である場合
|
||||
<a class=anchor href=#t%e3%81%8cbasic_value%e3%81%a7%e3%81%82%e3%82%8b%e5%a0%b4%e5%90%88>#</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>対応する値を検索し、変換せずに返します。変換が必要ないため、参照を返すことができます。</p><p>値が見つからなかった場合、デフォルト値を返します。</p><h2 id=tがtomlvaluesome_typeである場合><code>T</code>が<code>toml::value::{some_type}</code>である場合
|
||||
<a class=anchor href=#t%e3%81%8ctomlvaluesome_type%e3%81%a7%e3%81%82%e3%82%8b%e5%a0%b4%e5%90%88>#</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>対応する値を検索し、変換せずに返します。変換が必要ないため、参照を返すことができます。</p><p>値が見つからなかった場合、あるいは異なる型が格納されていた場合、デフォルト値を返します。</p><h2 id=tがconst-charである場合><code>T</code>が<code>const char*</code>である場合
|
||||
<a class=anchor href=#t%e3%81%8cconst-char%e3%81%a7%e3%81%82%e3%82%8b%e5%a0%b4%e5%90%88>#</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>std<span style=color:#f92672>::</span>string 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> k, <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>char</span><span style=color:#f92672>*</span> opt)
|
||||
</span></span></code></pre></div><p>対応する値を検索し、 <code>std::string</code> として返します。</p><p>失敗時に <code>const char*</code> から <code>std::string</code> を構築するため、参照を返すことはできません。</p><h2 id=tがその他の型である場合><code>T</code>がその他の型である場合
|
||||
<a class=anchor href=#t%e3%81%8c%e3%81%9d%e3%81%ae%e4%bb%96%e3%81%ae%e5%9e%8b%e3%81%a7%e3%81%82%e3%82%8b%e5%a0%b4%e5%90%88>#</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>対応する値を検索し、 <code>T</code> に変換して返します。</p><p>変換を行うため、参照を返すことはできません。</p><h2 id=複数のキーが与えられた場合>複数のキーが与えられた場合
|
||||
<a class=anchor href=#%e8%a4%87%e6%95%b0%e3%81%ae%e3%82%ad%e3%83%bc%e3%81%8c%e4%b8%8e%e3%81%88%e3%82%89%e3%82%8c%e3%81%9f%e5%a0%b4%e5%90%88>#</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>キーの列の最後の要素がデフォルト値であると解釈して、再帰的に<code>find_or</code>を適用します。</p><p><code>T</code> の推論結果が <code>toml::value</code> または <code>toml::value::some_type</code> になる場合、参照を返すことができます。</p><p><code>T</code> を明示的に指定した場合、常に変換を行います。</p><h1 id=関連項目>関連項目
|
||||
<a class=anchor href=#%e9%96%a2%e9%80%a3%e9%a0%85%e7%9b%ae>#</a></h1><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/reference/get/>get.hpp</a></li><li><a href=https://toruniina.github.io/toml11/ja/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=#概要>概要</a><ul><li><a href=#再帰的な検索に関しての注意>再帰的な検索に関しての注意</a></li></ul></li><li><a href=#tomlfindvalue-key><code>toml::find(value, key)</code></a><ul><li><a href=#例外>例外</a></li></ul></li><li><a href=#tomlfindvalue-index><code>toml::find(value, index)</code></a><ul><li><a href=#例外-1>例外</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=#tがbasic_valueである場合><code>T</code>が<code>basic_value</code>である場合</a></li><li><a href=#tがtomlvaluesome_typeである場合><code>T</code>が<code>toml::value::{some_type}</code>である場合</a></li><li><a href=#tがconst-charである場合><code>T</code>が<code>const char*</code>である場合</a></li><li><a href=#tがその他の型である場合><code>T</code>がその他の型である場合</a></li><li><a href=#複数のキーが与えられた場合>複数のキーが与えられた場合</a></li></ul></li><li><a href=#関連項目>関連項目</a></li></ul></nav></div></aside></main></body></html>
|
||||
458
ja/docs/reference/format/index.html
Normal file
458
ja/docs/reference/format/index.html
Normal file
File diff suppressed because one or more lines are too long
92
ja/docs/reference/from/index.html
Normal file
92
ja/docs/reference/from/index.html
Normal file
@@ -0,0 +1,92 @@
|
||||
<!doctype html><html lang=ja dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content='
|
||||
from.hpp
|
||||
#
|
||||
|
||||
toml::getやtoml::findで使用する、toml::valueからの変換を定義する構造体です。
|
||||
メンバ関数にfrom_tomlを追加することによっても同じ機能を追加できますが、メンバ関数を追加できないクラスに対してはfrom<T>を使用してください。
|
||||
このファイルでは特定の実装は提供しません。使用する際に、この構造体を特殊化してください。
|
||||
namespace toml
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
struct from;
|
||||
|
||||
} // toml
|
||||
|
||||
例
|
||||
#
|
||||
|
||||
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
|
||||
|
||||
関連項目
|
||||
#
|
||||
|
||||
|
||||
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/ja/docs/reference/from/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="from.hpp"><meta property="og:description" content='from.hpp # toml::getやtoml::findで使用する、toml::valueからの変換を定義する構造体です。
|
||||
メンバ関数にfrom_tomlを追加することによっても同じ機能を追加できますが、メンバ関数を追加できないクラスに対してはfrom<T>を使用してください。
|
||||
このファイルでは特定の実装は提供しません。使用する際に、この構造体を特殊化してください。
|
||||
namespace toml { template<typename T> struct from; } // toml 例 # 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 関連項目 # conversion.hpp into.hpp'><meta property="og:locale" content="ja"><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/ja/docs/reference/from/><link rel=alternate hreflang=en href=https://toruniina.github.io/toml11/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/ja.search.min.b1a1e3e4be0fdf11fae2bb2370353d99ecd7abea7ccc29273319c021dda76dfd.js integrity="sha256-saHj5L4P3xH64rsjcDU9mezXq+p8zCknMxnAId2nbf0=" 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/ja/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=検索 aria-label=検索 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>
|
||||
日本語</a></label><ul><li><a href=https://toruniina.github.io/toml11/docs/reference/from/>English</a></li></ul></li></ul><ul><li><a href=/toml11/ja/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-b4cfb5b55e913a8d853eacf5e8fba05f class=toggle>
|
||||
<label for=section-b4cfb5b55e913a8d853eacf5e8fba05f class="flex justify-between"><a href=/toml11/ja/docs/features/>features</a></label><ul><li><a href=/toml11/ja/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/ja/docs/features/value/>getting values</a></li><li><a href=/toml11/ja/docs/features/error_message/>error message</a></li><li><a href=/toml11/ja/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/ja/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/ja/docs/features/literal/>toml literal</a></li><li><a href=/toml11/ja/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/ja/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-01b096afc5186aea96713b408b47c967 class=toggle checked>
|
||||
<label for=section-01b096afc5186aea96713b408b47c967 class="flex justify-between"><a href=/toml11/ja/docs/reference/>reference</a></label><ul><li><a href=/toml11/ja/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/ja/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/ja/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/ja/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/ja/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/ja/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/ja/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/ja/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/ja/docs/reference/from/ class=active>from.hpp</a></li><li><a href=/toml11/ja/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/ja/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/ja/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/ja/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/ja/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/ja/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/ja/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/ja/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/ja/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/ja/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/ja/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/ja/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/ja/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/ja/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/ja/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=#例>例</a></li></ul></li><li><a href=#関連項目>関連項目</a></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=fromhpp>from.hpp
|
||||
<a class=anchor href=#fromhpp>#</a></h1><p><code>toml::get</code>や<code>toml::find</code>で使用する、<code>toml::value</code>からの変換を定義する構造体です。</p><p>メンバ関数に<code>from_toml</code>を追加することによっても同じ機能を追加できますが、メンバ関数を追加できないクラスに対しては<code>from<T></code>を使用してください。</p><p>このファイルでは特定の実装は提供しません。使用する際に、この構造体を特殊化してください。</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=例>例
|
||||
<a class=anchor href=#%e4%be%8b>#</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=関連項目>関連項目
|
||||
<a class=anchor href=#%e9%96%a2%e9%80%a3%e9%a0%85%e7%9b%ae>#</a></h1><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/reference/conversion/>conversion.hpp</a></li><li><a href=https://toruniina.github.io/toml11/ja/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=#例>例</a></li></ul></li><li><a href=#関連項目>関連項目</a></li></ul></nav></div></aside></main></body></html>
|
||||
195
ja/docs/reference/get/index.html
Normal file
195
ja/docs/reference/get/index.html
Normal file
@@ -0,0 +1,195 @@
|
||||
<!doctype html><html lang=ja dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
|
||||
get.hpp
|
||||
#
|
||||
|
||||
toml::valueから値を取り出し、同時に(必要な場合)型変換を行う関数です。
|
||||
|
||||
toml::value は格納する型を変更でき、toml::getはそれらに対応しているので、
|
||||
厳密には全て toml::basic_value<TC> が使われています。ただしこれでは冗長なので、
|
||||
関数の宣言と特に区別しなければならない場合を除いて、簡単のため説明文では toml::value と書きます。
|
||||
説明文では、テンプレートパラメータTCを変更して型が変更されていれば
|
||||
toml::value::integer_type などの型は追従して変更されると解釈してください。
|
||||
|
||||
|
||||
|
||||
toml::get<T>
|
||||
#
|
||||
|
||||
|
||||
概要
|
||||
#
|
||||
|
||||
基本的に、toml::getは以下のような関数として振る舞います。
|
||||
Tはtoml::get<int>(v)のようにして与えます。
|
||||
template<typename T, typename TC>
|
||||
T get(const basic_value<TC>& v);
|
||||
ただし、Tがどのような型であるかによって、toml::getは異なる挙動をします。
|
||||
Tの型の種類は、
|
||||
|
||||
変換が必要ない型
|
||||
変換する必要がある型
|
||||
|
||||
に分けられます。
|
||||
細かい条件と、特別にサポートしている具体的な型については後述します。
|
||||
|
||||
変換が必要ない型
|
||||
#
|
||||
|
||||
変換が必要ないのは、渡された toml::value が格納している型です。
|
||||
例えば、 toml::value::integer_type は std::int64_t のエイリアスなので、
|
||||
toml::get<std::int64_t>(v) は変換を必要としません。
|
||||
この場合、 toml:get は integer の値を toml::value から取り出し、その参照を返します。
|
||||
渡されたtoml::valueが可変参照(&)である場合、返す値も可変参照(&)です。
|
||||
不変参照(const&)の場合、返す値も不変参照(const&)となります。
|
||||
可変参照を返した場合、その参照を通してtoml::valueに格納されている値に上書きできます。
|
||||
|
||||
変換が必要な型
|
||||
#
|
||||
|
||||
上記の型以外については変換が必要です。
|
||||
例えば、toml::value::integer_typeはstd::int64_tのエイリアスなので、toml::get<std::size_t>(toml::value&)は変換が必要です。
|
||||
この場合、toml:getはintegerの値をtoml::valueから取り出し、それをキャストして返します。
|
||||
toml11は簡単なキャストだけでなく、
|
||||
toml::arrayからやstd::tuple<int, double, std::string>やstd::array<double, 4>、
|
||||
toml::tableからstd::map<std::string, int>などの複雑な型変換をサポートします。
|
||||
具体的には、続くセクションを参照してください。"><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/ja/docs/reference/get/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="get.hpp"><meta property="og:description" content="get.hpp # toml::valueから値を取り出し、同時に(必要な場合)型変換を行う関数です。
|
||||
toml::value は格納する型を変更でき、toml::getはそれらに対応しているので、 厳密には全て toml::basic_value<TC> が使われています。ただしこれでは冗長なので、 関数の宣言と特に区別しなければならない場合を除いて、簡単のため説明文では toml::value と書きます。 説明文では、テンプレートパラメータTCを変更して型が変更されていれば toml::value::integer_type などの型は追従して変更されると解釈してください。 toml::get<T> # 概要 # 基本的に、toml::getは以下のような関数として振る舞います。 Tはtoml::get<int>(v)のようにして与えます。
|
||||
template<typename T, typename TC> T get(const basic_value<TC>& v); ただし、Tがどのような型であるかによって、toml::getは異なる挙動をします。
|
||||
Tの型の種類は、
|
||||
変換が必要ない型 変換する必要がある型 に分けられます。
|
||||
細かい条件と、特別にサポートしている具体的な型については後述します。
|
||||
変換が必要ない型 # 変換が必要ないのは、渡された toml::value が格納している型です。 例えば、 toml::value::integer_type は std::int64_t のエイリアスなので、 toml::get<std::int64_t>(v) は変換を必要としません。 この場合、 toml:get は integer の値を toml::value から取り出し、その参照を返します。
|
||||
渡されたtoml::valueが可変参照(&)である場合、返す値も可変参照(&)です。 不変参照(const&)の場合、返す値も不変参照(const&)となります。 可変参照を返した場合、その参照を通してtoml::valueに格納されている値に上書きできます。
|
||||
変換が必要な型 # 上記の型以外については変換が必要です。 例えば、toml::value::integer_typeはstd::int64_tのエイリアスなので、toml::get<std::size_t>(toml::value&)は変換が必要です。 この場合、toml:getはintegerの値をtoml::valueから取り出し、それをキャストして返します。
|
||||
toml11は簡単なキャストだけでなく、 toml::arrayからやstd::tuple<int, double, std::string>やstd::array<double, 4>、 toml::tableからstd::map<std::string, int>などの複雑な型変換をサポートします。 具体的には、続くセクションを参照してください。"><meta property="og:locale" content="ja"><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/ja/docs/reference/get/><link rel=alternate hreflang=en href=https://toruniina.github.io/toml11/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/ja.search.min.b1a1e3e4be0fdf11fae2bb2370353d99ecd7abea7ccc29273319c021dda76dfd.js integrity="sha256-saHj5L4P3xH64rsjcDU9mezXq+p8zCknMxnAId2nbf0=" 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/ja/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=検索 aria-label=検索 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>
|
||||
日本語</a></label><ul><li><a href=https://toruniina.github.io/toml11/docs/reference/get/>English</a></li></ul></li></ul><ul><li><a href=/toml11/ja/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-b4cfb5b55e913a8d853eacf5e8fba05f class=toggle>
|
||||
<label for=section-b4cfb5b55e913a8d853eacf5e8fba05f class="flex justify-between"><a href=/toml11/ja/docs/features/>features</a></label><ul><li><a href=/toml11/ja/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/ja/docs/features/value/>getting values</a></li><li><a href=/toml11/ja/docs/features/error_message/>error message</a></li><li><a href=/toml11/ja/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/ja/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/ja/docs/features/literal/>toml literal</a></li><li><a href=/toml11/ja/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/ja/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-01b096afc5186aea96713b408b47c967 class=toggle checked>
|
||||
<label for=section-01b096afc5186aea96713b408b47c967 class="flex justify-between"><a href=/toml11/ja/docs/reference/>reference</a></label><ul><li><a href=/toml11/ja/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/ja/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/ja/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/ja/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/ja/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/ja/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/ja/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/ja/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/ja/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/ja/docs/reference/get/ class=active>get.hpp</a></li><li><a href=/toml11/ja/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/ja/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/ja/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/ja/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/ja/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/ja/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/ja/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/ja/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/ja/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/ja/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/ja/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/ja/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/ja/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/ja/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=#概要>概要</a><ul><li><a href=#変換が必要ない型>変換が必要ない型</a></li><li><a href=#変換が必要な型>変換が必要な型</a></li><li><a href=#失敗した場合>失敗した場合</a></li></ul></li><li><a href=#tがtomlvalueと同一のとき><code>T</code>が<code>toml::value</code>と同一のとき</a></li><li><a href=#tがtomlvaluesome_typeのいずれかのとき><code>T</code>が<code>toml::value::{some_type}</code>のいずれかのとき</a></li><li><a href=#tが異なるtypeconfigを持つbasic_valueothertcのとき><code>T</code>が異なる<code>TypeConfig</code>を持つ<code>basic_value<OtherTC></code>のとき</a></li><li><a href=#tが整数型の場合><code>T</code>が整数型の場合</a></li><li><a href=#tが浮動小数点数型の場合><code>T</code>が浮動小数点数型の場合</a></li><li><a href=#tがstdstring_viewの場合><code>T</code>が<code>std::string_view</code>の場合</a></li><li><a href=#tがstdchronodurationの場合><code>T</code>が<code>std::chrono::duration</code>の場合</a></li><li><a href=#tがstdchronosystem_clocktime_pointの場合><code>T</code>が<code>std::chrono::system_clock::time_point</code>の場合</a></li><li><a href=#tがarray-likeである場合><code>T</code>が<code>array-like</code>である場合</a></li><li><a href=#tがstdarrayである場合><code>T</code>が<code>std::array</code>である場合</a></li><li><a href=#tがstdforward_listである場合><code>T</code>が<code>std::forward_list</code>である場合</a></li><li><a href=#tがstdpairである場合><code>T</code>が<code>std::pair</code>である場合</a></li><li><a href=#tがstdtupleである場合><code>T</code>が<code>std::tuple</code>である場合</a></li><li><a href=#tがmap-likeである場合><code>T</code>が<code>map-like</code>である場合</a></li><li><a href=#tがtomlfromtの特殊化を持つユーザー定義型である場合><code>T</code>が<code>toml::from<T></code>の特殊化を持つユーザー定義型である場合</a></li><li><a href=#tがtfrom_tomlメンバ関数を持つユーザー定義型である場合><code>T</code>が<code>T::from_toml</code>メンバ関数を持つユーザー定義型である場合</a></li><li><a href=#tがtomlbasic_valuetcを取るコンストラクタを持つユーザー定義型である場合><code>T</code>が<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=#tがbasic_valuetcである場合><code>T</code>が<code>basic_value<TC></code>である場合</a></li><li><a href=#tがbasic_valuetcsome_typeである場合><code>T</code>が<code>basic_value<TC>::{some_type}</code>である場合</a></li><li><a href=#tがconst-charである場合><code>T</code>が<code>const char*</code>である場合</a></li><li><a href=#tがその他の場合><code>T</code>がその他の場合</a></li></ul></li><li><a href=#関連項目>関連項目</a></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=gethpp>get.hpp
|
||||
<a class=anchor href=#gethpp>#</a></h1><p><code>toml::value</code>から値を取り出し、同時に(必要な場合)型変換を行う関数です。</p><blockquote class="book-hint info"><code>toml::value</code> は格納する型を変更でき、<code>toml::get</code>はそれらに対応しているので、
|
||||
厳密には全て <code>toml::basic_value<TC></code> が使われています。ただしこれでは冗長なので、
|
||||
関数の宣言と特に区別しなければならない場合を除いて、簡単のため説明文では <code>toml::value</code> と書きます。
|
||||
説明文では、テンプレートパラメータ<code>TC</code>を変更して型が変更されていれば
|
||||
<code>toml::value::integer_type</code> などの型は追従して変更されると解釈してください。</blockquote><h1 id=tomlgett><code>toml::get<T></code>
|
||||
<a class=anchor href=#tomlgett>#</a></h1><h2 id=概要>概要
|
||||
<a class=anchor href=#%e6%a6%82%e8%a6%81>#</a></h2><p>基本的に、<code>toml::get</code>は以下のような関数として振る舞います。
|
||||
<code>T</code>は<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>ただし、<code>T</code>がどのような型であるかによって、<code>toml::get</code>は異なる挙動をします。</p><p><code>T</code>の型の種類は、</p><ol><li>変換が必要ない型</li><li>変換する必要がある型</li></ol><p>に分けられます。</p><p>細かい条件と、特別にサポートしている具体的な型については後述します。</p><h3 id=変換が必要ない型>変換が必要ない型
|
||||
<a class=anchor href=#%e5%a4%89%e6%8f%9b%e3%81%8c%e5%bf%85%e8%a6%81%e3%81%aa%e3%81%84%e5%9e%8b>#</a></h3><p>変換が必要ないのは、渡された <code>toml::value</code> が格納している型です。
|
||||
例えば、 <code>toml::value::integer_type</code> は <code>std::int64_t</code> のエイリアスなので、
|
||||
<code>toml::get<std::int64_t>(v)</code> は変換を必要としません。
|
||||
この場合、 <code>toml:get</code> は <code>integer</code> の値を <code>toml::value</code> から取り出し、その参照を返します。</p><p>渡された<code>toml::value</code>が可変参照(<code>&</code>)である場合、返す値も可変参照(<code>&</code>)です。
|
||||
不変参照(<code>const&</code>)の場合、返す値も不変参照(<code>const&</code>)となります。
|
||||
可変参照を返した場合、その参照を通して<code>toml::value</code>に格納されている値に上書きできます。</p><h3 id=変換が必要な型>変換が必要な型
|
||||
<a class=anchor href=#%e5%a4%89%e6%8f%9b%e3%81%8c%e5%bf%85%e8%a6%81%e3%81%aa%e5%9e%8b>#</a></h3><p>上記の型以外については変換が必要です。
|
||||
例えば、<code>toml::value::integer_type</code>は<code>std::int64_t</code>のエイリアスなので、<code>toml::get<std::size_t>(toml::value&)</code>は変換が必要です。
|
||||
この場合、<code>toml:get</code>は<code>integer</code>の値を<code>toml::value</code>から取り出し、それをキャストして返します。</p><p>toml11は簡単なキャストだけでなく、
|
||||
<code>toml::array</code>からや<code>std::tuple<int, double, std::string></code>や<code>std::array<double, 4></code>、
|
||||
<code>toml::table</code>から<code>std::map<std::string, int></code>などの複雑な型変換をサポートします。
|
||||
具体的には、続くセクションを参照してください。</p><h3 id=失敗した場合>失敗した場合
|
||||
<a class=anchor href=#%e5%a4%b1%e6%95%97%e3%81%97%e3%81%9f%e5%a0%b4%e5%90%88>#</a></h3><p>期待した型変換を行えない場合があります。例えば、<code>table</code>を持っている<code>toml::value</code>に<code>toml::get<int>(v)</code>を適用した場合などです。</p><p>このような場合は、取り出そうとした型に最も似ている型への変換(今回は<code>int</code>なので、<code>as_integer</code>)が失敗したとして、<code>toml::type_error</code>が送出されます。</p><p>ファイルからパースした場合、以下のようなエラーメッセージが出力されます。</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=tがtomlvalueと同一のとき><code>T</code>が<code>toml::value</code>と同一のとき
|
||||
<a class=anchor href=#t%e3%81%8ctomlvalue%e3%81%a8%e5%90%8c%e4%b8%80%e3%81%ae%e3%81%a8%e3%81%8d>#</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> 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>条件:</p><ul><li><code>std::is_same<T, basic_value<TC>></code> を満たす</li></ul><p><code>toml::value</code>から<code>toml::value</code>なので、変換は行われず、そのままの値が返されます。
|
||||
他の関数の実装を一般化するためだけに存在しています。</p><p>失敗しません。</p><h2 id=tがtomlvaluesome_typeのいずれかのとき><code>T</code>が<code>toml::value::{some_type}</code>のいずれかのとき
|
||||
<a class=anchor href=#t%e3%81%8ctomlvaluesome_type%e3%81%ae%e3%81%84%e3%81%9a%e3%82%8c%e3%81%8b%e3%81%ae%e3%81%a8%e3%81%8d>#</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>条件:</p><ul><li><code>T</code>が<code>toml::value</code>が格納できる型(<code>toml::value::boolean_type</code>など)のどれかと同一であること</li></ul><p><code>toml::value</code> が格納している型と同じ型、例えば <code>toml::value::integer_type</code> が
|
||||
<code>toml::get<T></code> の <code>T</code> として指定されたとき、型変換の必要がないため参照を返すことが可能です。</p><p>異なる型が格納されていた場合、<code>toml::type_error</code> が送出されます。</p><h2 id=tが異なるtypeconfigを持つbasic_valueothertcのとき><code>T</code>が異なる<code>TypeConfig</code>を持つ<code>basic_value<OtherTC></code>のとき
|
||||
<a class=anchor href=#t%e3%81%8c%e7%95%b0%e3%81%aa%e3%82%8btypeconfig%e3%82%92%e6%8c%81%e3%81%a4basic_valueothertc%e3%81%ae%e3%81%a8%e3%81%8d>#</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>条件:</p><ul><li><code>T</code>が<code>toml::basic_value<TC></code>ではない</li><li><code>T</code>が<code>toml::basic_value<OtherTC></code>である</li></ul><p>異なる型を格納し得る<code>basic_value</code>が指定された場合、変換が行われます。</p><p>型変換が発生するので、返す値は新規な値であり、参照ではありません。</p><p>失敗しません(メモリ枯渇などの場合を除く)。</p><h2 id=tが整数型の場合><code>T</code>が整数型の場合
|
||||
<a class=anchor href=#t%e3%81%8c%e6%95%b4%e6%95%b0%e5%9e%8b%e3%81%ae%e5%a0%b4%e5%90%88>#</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>条件:</p><ul><li><code>std::is_integral<T></code> を満たす</li><li><code>std::is_same<T, bool></code> ではない</li><li><code>toml::value::integer_type</code> ではない</li></ul><p><code>toml::value</code> を <code>integer_type</code> を保持しているとしてその値を取得し、それを <code>T</code> に変換して返します。</p><p><code>toml::value::integer_type</code> 以外の型が格納されていた場合、 <code>toml::type_error</code> が送出されます。</p><h2 id=tが浮動小数点数型の場合><code>T</code>が浮動小数点数型の場合
|
||||
<a class=anchor href=#t%e3%81%8c%e6%b5%ae%e5%8b%95%e5%b0%8f%e6%95%b0%e7%82%b9%e6%95%b0%e5%9e%8b%e3%81%ae%e5%a0%b4%e5%90%88>#</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>条件:</p><ul><li><code>std::is_floating_point<T></code> を満たす</li><li><code>toml::value::floating_type</code> ではない</li></ul><p><code>toml::value</code>を<code>floating_type</code>を保持しているとしてその値を取得し、それを<code>T</code>に変換して返します。</p><p><code>toml::value::floating_type</code> 以外の型が格納されていた場合、 <code>toml::type_error</code> が送出されます。</p><h2 id=tがstdstring_viewの場合><code>T</code>が<code>std::string_view</code>の場合
|
||||
<a class=anchor href=#t%e3%81%8cstdstring_view%e3%81%ae%e5%a0%b4%e5%90%88>#</a></h2><p>C++17以降でのみ使用可能です。</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>条件:</p><ul><li><code>std::is_same<std::string_view, T></code> を満たす</li></ul><p><code>toml::value</code>を<code>string_type</code>を保持しているとしてその値を取得し、それから<code>std::string_view</code>を構築して返します。</p><p><code>toml::value::string_type</code> 以外の型が格納されていた場合、 <code>toml::type_error</code> が送出されます。</p><h2 id=tがstdchronodurationの場合><code>T</code>が<code>std::chrono::duration</code>の場合
|
||||
<a class=anchor href=#t%e3%81%8cstdchronoduration%e3%81%ae%e5%a0%b4%e5%90%88>#</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>条件:</p><ul><li><code>T</code>が<code>std::chrono::duration<Rep, Period></code>である</li></ul><p><code>toml::value</code>を<code>local_time</code>を保持しているとしてその値を取得し、それを<code>std::chrono::duration</code>に変換して返します。</p><p><code>toml::value::local_time</code> 以外の型が格納されていた場合、 <code>toml::type_error</code> が送出されます。</p><h2 id=tがstdchronosystem_clocktime_pointの場合><code>T</code>が<code>std::chrono::system_clock::time_point</code>の場合
|
||||
<a class=anchor href=#t%e3%81%8cstdchronosystem_clocktime_point%e3%81%ae%e5%a0%b4%e5%90%88>#</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>条件:</p><ul><li><code>std::is_same<T, std::chrono::system_clock::time_point></code>を満たす</li></ul><p><code>toml::value</code> を <code>local_date</code>, <code>local_datetime</code>, <code>offset_datetime</code>のどれかを保持しているとしてその値を取得し、それを<code>std::chrono::system_clock::time_point</code>に変換して返します。</p><p><code>local_date</code>, <code>local_datetime</code>, <code>offset_datetime</code> 以外の型が格納されていた場合、 <code>toml::type_error</code> が送出されます。</p><h2 id=tがarray-likeである場合><code>T</code>が<code>array-like</code>である場合
|
||||
<a class=anchor href=#t%e3%81%8carray-like%e3%81%a7%e3%81%82%e3%82%8b%e5%a0%b4%e5%90%88>#</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>条件:</p><ul><li><code>T</code>は<code>T::iterator</code>を持つ</li><li><code>T</code>は<code>T::value_type</code>を持つ</li><li><code>T</code>は<code>T::push_back(x)</code>を持つ</li><li><code>T</code>は<code>toml::value::array_type</code>ではない</li><li><code>T</code>は<code>std::string</code>ではない</li><li><code>T</code>は<code>std::string_view</code>ではない</li><li><code>T</code>は<code>map-like</code>ではない</li><li><code>T</code>は<code>from_toml()</code>メンバ関数を持たない</li><li><code>toml::from<T></code>が定義されていない</li><li><code>toml::basic_value<TC></code>からのコンストラクタが定義されていない</li></ul><p><code>std::vector<int></code>や<code>std::deque<std::string></code>などが該当します。</p><p><code>toml::value</code>を<code>array</code>を保持しているとしてその値を取得し、それを指定されたコンテナに変換して返します。</p><p><code>toml::value::array_type</code> 以外の型が格納されていた場合、 <code>toml::type_error</code> が送出されます。</p><h2 id=tがstdarrayである場合><code>T</code>が<code>std::array</code>である場合
|
||||
<a class=anchor href=#t%e3%81%8cstdarray%e3%81%a7%e3%81%82%e3%82%8b%e5%a0%b4%e5%90%88>#</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>条件:</p><ul><li><code>T</code>は<code>std::array<U, N></code>である</li></ul><p><code>toml::value</code>を<code>array</code>を保持しているとしてその値を取得し、それを指定されたコンテナに変換して返します。</p><p><code>toml::value::array_type</code> 以外の型が格納されていた場合、 <code>toml::type_error</code> が送出されます。</p><p><code>toml::value</code> が持つ <code>array</code> が十分な数の要素を持っていなかった場合、<code>std::out_of_range</code>が送出されます。</p><h2 id=tがstdforward_listである場合><code>T</code>が<code>std::forward_list</code>である場合
|
||||
<a class=anchor href=#t%e3%81%8cstdforward_list%e3%81%a7%e3%81%82%e3%82%8b%e5%a0%b4%e5%90%88>#</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>条件:</p><ul><li><code>T</code>は<code>std::forward_list<U></code>である</li></ul><p><code>toml::value</code>を<code>array</code>を保持しているとしてその値を取得し、それを<code>std::forward_list</code>に変換して返します。</p><p><code>toml::value::array_type</code> 以外の型が格納されていた場合、 <code>toml::type_error</code> が送出されます。</p><p><code>forward_list</code>は<code>push_back</code>を持たないので、別に実装されています。</p><h2 id=tがstdpairである場合><code>T</code>が<code>std::pair</code>である場合
|
||||
<a class=anchor href=#t%e3%81%8cstdpair%e3%81%a7%e3%81%82%e3%82%8b%e5%a0%b4%e5%90%88>#</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>条件:</p><ul><li><code>T</code>は<code>std::pair<T1, T2></code>である</li></ul><p><code>toml::value</code>を<code>array</code>を保持しているとしてその値を取得し、それを<code>std::pair<T1, T2></code>に変換して返します。</p><p><code>first</code> と <code>second</code> はそれぞれ再帰的に変換されます。</p><p><code>toml::value::array_type</code> 以外の型が格納されていた場合、 <code>toml::type_error</code> が送出されます。</p><p><code>toml::value</code> が持つ <code>array</code> の要素数がちょうど2個でなかった場合、<code>std::out_of_range</code>が送出されます。</p><h2 id=tがstdtupleである場合><code>T</code>が<code>std::tuple</code>である場合
|
||||
<a class=anchor href=#t%e3%81%8cstdtuple%e3%81%a7%e3%81%82%e3%82%8b%e5%a0%b4%e5%90%88>#</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>条件:</p><ul><li><code>T</code>は<code>std::tuple<T1, T2, ... TN></code>である</li></ul><p><code>toml::value</code>を<code>array</code>を保持しているとしてその値を取得し、それを<code>std::tuple<T1, T2, ...TN></code>に変換して返します。</p><p>各要素はそれぞれ再帰的に変換されます。</p><p><code>toml::value::array_type</code> 以外の型が格納されていた場合、 <code>toml::type_error</code> が送出されます。</p><p><code>toml::value</code> が持つ <code>array</code> の要素数がちょうど <code>std::tuple_size<T>::value</code> 個でなかった場合、<code>std::out_of_range</code>が送出されます。</p><h2 id=tがmap-likeである場合><code>T</code>が<code>map-like</code>である場合
|
||||
<a class=anchor href=#t%e3%81%8cmap-like%e3%81%a7%e3%81%82%e3%82%8b%e5%a0%b4%e5%90%88>#</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>条件:</p><ul><li><code>T</code>は<code>T::iterator</code>を持つ</li><li><code>T</code>は<code>T::key_type</code>を持つ</li><li><code>T</code>は<code>T::value_type</code>を持つ</li><li><code>T</code>は<code>T::mapped_type</code>を持つ</li><li><code>T</code>は<code>toml::value::table_type</code>ではない</li><li><code>T</code>は<code>from_toml()</code>メンバ関数を持たない</li><li><code>toml::from<T></code>が定義されていない</li><li><code>toml::basic_value<TC></code>からのコンストラクタが定義されていない</li></ul><p><code>std::map<std::string, int></code>や<code>std::unordered_map<std::string, float></code>などが該当します。</p><p><code>toml::value</code>を<code>table</code>を保持しているとしてその値を取得し、それを <code>T</code> に変換して返します。</p><p>各要素はそれぞれ再帰的に変換されます。</p><p><code>basic_value::table_type</code> 以外の型が格納されていた場合、 <code>toml::type_error</code> が送出されます。</p><h2 id=tがtomlfromtの特殊化を持つユーザー定義型である場合><code>T</code>が<code>toml::from<T></code>の特殊化を持つユーザー定義型である場合
|
||||
<a class=anchor href=#t%e3%81%8ctomlfromt%e3%81%ae%e7%89%b9%e6%ae%8a%e5%8c%96%e3%82%92%e6%8c%81%e3%81%a4%e3%83%a6%e3%83%bc%e3%82%b6%e3%83%bc%e5%ae%9a%e7%be%a9%e5%9e%8b%e3%81%a7%e3%81%82%e3%82%8b%e5%a0%b4%e5%90%88>#</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>条件:</p><ul><li><code>toml::from<T></code>が定義されている</li></ul><p><code>toml::from</code> の <code>T</code> に対する特殊化が定義されていた場合、それを使用した型変換が行われます。</p><p>個別にサポートされる型( <code>std::array</code>, <code>std::pair</code>, <code>std::tuple</code> )と衝突しないようにしてください。</p><h2 id=tがtfrom_tomlメンバ関数を持つユーザー定義型である場合><code>T</code>が<code>T::from_toml</code>メンバ関数を持つユーザー定義型である場合
|
||||
<a class=anchor href=#t%e3%81%8ctfrom_toml%e3%83%a1%e3%83%b3%e3%83%90%e9%96%a2%e6%95%b0%e3%82%92%e6%8c%81%e3%81%a4%e3%83%a6%e3%83%bc%e3%82%b6%e3%83%bc%e5%ae%9a%e7%be%a9%e5%9e%8b%e3%81%a7%e3%81%82%e3%82%8b%e5%a0%b4%e5%90%88>#</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>条件:</p><ul><li><code>toml::from<T></code>が定義されていない</li><li><code>T</code>は<code>from_toml()</code>メンバ関数を持つ</li></ul><p><code>T</code> に <code>from_toml(toml::basic_value<TC>)</code> メンバ関数が定義されていた場合、それを使用した型変換が行われます。</p><p><code>toml::from<T></code> が定義されていると、そちらが優先されます。</p><h2 id=tがtomlbasic_valuetcを取るコンストラクタを持つユーザー定義型である場合><code>T</code>が<code>toml::basic_value<TC></code>を取るコンストラクタを持つユーザー定義型である場合
|
||||
<a class=anchor href=#t%e3%81%8ctomlbasic_valuetc%e3%82%92%e5%8f%96%e3%82%8b%e3%82%b3%e3%83%b3%e3%82%b9%e3%83%88%e3%83%a9%e3%82%af%e3%82%bf%e3%82%92%e6%8c%81%e3%81%a4%e3%83%a6%e3%83%bc%e3%82%b6%e3%83%bc%e5%ae%9a%e7%be%a9%e5%9e%8b%e3%81%a7%e3%81%82%e3%82%8b%e5%a0%b4%e5%90%88>#</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>条件:</p><ul><li><code>toml::from<T></code>が定義されていない</li><li><code>T</code>は<code>from_toml()</code>メンバ関数を持たない</li><li><code>T</code>は<code>toml::basic_value<TC></code>を取るコンストラクタを持つ</li></ul><p><code>T</code> に <code>toml::basic_value<TC></code> を取るコンストラクタが定義されていた場合、それを使用した型変換が行われます。</p><p><code>toml::from<T></code> または <code>T::from_toml</code> が定義されていると、そちらが優先されます。</p><h1 id=tomlget_ort><code>toml::get_or<T></code>
|
||||
<a class=anchor href=#tomlget_ort>#</a></h1><p><code>get_or</code> は失敗した際のためのデフォルト値を受け取ることで、失敗時に例外を投げないようにします。</p><p>このデフォルト値は受け取る型<code>T</code>と同じ型でなければなりません。
|
||||
よって、 <code>toml::get<T></code> とは違って、 <code>get_or</code> では <code>T</code> を指定せずとも推論されます。</p><h2 id=tがbasic_valuetcである場合><code>T</code>が<code>basic_value<TC></code>である場合
|
||||
<a class=anchor href=#t%e3%81%8cbasic_valuetc%e3%81%a7%e3%81%82%e3%82%8b%e5%a0%b4%e5%90%88>#</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>変換先は同一の<code>toml::value</code>なので、失敗しません。</p><p>他の関数の実装を一般化するためだけに存在しています。</p><h2 id=tがbasic_valuetcsome_typeである場合><code>T</code>が<code>basic_value<TC>::{some_type}</code>である場合
|
||||
<a class=anchor href=#t%e3%81%8cbasic_valuetcsome_type%e3%81%a7%e3%81%82%e3%82%8b%e5%a0%b4%e5%90%88>#</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><code>toml::get<T></code>と同様の変換を行います。失敗した場合は第二引数が返されます。</p><h2 id=tがconst-charである場合><code>T</code>が<code>const char*</code>である場合
|
||||
<a class=anchor href=#t%e3%81%8cconst-char%e3%81%a7%e3%81%82%e3%82%8b%e5%a0%b4%e5%90%88>#</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><code>const char*</code> が渡された場合、変換先は <code>std::string</code> として解釈されます。</p><h2 id=tがその他の場合><code>T</code>がその他の場合
|
||||
<a class=anchor href=#t%e3%81%8c%e3%81%9d%e3%81%ae%e4%bb%96%e3%81%ae%e5%a0%b4%e5%90%88>#</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><code>toml::get<T></code>と同様の変換を行います。失敗した場合は第二引数が返されます。</p><h1 id=関連項目>関連項目
|
||||
<a class=anchor href=#%e9%96%a2%e9%80%a3%e9%a0%85%e7%9b%ae>#</a></h1><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/reference/find/>find.hpp</a></li><li><a href=https://toruniina.github.io/toml11/ja/docs/reference/from/>from.hpp</a></li><li><a href=https://toruniina.github.io/toml11/ja/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=#概要>概要</a><ul><li><a href=#変換が必要ない型>変換が必要ない型</a></li><li><a href=#変換が必要な型>変換が必要な型</a></li><li><a href=#失敗した場合>失敗した場合</a></li></ul></li><li><a href=#tがtomlvalueと同一のとき><code>T</code>が<code>toml::value</code>と同一のとき</a></li><li><a href=#tがtomlvaluesome_typeのいずれかのとき><code>T</code>が<code>toml::value::{some_type}</code>のいずれかのとき</a></li><li><a href=#tが異なるtypeconfigを持つbasic_valueothertcのとき><code>T</code>が異なる<code>TypeConfig</code>を持つ<code>basic_value<OtherTC></code>のとき</a></li><li><a href=#tが整数型の場合><code>T</code>が整数型の場合</a></li><li><a href=#tが浮動小数点数型の場合><code>T</code>が浮動小数点数型の場合</a></li><li><a href=#tがstdstring_viewの場合><code>T</code>が<code>std::string_view</code>の場合</a></li><li><a href=#tがstdchronodurationの場合><code>T</code>が<code>std::chrono::duration</code>の場合</a></li><li><a href=#tがstdchronosystem_clocktime_pointの場合><code>T</code>が<code>std::chrono::system_clock::time_point</code>の場合</a></li><li><a href=#tがarray-likeである場合><code>T</code>が<code>array-like</code>である場合</a></li><li><a href=#tがstdarrayである場合><code>T</code>が<code>std::array</code>である場合</a></li><li><a href=#tがstdforward_listである場合><code>T</code>が<code>std::forward_list</code>である場合</a></li><li><a href=#tがstdpairである場合><code>T</code>が<code>std::pair</code>である場合</a></li><li><a href=#tがstdtupleである場合><code>T</code>が<code>std::tuple</code>である場合</a></li><li><a href=#tがmap-likeである場合><code>T</code>が<code>map-like</code>である場合</a></li><li><a href=#tがtomlfromtの特殊化を持つユーザー定義型である場合><code>T</code>が<code>toml::from<T></code>の特殊化を持つユーザー定義型である場合</a></li><li><a href=#tがtfrom_tomlメンバ関数を持つユーザー定義型である場合><code>T</code>が<code>T::from_toml</code>メンバ関数を持つユーザー定義型である場合</a></li><li><a href=#tがtomlbasic_valuetcを取るコンストラクタを持つユーザー定義型である場合><code>T</code>が<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=#tがbasic_valuetcである場合><code>T</code>が<code>basic_value<TC></code>である場合</a></li><li><a href=#tがbasic_valuetcsome_typeである場合><code>T</code>が<code>basic_value<TC>::{some_type}</code>である場合</a></li><li><a href=#tがconst-charである場合><code>T</code>が<code>const char*</code>である場合</a></li><li><a href=#tがその他の場合><code>T</code>がその他の場合</a></li></ul></li><li><a href=#関連項目>関連項目</a></li></ul></nav></div></aside></main></body></html>
|
||||
138
ja/docs/reference/index.html
Normal file
138
ja/docs/reference/index.html
Normal file
@@ -0,0 +1,138 @@
|
||||
<!doctype html><html lang=ja dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content='
|
||||
Reference
|
||||
#
|
||||
|
||||
以下では、toml11が公開するクラスと関数の効果を説明します。
|
||||
|
||||
ディレクトリ構造
|
||||
#
|
||||
|
||||
toml.hpp と toml_fwd.hpp は ${TOML11_INCLUDE_DIR} にあります。
|
||||
他のファイルは、${TOML11_INCLUDE_DIR}/toml11 にあります。
|
||||
もし各機能のファイルを個別に #include したい場合は、 #include <toml11/color.hpp> としてください。
|
||||
全てを一度に #include する場合は、 #include <toml.hpp> としてください。
|
||||
|
||||
color.hpp
|
||||
#
|
||||
|
||||
エラーメッセージの色付けに関する関数を定義します。
|
||||
|
||||
comments.hpp
|
||||
#
|
||||
|
||||
コメントを持つpreserve_comment型とdiscard_comment型を定義します。
|
||||
|
||||
conversion.hpp
|
||||
#
|
||||
|
||||
toml::valueとユーザー定義クラスを自動的に変換するマクロを定義します。
|
||||
|
||||
datetime.hpp
|
||||
#
|
||||
|
||||
日時情報を持つクラスを定義します。
|
||||
|
||||
error_info.hpp
|
||||
#
|
||||
|
||||
エラー情報を持つクラスを定義します。
|
||||
|
||||
exception.hpp
|
||||
#
|
||||
|
||||
toml11で使用される例外の基底クラス、toml::exceptionを定義します。
|
||||
|
||||
find.hpp
|
||||
#
|
||||
|
||||
値を探し変換するtoml::find関数を定義します。
|
||||
|
||||
format.hpp
|
||||
#
|
||||
|
||||
値のフォーマット情報を持つクラスを定義します。
|
||||
|
||||
from.hpp
|
||||
#
|
||||
|
||||
ユーザー定義型を変換するためのfrom<T>型の前方宣言です。
|
||||
|
||||
get.hpp
|
||||
#
|
||||
|
||||
toml::valueの値を取り出し変換するtoml::get<T>関数を定義します。
|
||||
|
||||
into.hpp
|
||||
#
|
||||
|
||||
ユーザー定義型を変換するためのinto<T>型の前方宣言です。
|
||||
|
||||
literal.hpp
|
||||
#
|
||||
|
||||
operator"" _tomlリテラルを定義します。
|
||||
|
||||
ordered_map.hpp
|
||||
#
|
||||
|
||||
toml::ordered_mapを定義します。
|
||||
|
||||
parser.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/ja/docs/reference/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="reference"><meta property="og:description" content='Reference # 以下では、toml11が公開するクラスと関数の効果を説明します。
|
||||
ディレクトリ構造 # toml.hpp と toml_fwd.hpp は ${TOML11_INCLUDE_DIR} にあります。 他のファイルは、${TOML11_INCLUDE_DIR}/toml11 にあります。
|
||||
もし各機能のファイルを個別に #include したい場合は、 #include <toml11/color.hpp> としてください。 全てを一度に #include する場合は、 #include <toml.hpp> としてください。
|
||||
color.hpp # エラーメッセージの色付けに関する関数を定義します。
|
||||
comments.hpp # コメントを持つpreserve_comment型とdiscard_comment型を定義します。
|
||||
conversion.hpp # toml::valueとユーザー定義クラスを自動的に変換するマクロを定義します。
|
||||
datetime.hpp # 日時情報を持つクラスを定義します。
|
||||
error_info.hpp # エラー情報を持つクラスを定義します。
|
||||
exception.hpp # toml11で使用される例外の基底クラス、toml::exceptionを定義します。
|
||||
find.hpp # 値を探し変換するtoml::find関数を定義します。
|
||||
format.hpp # 値のフォーマット情報を持つクラスを定義します。
|
||||
from.hpp # ユーザー定義型を変換するためのfrom<T>型の前方宣言です。
|
||||
get.hpp # toml::valueの値を取り出し変換するtoml::get<T>関数を定義します。
|
||||
into.hpp # ユーザー定義型を変換するためのinto<T>型の前方宣言です。
|
||||
literal.hpp # operator"" _tomlリテラルを定義します。
|
||||
ordered_map.hpp # toml::ordered_mapを定義します。
|
||||
parser.hpp # ファイルまたは文字列をパースする関数を定義します。'><meta property="og:locale" content="ja"><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/ja/docs/reference/><link rel=alternate hreflang=en href=https://toruniina.github.io/toml11/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/ja.search.min.b1a1e3e4be0fdf11fae2bb2370353d99ecd7abea7ccc29273319c021dda76dfd.js integrity="sha256-saHj5L4P3xH64rsjcDU9mezXq+p8zCknMxnAId2nbf0=" crossorigin=anonymous></script><link rel=alternate type=application/rss+xml href=https://toruniina.github.io/toml11/ja/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/ja/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=検索 aria-label=検索 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>
|
||||
日本語</a></label><ul><li><a href=https://toruniina.github.io/toml11/docs/reference/>English</a></li></ul></li></ul><ul><li><a href=/toml11/ja/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-b4cfb5b55e913a8d853eacf5e8fba05f class=toggle>
|
||||
<label for=section-b4cfb5b55e913a8d853eacf5e8fba05f class="flex justify-between"><a href=/toml11/ja/docs/features/>features</a></label><ul><li><a href=/toml11/ja/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/ja/docs/features/value/>getting values</a></li><li><a href=/toml11/ja/docs/features/error_message/>error message</a></li><li><a href=/toml11/ja/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/ja/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/ja/docs/features/literal/>toml literal</a></li><li><a href=/toml11/ja/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/ja/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-01b096afc5186aea96713b408b47c967 class=toggle checked>
|
||||
<label for=section-01b096afc5186aea96713b408b47c967 class="flex justify-between"><a href=/toml11/ja/docs/reference/ class=active>reference</a></label><ul><li><a href=/toml11/ja/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/ja/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/ja/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/ja/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/ja/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/ja/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/ja/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/ja/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/ja/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/ja/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/ja/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/ja/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/ja/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/ja/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/ja/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/ja/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/ja/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/ja/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/ja/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/ja/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/ja/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/ja/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/ja/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/ja/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=#ディレクトリ構造>ディレクトリ構造</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=#備考>備考</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>以下では、toml11が公開するクラスと関数の効果を説明します。</p><h2 id=ディレクトリ構造>ディレクトリ構造
|
||||
<a class=anchor href=#%e3%83%87%e3%82%a3%e3%83%ac%e3%82%af%e3%83%88%e3%83%aa%e6%a7%8b%e9%80%a0>#</a></h2><p><code>toml.hpp</code> と <code>toml_fwd.hpp</code> は <code>${TOML11_INCLUDE_DIR}</code> にあります。
|
||||
他のファイルは、<code>${TOML11_INCLUDE_DIR}/toml11</code> にあります。</p><p>もし各機能のファイルを個別に <code>#include</code> したい場合は、 <code>#include <toml11/color.hpp></code> としてください。
|
||||
全てを一度に <code>#include</code> する場合は、 <code>#include <toml.hpp></code> としてください。</p><h2 id=colorhpp><a href=color>color.hpp</a>
|
||||
<a class=anchor href=#colorhpp>#</a></h2><p>エラーメッセージの色付けに関する関数を定義します。</p><h2 id=commentshpp><a href=comments>comments.hpp</a>
|
||||
<a class=anchor href=#commentshpp>#</a></h2><p>コメントを持つ<code>preserve_comment</code>型と<code>discard_comment</code>型を定義します。</p><h2 id=conversionhpp><a href=conversion>conversion.hpp</a>
|
||||
<a class=anchor href=#conversionhpp>#</a></h2><p><code>toml::value</code>とユーザー定義クラスを自動的に変換するマクロを定義します。</p><h2 id=datetimehpp><a href=datetime>datetime.hpp</a>
|
||||
<a class=anchor href=#datetimehpp>#</a></h2><p>日時情報を持つクラスを定義します。</p><h2 id=error_><a href=error_info>error_info.hpp</a>
|
||||
<a class=anchor href=#error_>#</a></h2><p>エラー情報を持つクラスを定義します。</p><h2 id=exceptionhpp><a href=exception>exception.hpp</a>
|
||||
<a class=anchor href=#exceptionhpp>#</a></h2><p>toml11で使用される例外の基底クラス、<code>toml::exception</code>を定義します。</p><h2 id=findhpp><a href=find>find.hpp</a>
|
||||
<a class=anchor href=#findhpp>#</a></h2><p>値を探し変換する<code>toml::find</code>関数を定義します。</p><h2 id=formathpp><a href=format>format.hpp</a>
|
||||
<a class=anchor href=#formathpp>#</a></h2><p>値のフォーマット情報を持つクラスを定義します。</p><h2 id=fromhpp><a href=from>from.hpp</a>
|
||||
<a class=anchor href=#fromhpp>#</a></h2><p>ユーザー定義型を変換するための<code>from<T></code>型の前方宣言です。</p><h2 id=gethpp><a href=get>get.hpp</a>
|
||||
<a class=anchor href=#gethpp>#</a></h2><p><code>toml::value</code>の値を取り出し変換する<code>toml::get<T></code>関数を定義します。</p><h2 id=intohpp><a href=into>into.hpp</a>
|
||||
<a class=anchor href=#intohpp>#</a></h2><p>ユーザー定義型を変換するための<code>into<T></code>型の前方宣言です。</p><h2 id=literalhpp><a href=literal>literal.hpp</a>
|
||||
<a class=anchor href=#literalhpp>#</a></h2><p><code>operator"" _toml</code>リテラルを定義します。</p><h2 id=ordered_><a href=ordered_map>ordered_map.hpp</a>
|
||||
<a class=anchor href=#ordered_>#</a></h2><p><code>toml::ordered_map</code>を定義します。</p><h2 id=parserhpp><a href=parser>parser.hpp</a>
|
||||
<a class=anchor href=#parserhpp>#</a></h2><p>ファイルまたは文字列をパースする関数を定義します。</p><h2 id=resulthpp><a href=result>result.hpp</a>
|
||||
<a class=anchor href=#resulthpp>#</a></h2><p>他の関数の返り値として使われる、成功値または失敗値を持つ<code>result<T, E></code>型を定義します。</p><h2 id=serializerhpp><a href=serializer>serializer.hpp</a>
|
||||
<a class=anchor href=#serializerhpp>#</a></h2><p>シリアライズに用いる<code>toml::format</code>関数と<code>toml::serializer</code>を定義します。</p><h2 id=source_><a href=source_location>source_location.hpp</a>
|
||||
<a class=anchor href=#source_>#</a></h2><p>エラー情報に用いられる、ファイル内のある領域を指す<code>source_location</code>型を定義します。</p><h2 id=spechpp><a href=spec>spec.hpp</a>
|
||||
<a class=anchor href=#spechpp>#</a></h2><p>TOML言語のバージョン情報と機能フラグを制御する、<code>toml::semantic_version</code>型と<code>toml::spec</code>型を定義します。</p><h2 id=tomlhpp><a href=toml>toml.hpp</a>
|
||||
<a class=anchor href=#tomlhpp>#</a></h2><p><code>toml.hpp</code>は、他の全てのヘッダを <code>include</code> します。
|
||||
toml11の全機能が使用可能になります。</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>は、toml11で定義される構造体の前方宣言と、マクロ定義を持ちます。</p><h2 id=typeshpp><a href=types>types.hpp</a>
|
||||
<a class=anchor href=#typeshpp>#</a></h2><p><code>toml::value</code>の持つ型を制御するための<code>toml::type_config</code>型を定義します。</p><h2 id=valuehpp><a href=value>value.hpp</a>
|
||||
<a class=anchor href=#valuehpp>#</a></h2><p><code>toml::value</code>型を定義します。</p><h2 id=value_><a href=value_t>value_t.hpp</a>
|
||||
<a class=anchor href=#value_>#</a></h2><p>列挙型<code>toml::value_t</code>を定義します。</p><h2 id=versionhpp><a href=version>version.hpp</a>
|
||||
<a class=anchor href=#versionhpp>#</a></h2><p>toml11のバージョン情報を定義します。</p><h2 id=visithpp><a href=visit>visit.hpp</a>
|
||||
<a class=anchor href=#visithpp>#</a></h2><p><code>toml::value</code>の持つ値に関数を適用する<code>toml::visit</code>関数を定義します。</p><h2 id=備考>備考
|
||||
<a class=anchor href=#%e5%82%99%e8%80%83>#</a></h2><p>ここで明記されない関数(主に<code>namespace toml::detail</code>や<code>namespace toml::cxx</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=#reference>Reference</a><ul><li><a href=#ディレクトリ構造>ディレクトリ構造</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=#備考>備考</a></li></ul></li></ul></nav></div></aside></main></body></html>
|
||||
1132
ja/docs/reference/index.xml
Normal file
1132
ja/docs/reference/index.xml
Normal file
File diff suppressed because it is too large
Load Diff
96
ja/docs/reference/into/index.html
Normal file
96
ja/docs/reference/into/index.html
Normal file
@@ -0,0 +1,96 @@
|
||||
<!doctype html><html lang=ja dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content='
|
||||
into.hpp
|
||||
#
|
||||
|
||||
toml::valueのコンストラクタで使用する、ユーザー定義型からの変換を定義する構造体です。
|
||||
メンバ関数にinto_tomlを追加することによっても同じ機能を追加できますが、メンバ関数を追加できないクラスに対してはinto<T>を使用してください。
|
||||
このファイルでは特定の実装は提供しません。使用する際に、この構造体を特殊化してください。
|
||||
namespace toml
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
struct into;
|
||||
|
||||
} // toml
|
||||
|
||||
例
|
||||
#
|
||||
|
||||
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
|
||||
|
||||
関連項目
|
||||
#
|
||||
|
||||
|
||||
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/ja/docs/reference/into/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="into.hpp"><meta property="og:description" content='into.hpp # toml::valueのコンストラクタで使用する、ユーザー定義型からの変換を定義する構造体です。
|
||||
メンバ関数にinto_tomlを追加することによっても同じ機能を追加できますが、メンバ関数を追加できないクラスに対してはinto<T>を使用してください。
|
||||
このファイルでは特定の実装は提供しません。使用する際に、この構造体を特殊化してください。
|
||||
namespace toml { template<typename T> struct into; } // toml 例 # 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 関連項目 # conversion.hpp from.hpp'><meta property="og:locale" content="ja"><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/ja/docs/reference/into/><link rel=alternate hreflang=en href=https://toruniina.github.io/toml11/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/ja.search.min.b1a1e3e4be0fdf11fae2bb2370353d99ecd7abea7ccc29273319c021dda76dfd.js integrity="sha256-saHj5L4P3xH64rsjcDU9mezXq+p8zCknMxnAId2nbf0=" 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/ja/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=検索 aria-label=検索 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>
|
||||
日本語</a></label><ul><li><a href=https://toruniina.github.io/toml11/docs/reference/into/>English</a></li></ul></li></ul><ul><li><a href=/toml11/ja/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-b4cfb5b55e913a8d853eacf5e8fba05f class=toggle>
|
||||
<label for=section-b4cfb5b55e913a8d853eacf5e8fba05f class="flex justify-between"><a href=/toml11/ja/docs/features/>features</a></label><ul><li><a href=/toml11/ja/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/ja/docs/features/value/>getting values</a></li><li><a href=/toml11/ja/docs/features/error_message/>error message</a></li><li><a href=/toml11/ja/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/ja/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/ja/docs/features/literal/>toml literal</a></li><li><a href=/toml11/ja/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/ja/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-01b096afc5186aea96713b408b47c967 class=toggle checked>
|
||||
<label for=section-01b096afc5186aea96713b408b47c967 class="flex justify-between"><a href=/toml11/ja/docs/reference/>reference</a></label><ul><li><a href=/toml11/ja/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/ja/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/ja/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/ja/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/ja/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/ja/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/ja/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/ja/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/ja/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/ja/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/ja/docs/reference/into/ class=active>into.hpp</a></li><li><a href=/toml11/ja/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/ja/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/ja/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/ja/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/ja/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/ja/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/ja/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/ja/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/ja/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/ja/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/ja/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/ja/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/ja/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=#例>例</a></li></ul></li><li><a href=#関連項目>関連項目</a></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=intohpp>into.hpp
|
||||
<a class=anchor href=#intohpp>#</a></h1><p><code>toml::value</code>のコンストラクタで使用する、ユーザー定義型からの変換を定義する構造体です。</p><p>メンバ関数に<code>into_toml</code>を追加することによっても同じ機能を追加できますが、メンバ関数を追加できないクラスに対しては<code>into<T></code>を使用してください。</p><p>このファイルでは特定の実装は提供しません。使用する際に、この構造体を特殊化してください。</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=例>例
|
||||
<a class=anchor href=#%e4%be%8b>#</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=関連項目>関連項目
|
||||
<a class=anchor href=#%e9%96%a2%e9%80%a3%e9%a0%85%e7%9b%ae>#</a></h1><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/reference/conversion/>conversion.hpp</a></li><li><a href=https://toruniina.github.io/toml11/ja/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=#例>例</a></li></ul></li><li><a href=#関連項目>関連項目</a></li></ul></nav></div></aside></main></body></html>
|
||||
87
ja/docs/reference/literal/index.html
Normal file
87
ja/docs/reference/literal/index.html
Normal file
@@ -0,0 +1,87 @@
|
||||
<!doctype html><html lang=ja dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content='
|
||||
literal.hpp
|
||||
#
|
||||
|
||||
literal.hppでは、_tomlリテラルが定義されます。
|
||||
_tomlリテラルは、文字列リテラルをパースして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); // C++20以降
|
||||
} // toml_literals
|
||||
} // literals
|
||||
} // toml
|
||||
|
||||
自由関数
|
||||
#
|
||||
|
||||
|
||||
operator"" _toml(char)
|
||||
#
|
||||
|
||||
toml::value operator"" _toml(const char* str, std::size_t len);
|
||||
文字列リテラルをパースしてtoml::valueに変換します。
|
||||
通常のTOMLファイルの場合、toml::parseと同等の処理が行われます。
|
||||
const auto v1 = "a = 'foo'"_toml; // v1: {a = 'foo'}
|
||||
改行を含む場合、生文字列リテラルが便利です。
|
||||
const auto v1 = R"(
|
||||
a = 42
|
||||
b = "foo"
|
||||
)"_toml;
|
||||
値が単体で書かれていた場合、その値になります。
|
||||
const auto v2 = "'foo'"_toml; // v2: 'foo'
|
||||
TOMLは数値のみからなるキーを許可しています。
|
||||
[1]のように、テーブル定義と配列の区別がつかない場合、テーブル定義が優先されます。
|
||||
配列として解釈させるには、trailing commaを使用してください。'><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/ja/docs/reference/literal/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="literal.hpp"><meta property="og:description" content='literal.hpp # literal.hppでは、_tomlリテラルが定義されます。
|
||||
_tomlリテラルは、文字列リテラルをパースして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); // C++20以降 } // toml_literals } // literals } // toml 自由関数 # operator"" _toml(char) # toml::value operator"" _toml(const char* str, std::size_t len); 文字列リテラルをパースしてtoml::valueに変換します。
|
||||
通常のTOMLファイルの場合、toml::parseと同等の処理が行われます。
|
||||
const auto v1 = "a = 'foo'"_toml; // v1: {a = 'foo'} 改行を含む場合、生文字列リテラルが便利です。
|
||||
const auto v1 = R"( a = 42 b = "foo" )"_toml; 値が単体で書かれていた場合、その値になります。
|
||||
const auto v2 = "'foo'"_toml; // v2: 'foo' TOMLは数値のみからなるキーを許可しています。 [1]のように、テーブル定義と配列の区別がつかない場合、テーブル定義が優先されます。
|
||||
配列として解釈させるには、trailing commaを使用してください。'><meta property="og:locale" content="ja"><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/ja/docs/reference/literal/><link rel=alternate hreflang=en href=https://toruniina.github.io/toml11/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/ja.search.min.b1a1e3e4be0fdf11fae2bb2370353d99ecd7abea7ccc29273319c021dda76dfd.js integrity="sha256-saHj5L4P3xH64rsjcDU9mezXq+p8zCknMxnAId2nbf0=" 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/ja/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=検索 aria-label=検索 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>
|
||||
日本語</a></label><ul><li><a href=https://toruniina.github.io/toml11/docs/reference/literal/>English</a></li></ul></li></ul><ul><li><a href=/toml11/ja/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-b4cfb5b55e913a8d853eacf5e8fba05f class=toggle>
|
||||
<label for=section-b4cfb5b55e913a8d853eacf5e8fba05f class="flex justify-between"><a href=/toml11/ja/docs/features/>features</a></label><ul><li><a href=/toml11/ja/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/ja/docs/features/value/>getting values</a></li><li><a href=/toml11/ja/docs/features/error_message/>error message</a></li><li><a href=/toml11/ja/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/ja/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/ja/docs/features/literal/>toml literal</a></li><li><a href=/toml11/ja/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/ja/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-01b096afc5186aea96713b408b47c967 class=toggle checked>
|
||||
<label for=section-01b096afc5186aea96713b408b47c967 class="flex justify-between"><a href=/toml11/ja/docs/reference/>reference</a></label><ul><li><a href=/toml11/ja/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/ja/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/ja/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/ja/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/ja/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/ja/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/ja/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/ja/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/ja/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/ja/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/ja/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/ja/docs/reference/literal/ class=active>literal.hpp</a></li><li><a href=/toml11/ja/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/ja/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/ja/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/ja/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/ja/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/ja/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/ja/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/ja/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/ja/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/ja/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/ja/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/ja/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/ja/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=#自由関数>自由関数</a><ul><li><a href=#operator-_tomlchar><code>operator"" _toml(char)</code></a></li><li><a href=#operator-_tomlchar8_t><code>operator"" _toml(char8_t)</code></a></li></ul></li></ul></li><li><a href=#例>例</a></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=literalhpp>literal.hpp
|
||||
<a class=anchor href=#literalhpp>#</a></h1><p><code>literal.hpp</code>では、<code>_toml</code>リテラルが定義されます。</p><p><code>_toml</code>リテラルは、文字列リテラルをパースして<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>// C++20以降
|
||||
</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=自由関数>自由関数
|
||||
<a class=anchor href=#%e8%87%aa%e7%94%b1%e9%96%a2%e6%95%b0>#</a></h2><h3 id=operator-_tomlchar><code>operator"" _toml(char)</code>
|
||||
<a class=anchor href=#operator-_tomlchar>#</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>文字列リテラルをパースして<code>toml::value</code>に変換します。</p><p>通常のTOMLファイルの場合、<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>改行を含む場合、生文字列リテラルが便利です。</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>値が単体で書かれていた場合、その値になります。</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は数値のみからなるキーを許可しています。
|
||||
<code>[1]</code>のように、テーブル定義と配列の区別がつかない場合、テーブル定義が優先されます。</p><p>配列として解釈させるには、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-_tomlchar8_t><code>operator"" _toml(char8_t)</code>
|
||||
<a class=anchor href=#operator-_tomlchar8_t>#</a></h3><p><code>char8_t</code>が利用可能な場合に定義されます。引数の型のほかに違いはありません。</p><h1 id=例>例
|
||||
<a class=anchor href=#%e4%be%8b>#</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=#自由関数>自由関数</a><ul><li><a href=#operator-_tomlchar><code>operator"" _toml(char)</code></a></li><li><a href=#operator-_tomlchar8_t><code>operator"" _toml(char8_t)</code></a></li></ul></li></ul></li><li><a href=#例>例</a></li></ul></nav></div></aside></main></body></html>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user