Files
toml11/docs/reference/serializer/index.html
ToruNiina 360850a8c8 Merge pull request #295 from franzpoeschel/undef-source-location
Add a way to optionally suppress usage of std::source_location b96acf96ba
2025-12-03 15:01:09 +00:00

65 lines
15 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!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&rsquo;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 theres 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>&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><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&rsquo;s a <code>table_type</code>, it&rsquo;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&rsquo;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>&amp;</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>