<!-- HTML header for doxygen 1.8.8--> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <!-- For Mobile Devices --> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <meta name="generator" content="Doxygen 1.8.15"/> <script type="text/javascript" src="jquery.min.js"></script> <title>rttr: rttr::wrapper_mapper< T > Struct Template Reference</title> <!--<link href="tabs.css" rel="stylesheet" type="text/css"/>--> <script type="text/javascript" src="dynsections.js"></script> <link rel = "shortcut icon" type = "image/x-icon" href = "favicon.ico"> <link rel = "stylesheet" href = "fonts/ptsans_regular_macroman/stylesheet.css"> <link rel = "stylesheet" href = "fonts/source_code_pro_regular/stylesheet.css"> <link href="doxygen.css" rel="stylesheet" type="text/css" /> <link href="custom-doxygen.css" rel="stylesheet" type="text/css"/> <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css"> <link rel="stylesheet" href="custom-bootstrap.css"> <script src="bootstrap/js/bootstrap.min.js"></script> <script type="text/javascript" src="doxy-boot.js"></script> </head> <body> <!-- <nav class="navbar navbar-default" role="navigation"> <div class="container"> <div class="navbar-header"> <a class="navbar-brand">rttr 0.9.6</a> </div> </div> </nav> --> <div id="top"><!-- do not remove this div, it is closed by doxygen! --> <div class="content" id="content"> <div class="container"> <div class="row"> <div class="col-sm-12 panel panel-default" style="padding-bottom: 15px;"> <div style="margin-bottom: 15px;"> <!-- end header part --> <!-- Generated by Doxygen 1.8.15 --> <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&dn=gpl-2.0.txt GPL-v2 */ $(function() { initMenu('',false,false,'search.php','Search'); }); /* @license-end */</script> <div id="main-nav"></div> <div id="nav-path" class="navpath"> <ul> <li class="navelem"><a class="el" href="namespacerttr.html">rttr</a></li><li class="navelem"><a class="el" href="structrttr_1_1wrapper__mapper.html">wrapper_mapper</a></li> </ul> </div> </div><!-- top --> <div class="header"> <div class="summary"> <a href="#pub-types">Public Types</a> | <a href="#pub-static-methods">Static Public Member Functions</a> | <a href="structrttr_1_1wrapper__mapper-members.html">List of all members</a> </div> <div class="headertitle"> <div class="title">rttr::wrapper_mapper< T > Struct Template Reference</div> </div> </div><!--header--> <div class="contents"> <p>The <a class="el" href="structrttr_1_1wrapper__mapper.html">wrapper_mapper</a> class is a class template to access different wrapper types via one common interface. <a href="structrttr_1_1wrapper__mapper.html#details">More...</a></p> <p><code>#include <<a class="el" href="wrapper__mapper_8h_source.html">wrapper_mapper.h</a>></code></p> <table class="memberdecls"> <tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-types"></a> Public Types</h2></td></tr> <tr class="memitem:aa31a021c9204019005f773f3936664ae"><td class="memItemLeft" align="right" valign="top">using </td><td class="memItemRight" valign="bottom"><a class="el" href="structrttr_1_1wrapper__mapper.html#aa31a021c9204019005f773f3936664ae">type</a> = T</td></tr> <tr class="separator:aa31a021c9204019005f773f3936664ae"><td class="memSeparator" colspan="2"> </td></tr> <tr class="memitem:aef27f279c5b9dc07b35b4aea43d52e54"><td class="memItemLeft" align="right" valign="top">using </td><td class="memItemRight" valign="bottom"><a class="el" href="structrttr_1_1wrapper__mapper.html#aef27f279c5b9dc07b35b4aea43d52e54">wrapped_type</a> = typename wrapper_type::encapsulated_type</td></tr> <tr class="separator:aef27f279c5b9dc07b35b4aea43d52e54"><td class="memSeparator" colspan="2"> </td></tr> </table><table class="memberdecls"> <tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-static-methods"></a> Static Public Member Functions</h2></td></tr> <tr class="memitem:a09b97542c595c46018beb77ad471c138"><td class="memTemplParams" colspan="2">template<typename U > </td></tr> <tr class="memitem:a09b97542c595c46018beb77ad471c138"><td class="memTemplItemLeft" align="right" valign="top">static T< U > </td><td class="memTemplItemRight" valign="bottom"><a class="el" href="structrttr_1_1wrapper__mapper.html#a09b97542c595c46018beb77ad471c138">convert</a> (const <a class="el" href="structrttr_1_1wrapper__mapper.html#aa31a021c9204019005f773f3936664ae">type</a> &source, bool &ok)</td></tr> <tr class="separator:a09b97542c595c46018beb77ad471c138"><td class="memSeparator" colspan="2"> </td></tr> <tr class="memitem:a144d8f748363da93668c19b51b053250"><td class="memItemLeft" align="right" valign="top">static <a class="el" href="structrttr_1_1wrapper__mapper.html#aa31a021c9204019005f773f3936664ae">type</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="structrttr_1_1wrapper__mapper.html#a144d8f748363da93668c19b51b053250">create</a> (const <a class="el" href="structrttr_1_1wrapper__mapper.html#aef27f279c5b9dc07b35b4aea43d52e54">wrapped_type</a> &<a class="el" href="namespacerttr.html#a54ecd8bad715cbc451e7aa8491667d4a">value</a>)</td></tr> <tr class="separator:a144d8f748363da93668c19b51b053250"><td class="memSeparator" colspan="2"> </td></tr> <tr class="memitem:a2e313e8bcecb6e485b4dbe38267ecee7"><td class="memItemLeft" align="right" valign="top">static <a class="el" href="structrttr_1_1wrapper__mapper.html#aef27f279c5b9dc07b35b4aea43d52e54">wrapped_type</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="structrttr_1_1wrapper__mapper.html#a2e313e8bcecb6e485b4dbe38267ecee7">get</a> (const <a class="el" href="structrttr_1_1wrapper__mapper.html#aa31a021c9204019005f773f3936664ae">type</a> &obj)</td></tr> <tr class="separator:a2e313e8bcecb6e485b4dbe38267ecee7"><td class="memSeparator" colspan="2"> </td></tr> </table> <a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2> <div class="textblock"><h3>template<typename T><br /> struct rttr::wrapper_mapper< T ></h3> <p>The <a class="el" href="structrttr_1_1wrapper__mapper.html">wrapper_mapper</a> class is a class template to access different wrapper types via one common interface. </p> <p>A wrapper type is a class which encapsulate an instance of another type. This are for instance smart pointer classes, e.g. <code>std::shared_ptr<T></code> or <code>std::unique_ptr<T></code>. Out of the box, RTTR recognize following wrapper types:</p><ul> <li><code><code>std::shared_ptr<T></code></code> </li> <li><code><code>std::reference_wrapper<T></code></code> </li> <li><code><code>std::weak_ptr<T></code></code> </li> <li><code><code>std::unique_ptr<T></code></code> </li> </ul> <h2>Custom wrapper types </h2> <p>In order to work with custom wrapper types, its required to specialize the class <a class="el" href="structrttr_1_1wrapper__mapper.html">wrapper_mapper<T></a>. Therefore you have to provide two nested type aliases:</p><ol type="1"> <li><code>using wrapped_type = typename T::encapsulated_type;</code></li> <li><code>using type = T</code></li> </ol> <p>And three functions:</p><ol type="1"> <li><code>static wrapped_type <a class="el" href="structrttr_1_1wrapper__mapper.html#a2e313e8bcecb6e485b4dbe38267ecee7">get(const T& obj)</a>;</code></li> <li><code>static T create(wrapped_type& obj);</code> (Optional)</li> <li><code>static T<U> <a class="el" href="structrttr_1_1wrapper__mapper.html#a09b97542c595c46018beb77ad471c138">convert(const type& source, bool& ok)</a>;</code> (Optional)</li> </ol> <dl class="section remark"><dt>Remarks</dt><dd>The create() function is optional. When no one is provided, then it will be not possible to convert from the wrapped type to the wrapper class from inside a variant. The <a class="el" href="structrttr_1_1wrapper__mapper.html#a09b97542c595c46018beb77ad471c138">convert()</a> function is also optional. When no one is provided, you cannot use the <a class="el" href="classrttr_1_1type.html#a80fbbd3ac5729e695c8c2ef0fca4cbbc">rttr::type::register_wrapper_converter_for_base_classes<T>()</a> function. For the wrapper classes: <code>std::shared_ptr<T></code> and <code>std::reference_wrapper<T></code> default conversion functions are included.</dd></dl> <dl class="section see"><dt>See also</dt><dd><a class="el" href="classrttr_1_1variant.html#a48031e0f0a64cc87b7476138071e9c2c" title="Converts the containing variant internally to the given type target_type.">variant::convert()</a></dd></dl> <p>Following code example illustrates how to add a specialization: </p><div class="fragment"><div class="line"><span class="comment">// custom_type.h</span></div><div class="line"></div><div class="line"><span class="keyword">template</span><<span class="keyword">typename</span> T></div><div class="line"><span class="keyword">class </span>custom_type</div><div class="line">{</div><div class="line"><span class="keyword">public</span>:</div><div class="line"> custom_type(T& obj) : m_data(std::addressof(obj)) {}</div><div class="line"> custom_type(T) : m_data(nullptr) {}</div><div class="line"> T& get_data() { <span class="keywordflow">return</span> *m_value; }</div><div class="line"><span class="keyword">private</span>:</div><div class="line"> T* m_data;</div><div class="line">};</div><div class="line"></div><div class="line"><span class="comment">// the best place for the specialization, is in the same header file like the type itself</span></div><div class="line"><span class="keyword">namespace </span><a class="code" href="namespacerttr.html">rttr</a></div><div class="line">{</div><div class="line"></div><div class="line"><span class="keyword">template</span><<span class="keyword">typename</span> T></div><div class="line"><span class="keyword">struct </span>wrapper_mapper<custom_type<T>></div><div class="line">{</div><div class="line"> <span class="keyword">using</span> <a class="code" href="structrttr_1_1wrapper__mapper.html#aef27f279c5b9dc07b35b4aea43d52e54">wrapped_type</a> = decltype(std::declval<custom_type<T>>().get_data());</div><div class="line"> <span class="keyword">using</span> <a class="code" href="structrttr_1_1wrapper__mapper.html#aa31a021c9204019005f773f3936664ae">type</a> = custom_type<T>;</div><div class="line"></div><div class="line"> <span class="keyword">inline</span> <span class="keyword">static</span> <a class="code" href="structrttr_1_1wrapper__mapper.html#aef27f279c5b9dc07b35b4aea43d52e54">wrapped_type</a> <a class="code" href="structrttr_1_1wrapper__mapper.html#a2e313e8bcecb6e485b4dbe38267ecee7">get</a>(<span class="keyword">const</span> <a class="code" href="structrttr_1_1wrapper__mapper.html#aa31a021c9204019005f773f3936664ae">type</a>& obj)</div><div class="line"> {</div><div class="line"> <span class="keywordflow">return</span> obj.get_data();</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="keyword">inline</span> <span class="keyword">static</span> <a class="code" href="structrttr_1_1wrapper__mapper.html#aa31a021c9204019005f773f3936664ae">type</a> <a class="code" href="structrttr_1_1wrapper__mapper.html#a144d8f748363da93668c19b51b053250">create</a>(<span class="keyword">const</span> <a class="code" href="structrttr_1_1wrapper__mapper.html#aef27f279c5b9dc07b35b4aea43d52e54">wrapped_type</a>& <a class="code" href="namespacerttr.html#a54ecd8bad715cbc451e7aa8491667d4a">value</a>)</div><div class="line"> {</div><div class="line"> <span class="keywordflow">return</span> custom_type<T>(<a class="code" href="namespacerttr.html#a54ecd8bad715cbc451e7aa8491667d4a">value</a>);</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="keyword">template</span><<span class="keyword">typename</span> U></div><div class="line"> <span class="keyword">inline</span> <span class="keyword">static</span> custom_type<U> <a class="code" href="structrttr_1_1wrapper__mapper.html#a09b97542c595c46018beb77ad471c138">convert</a>(<span class="keyword">const</span> <a class="code" href="structrttr_1_1wrapper__mapper.html#aa31a021c9204019005f773f3936664ae">type</a>& source, <span class="keywordtype">bool</span>& ok)</div><div class="line"> {</div><div class="line"> <span class="keywordflow">if</span> (<span class="keyword">auto</span> obj = <a class="code" href="namespacerttr.html#ab3dd8b62e5ddca4c1d57cc572ba6bb81">rttr_cast</a><<span class="keyword">typename</span> custom_type<U>::wrapped_type*>(&source.get_data()))</div><div class="line"> {</div><div class="line"> ok = <span class="keyword">true</span>;</div><div class="line"> <span class="keywordflow">return</span> custom_type<U>(*obj);</div><div class="line"> }</div><div class="line"> <span class="keywordflow">else</span></div><div class="line"> {</div><div class="line"> ok = <span class="keyword">false</span>;</div><div class="line"> <span class="keywordflow">return</span> custom_type<U>();</div><div class="line"> }</div><div class="line"> }</div><div class="line">};</div><div class="line"></div><div class="line">} <span class="comment">// end namespace rttr</span></div></div><!-- fragment --><dl class="section remark"><dt>Remarks</dt><dd>It is very important that the type alias for <code>wrapped_type</code> is the actual return type of the getter function. Make also sure you put your specialization inside the namespace <code>rttr</code>. The best place for this code, is below the declaration of your wrapper type. When this is not possible, include your specialization code before registering your types to RTTR. </dd></dl> </div><h2 class="groupheader">Member Typedef Documentation</h2> <a id="aa31a021c9204019005f773f3936664ae"></a> <h2 class="memtitle"><span class="permalink"><a href="#aa31a021c9204019005f773f3936664ae">◆ </a></span>type</h2> <div class="memitem"> <div class="memproto"> <div class="memtemplate"> template<typename T > </div> <table class="memname"> <tr> <td class="memname">using <a class="el" href="structrttr_1_1wrapper__mapper.html">rttr::wrapper_mapper</a>< T >::<a class="el" href="structrttr_1_1wrapper__mapper.html#aa31a021c9204019005f773f3936664ae">type</a> = T</td> </tr> </table> </div><div class="memdoc"> </div> </div> <a id="aef27f279c5b9dc07b35b4aea43d52e54"></a> <h2 class="memtitle"><span class="permalink"><a href="#aef27f279c5b9dc07b35b4aea43d52e54">◆ </a></span>wrapped_type</h2> <div class="memitem"> <div class="memproto"> <div class="memtemplate"> template<typename T > </div> <table class="memname"> <tr> <td class="memname">using <a class="el" href="structrttr_1_1wrapper__mapper.html">rttr::wrapper_mapper</a>< T >::<a class="el" href="structrttr_1_1wrapper__mapper.html#aef27f279c5b9dc07b35b4aea43d52e54">wrapped_type</a> = typename wrapper_type::encapsulated_type</td> </tr> </table> </div><div class="memdoc"> </div> </div> <h2 class="groupheader">Member Function Documentation</h2> <a id="a09b97542c595c46018beb77ad471c138"></a> <h2 class="memtitle"><span class="permalink"><a href="#a09b97542c595c46018beb77ad471c138">◆ </a></span>convert()</h2> <div class="memitem"> <div class="memproto"> <div class="memtemplate"> template<typename T > </div> <div class="memtemplate"> template<typename U > </div> <table class="mlabels"> <tr> <td class="mlabels-left"> <table class="memname"> <tr> <td class="memname">static T<U> <a class="el" href="structrttr_1_1wrapper__mapper.html">rttr::wrapper_mapper</a>< T >::convert </td> <td>(</td> <td class="paramtype">const <a class="el" href="structrttr_1_1wrapper__mapper.html#aa31a021c9204019005f773f3936664ae">type</a> & </td> <td class="paramname"><em>source</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">bool & </td> <td class="paramname"><em>ok</em> </td> </tr> <tr> <td></td> <td>)</td> <td></td><td></td> </tr> </table> </td> <td class="mlabels-right"> <span class="mlabels"><span class="mlabel">inline</span><span class="mlabel">static</span></span> </td> </tr> </table> </div><div class="memdoc"> </div> </div> <a id="a144d8f748363da93668c19b51b053250"></a> <h2 class="memtitle"><span class="permalink"><a href="#a144d8f748363da93668c19b51b053250">◆ </a></span>create()</h2> <div class="memitem"> <div class="memproto"> <div class="memtemplate"> template<typename T > </div> <table class="mlabels"> <tr> <td class="mlabels-left"> <table class="memname"> <tr> <td class="memname">static <a class="el" href="structrttr_1_1wrapper__mapper.html#aa31a021c9204019005f773f3936664ae">type</a> <a class="el" href="structrttr_1_1wrapper__mapper.html">rttr::wrapper_mapper</a>< T >::create </td> <td>(</td> <td class="paramtype">const <a class="el" href="structrttr_1_1wrapper__mapper.html#aef27f279c5b9dc07b35b4aea43d52e54">wrapped_type</a> & </td> <td class="paramname"><em>value</em></td><td>)</td> <td></td> </tr> </table> </td> <td class="mlabels-right"> <span class="mlabels"><span class="mlabel">inline</span><span class="mlabel">static</span></span> </td> </tr> </table> </div><div class="memdoc"> </div> </div> <a id="a2e313e8bcecb6e485b4dbe38267ecee7"></a> <h2 class="memtitle"><span class="permalink"><a href="#a2e313e8bcecb6e485b4dbe38267ecee7">◆ </a></span>get()</h2> <div class="memitem"> <div class="memproto"> <div class="memtemplate"> template<typename T > </div> <table class="mlabels"> <tr> <td class="mlabels-left"> <table class="memname"> <tr> <td class="memname">static <a class="el" href="structrttr_1_1wrapper__mapper.html#aef27f279c5b9dc07b35b4aea43d52e54">wrapped_type</a> <a class="el" href="structrttr_1_1wrapper__mapper.html">rttr::wrapper_mapper</a>< T >::get </td> <td>(</td> <td class="paramtype">const <a class="el" href="structrttr_1_1wrapper__mapper.html#aa31a021c9204019005f773f3936664ae">type</a> & </td> <td class="paramname"><em>obj</em></td><td>)</td> <td></td> </tr> </table> </td> <td class="mlabels-right"> <span class="mlabels"><span class="mlabel">inline</span><span class="mlabel">static</span></span> </td> </tr> </table> </div><div class="memdoc"> </div> </div> <hr/>The documentation for this struct was generated from the following file:<ul> <li><a class="el" href="wrapper__mapper_8h_source.html">wrapper_mapper.h</a></li> </ul> </div><!-- contents --> <!-- HTML footer for doxygen 1.8.9.1--> <!-- start footer part --> <hr class="footer"/> <address class="footer"> <small> Generated on Thu Apr 11 2019 20:06:00 for rttr - 0.9.6 by <a href="http://www.doxygen.org/index.html">doxygen</a>. </small> </address> </body> </html>