cereal/assets/doxygen/structcereal_1_1LoadAndConstruct.html
2022-02-27 19:48:38 -08:00

154 lines
10 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.17"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>cereal: cereal::LoadAndConstruct&lt; T &gt; Struct Template Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">cereal
</div>
<div id="projectbrief">A C++11 library for serialization</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.17 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div id="nav-path" class="navpath">
<ul>
<li class="navelem"><b>cereal</b></li><li class="navelem"><a class="el" href="structcereal_1_1LoadAndConstruct.html">LoadAndConstruct</a></li> </ul>
</div>
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">cereal::LoadAndConstruct&lt; T &gt; Struct Template Reference<div class="ingroups"><a class="el" href="group__Access.html">Access Control and Disambiguation</a></div></div> </div>
</div><!--header-->
<div class="contents">
<p>A class that allows cereal to load smart pointers to types that have no default constructor.
<a href="structcereal_1_1LoadAndConstruct.html#details">More...</a></p>
<p><code>#include &lt;<a class="el" href="access_8hpp_source.html">/home/shane/workspace/cereal/include/cereal/access.hpp</a>&gt;</code></p>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><h3>template&lt;class T&gt;<br />
struct cereal::LoadAndConstruct&lt; T &gt;</h3>
<p>A class that allows cereal to load smart pointers to types that have no default constructor. </p>
<p>If your class does not have a default constructor, cereal will not be able to load any smart pointers to it unless you overload <a class="el" href="structcereal_1_1LoadAndConstruct.html" title="A class that allows cereal to load smart pointers to types that have no default constructor.">LoadAndConstruct</a> for your class, and provide an appropriate load_and_construct method. You can also choose to define a member static function instead of specializing this class.</p>
<p>The specialization of <a class="el" href="structcereal_1_1LoadAndConstruct.html" title="A class that allows cereal to load smart pointers to types that have no default constructor.">LoadAndConstruct</a> must be placed within the cereal namespace:</p>
<div class="fragment"><div class="line"><span class="keyword">struct </span>MyType</div>
<div class="line">{</div>
<div class="line"> MyType( <span class="keywordtype">int</span> x ); <span class="comment">// note: no default ctor</span></div>
<div class="line"> <span class="keywordtype">int</span> myX;</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Define a serialize or load/save pair as you normally would</span></div>
<div class="line"> <span class="keyword">template</span> &lt;<span class="keyword">class</span> Archive&gt;</div>
<div class="line"> <span class="keywordtype">void</span> <a class="code" href="functional_8hpp.html#a02f9cfc9a4055c8a49eb050b02cd3357">serialize</a>( Archive &amp; ar )</div>
<div class="line"> {</div>
<div class="line"> ar( myX );</div>
<div class="line"> }</div>
<div class="line">};</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Provide a specialization for LoadAndConstruct for your type</span></div>
<div class="line"><span class="keyword">namespace </span>cereal</div>
<div class="line">{</div>
<div class="line"> <span class="keyword">template</span> &lt;&gt; <span class="keyword">struct </span>LoadAndConstruct&lt;MyType&gt;</div>
<div class="line"> {</div>
<div class="line"> <span class="comment">// load_and_construct will be passed the archive that you will be loading</span></div>
<div class="line"> <span class="comment">// from as well as a construct object which you can use as if it were the</span></div>
<div class="line"> <span class="comment">// constructor for your type. cereal will handle all memory management for you.</span></div>
<div class="line"> <span class="keyword">template</span> &lt;<span class="keyword">class</span> Archive&gt;</div>
<div class="line"> <span class="keyword">static</span> <span class="keywordtype">void</span> load_and_construct( Archive &amp; ar, <a class="code" href="classcereal_1_1construct.html">cereal::construct&lt;MyType&gt;</a> &amp; construct )</div>
<div class="line"> {</div>
<div class="line"> <span class="keywordtype">int</span> x;</div>
<div class="line"> ar( x );</div>
<div class="line"> construct( x );</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// if you require versioning, simply add a const std::uint32_t as the final parameter, e.g.:</span></div>
<div class="line"> <span class="comment">// load_and_construct( Archive &amp; ar, cereal::construct&lt;MyType&gt; &amp; construct, std::uint32_t const version )</span></div>
<div class="line"> };</div>
<div class="line">} <span class="comment">// end namespace cereal</span></div>
</div><!-- fragment --><p>Please note that just as in using external serialization functions, you cannot get access to non-public members of your class by befriending <a class="el" href="classcereal_1_1access.html" title="A class that can be made a friend to give cereal access to non public functions.">cereal::access</a>. If you have the ability to modify the class you wish to serialize, it is recommended that you use member serialize functions and a static member load_and_construct function.</p>
<p>load_and_construct functions, regardless of whether they are static members of your class or whether you create one in the <a class="el" href="structcereal_1_1LoadAndConstruct.html" title="A class that allows cereal to load smart pointers to types that have no default constructor.">LoadAndConstruct</a> specialization, have the following signature:</p>
<div class="fragment"><div class="line"><span class="comment">// generally Archive will be templated, but it can be specific if desired</span></div>
<div class="line"><span class="keyword">template</span> &lt;<span class="keyword">class</span> Archive&gt;</div>
<div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> load_and_construct( Archive &amp; ar, <a class="code" href="classcereal_1_1construct.html">cereal::construct&lt;MyType&gt;</a> &amp; construct );</div>
<div class="line"><span class="comment">// with an optional last parameter specifying the version: const std::uint32_t version</span></div>
</div><!-- fragment --><p>Versioning behaves the same way as it does for standard serialization functions.</p>
<dl class="tparams"><dt>Template Parameters</dt><dd>
<table class="tparams">
<tr><td class="paramname">T</td><td>The type to specialize for </td></tr>
</table>
</dd>
</dl>
</div><hr/>The documentation for this struct was generated from the following file:<ul>
<li><a class="el" href="access_8hpp_source.html">access.hpp</a></li>
</ul>
</div><!-- contents -->
<div class="ttc" id="aclasscereal_1_1construct_html"><div class="ttname"><a href="classcereal_1_1construct.html">cereal::construct</a></div><div class="ttdoc">Used to construct types with no default constructor.</div><div class="ttdef"><b>Definition:</b> access.hpp:164</div></div>
<div class="ttc" id="afunctional_8hpp_html_a02f9cfc9a4055c8a49eb050b02cd3357"><div class="ttname"><a href="functional_8hpp.html#a02f9cfc9a4055c8a49eb050b02cd3357">cereal::serialize</a></div><div class="ttdeci">void serialize(Archive &amp;, std::less&lt; T &gt; &amp;)</div><div class="ttdoc">Saving for std::less.</div><div class="ttdef"><b>Definition:</b> functional.hpp:39</div></div>
<!-- HTML footer for doxygen 1.8.3.1-->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Sun Feb 27 2022 19:46:46 for cereal by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.17
</small></address>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-42360142-1', 'uscilab.github.io');
ga('send', 'pageview');
</script>
</body>
</html>