<!-- 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: Query information from rttr::type</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><!-- top --> <div class="PageDoc"><div class="header"> <div class="headertitle"> <div class="title">Query information from <a class="el" href="classrttr_1_1type.html" title="The type class holds the type information for any arbitrary object.">rttr::type</a> </div> </div> </div><!--header--> <div class="contents"> <div class="textblock"><p>A <a class="el" href="classrttr_1_1type.html">type</a> object contains automatically a lot of useful meta information, which exceeds the information of the standard <a href="http://en.cppreference.com/w/cpp/types/type_info" target="_blank">type_info</a> object.</p> <div class="fragment"><div class="line"><span class="keyword">struct </span>D { ... };</div><div class="line"></div><div class="line">type::get<D>().get_name(); <span class="comment">// returns 'struct D'; remark this is a compiler specific defined string (not portable)</span></div><div class="line">type::get<D>().is_class(); <span class="comment">// true</span></div><div class="line">type::get<D>().is_pointer(); <span class="comment">// false</span></div><div class="line">type::get<D*>().is_pointer(); <span class="comment">// true</span></div><div class="line">type::get<D>().is_array(); <span class="comment">// false</span></div><div class="line">type::get<D[50]>().is_array(); <span class="comment">// true</span></div><div class="line">type::get<std::vector<D>>().is_array(); <span class="comment">// true</span></div><div class="line">type::get<D>().is_arithmetic(); <span class="comment">// false</span></div><div class="line">type::get<D>().is_enumeration(); <span class="comment">// false</span></div></div><!-- fragment --><p>The returned name of the function <a class="el" href="classrttr_1_1type.html#a16d519457c68429ef2316067d1cf6700">get_name()</a> returns a compiler depended string. So don't use it directly when comparing with a string literal, but it is very useful for debugging purposes.</p> <p>This functionality gets more useful when working with other components like <a class="el" href="classrttr_1_1property.html">properties</a> or <a class="el" href="classrttr_1_1variant.html">variants</a>. For example: when you iterate over all properties of class you might not want to store the values of pointer types. Or you might want to group stuff together, like: <em>give me all primitive properties of a class</em> and so on.</p> <p>It is also possible to retrieve information about the inheritance graph of a class. </p><div class="fragment"><div class="line"><span class="keyword">struct </span>Base { <a class="code" href="rttr__enable_8h.html#a848bcae21d3a54e07ca6450689820a59">RTTR_ENABLE</a>() };</div><div class="line"><span class="keyword">struct </span>Derived : Base { <a class="code" href="rttr__enable_8h.html#a848bcae21d3a54e07ca6450689820a59">RTTR_ENABLE</a>(Base) };</div><div class="line"></div><div class="line">Derived d;</div><div class="line"></div><div class="line">std::vector<type> base_list = type::get(d).get_base_classes();</div><div class="line"></div><div class="line"><span class="keywordflow">for</span> (<span class="keyword">auto</span>& t : base_list)</div><div class="line"> std::cout << t.get_name() << std::endl; <span class="comment">// 'struct Base'</span></div></div><!-- fragment --><p>Or use a shorthand method to check if a type is derived from another:</p> <div class="fragment"><div class="line">type::get(d).is_derived_from<Base>(); <span class="comment">// true</span></div></div><!-- fragment --><p>The meta information presented in the first code snipped (e.g. <a class="el" href="classrttr_1_1type.html#a34296e0290e93317c34118945c0e2db9">is_class()</a>, <a class="el" href="classrttr_1_1type.html#a24a00513155d3e678454aa349b0caaa7">is_pointer()</a>) will work without registering anything manually to the type system. In order to retrieve class hierarchy informations, like <a class="el" href="classrttr_1_1type.html#aed9b001581881e62aaf794f456e405e7">get_base_classes()</a> or <a class="el" href="classrttr_1_1type.html#ac8484b0779404e55c3116ea5a1b894fa">is_derived_from()</a>, you will have to add manually some information to the type system. How this will be done, is discussed in the <a class="el" href="rttr_type_class_hierachy_page.html">next</a> chapter.</p> <h2>Summary </h2> <ul> <li>with a <a class="el" href="classrttr_1_1type.html">type</a> object you can retrieve additional meta information at runtime</li> </ul> <hr/> <div class="btn btn-default doxy-button"><a class="el" href="rttr_type_get_page.html">previous</a></div><div class="btn btn-default doxy-button"><a class="el" href="rttr_type_class_hierachy_page.html">next</a></div> </div></div><!-- PageDoc --> </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:05:57 for rttr - 0.9.6 by <a href="http://www.doxygen.org/index.html">doxygen</a>. </small> </address> </body> </html>