<!-- 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: Enums</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">Enums </div> </div> </div><!--header--> <div class="contents"> <div class="textblock"><p>RTTR allows also to register enumerated constants (enums). Therefore use the function <a class="el" href="classrttr_1_1registration.html#ae185f4e001154c4d95a3901bcbd6e234">registration::enumeration()</a>.</p> <p>It has following synopsis:</p> <div class="fragment"><div class="line"><span class="keyword">template</span><<span class="keyword">typename</span> Enum_Type></div><div class="line">registration <a class="code" href="classrttr_1_1registration.html#ae185f4e001154c4d95a3901bcbd6e234">rttr::registration::enumeration</a>( <a class="code" href="namespacerttr.html#a61265f69675ac438ecfa23b084adaa56">string_view</a> name );</div></div><!-- fragment --><ul> <li><code>name</code> the declared name of this enum</li> </ul> <div class="fragment"><div class="line"><span class="preprocessor">#include <rttr/registration></span></div><div class="line"><span class="keyword">using namespace </span><a class="code" href="namespacerttr.html">rttr</a>;</div><div class="line"></div><div class="line"><span class="keyword">enum class</span> E_Alignment</div><div class="line">{</div><div class="line"> AlignLeft = 0x0001,</div><div class="line"> AlignRight = 0x0002,</div><div class="line"> AlignHCenter = 0x0004,</div><div class="line"> AlignJustify = 0x0008</div><div class="line">};</div><div class="line"></div><div class="line"><a class="code" href="registration_8h.html#ac6326400f16225ee15b52eabcaae8130">RTTR_REGISTRATION</a></div><div class="line">{</div><div class="line"> registration::enumeration<E_Alignment>(<span class="stringliteral">"E_Alignment"</span>)</div><div class="line"> (</div><div class="line"> <a class="code" href="namespacerttr.html#a54ecd8bad715cbc451e7aa8491667d4a">value</a>(<span class="stringliteral">"AlignLeft"</span>, E_Alignment::AlignLeft),</div><div class="line"> <a class="code" href="namespacerttr.html#a54ecd8bad715cbc451e7aa8491667d4a">value</a>(<span class="stringliteral">"AlignRight"</span>, E_Alignment::AlignRight),</div><div class="line"> <a class="code" href="namespacerttr.html#a54ecd8bad715cbc451e7aa8491667d4a">value</a>(<span class="stringliteral">"AlignHCenter"</span>, E_Alignment::AlignHCenter),</div><div class="line"> <a class="code" href="namespacerttr.html#a54ecd8bad715cbc451e7aa8491667d4a">value</a>(<span class="stringliteral">"AlignJustify"</span>, E_Alignment::AlignJustify)</div><div class="line"> );</div><div class="line">}</div></div><!-- fragment --><p> In order to add the individual enumerators you have to use the <code>()</code> operator of the returned <a class="el" href="classrttr_1_1registration_1_1bind.html">bind</a> object. Then you call for every enumerator you want to add, the function <a class="el" href="namespacerttr.html#a54ecd8bad715cbc451e7aa8491667d4a">value()</a>.</p> <p>It has following synopsis: </p><div class="fragment"><div class="line"><span class="keyword">template</span><<span class="keyword">typename</span> Enum_Type></div><div class="line">detail::enum_data<Enum_Type> <a class="code" href="namespacerttr.html#a54ecd8bad715cbc451e7aa8491667d4a">value</a>(<a class="code" href="namespacerttr.html#a61265f69675ac438ecfa23b084adaa56">string_view</a> name, Enum_Type <a class="code" href="namespacerttr.html#a54ecd8bad715cbc451e7aa8491667d4a">value</a>);</div></div><!-- fragment --><p>The <em>name</em> is a <code>string_view</code> and the <em>value</em> is the enum value.</p> <p>The class <a class="el" href="classrttr_1_1enumeration.html">enumeration</a> contains several meta information about an enum with conversion functions between the value representation and its literal representation.</p> <p>How to use the enumeration class shows following example: </p><div class="fragment"><div class="line"><span class="keyword">using namespace </span><a class="code" href="namespacerttr.html">rttr</a>; </div><div class="line"><a class="code" href="classrttr_1_1type.html">type</a> enum_type = <a class="code" href="classrttr_1_1type.html#a7ba79b9f4916c30db74fe65508dca033">type::get_by_name</a>(<span class="stringliteral">"E_Alignment"</span>);</div><div class="line"><span class="keywordflow">if</span> (enum_type && enum_type.<a class="code" href="classrttr_1_1type.html#a60e41c2c736ed5ce3198a84da9af4d6d">is_enumeration</a>())</div><div class="line">{</div><div class="line"> <a class="code" href="classrttr_1_1enumeration.html">enumeration</a> enum_align = enum_type.<a class="code" href="classrttr_1_1type.html#aa0b0e3e85de99df74f956a84b463f10b">get_enumeration</a>();</div><div class="line"> std::string name = enum_align.<a class="code" href="classrttr_1_1enumeration.html#a250cafc29edef91c37dda0cd3e0334ce">value_to_name</a>(E_Alignment::AlignHCenter);</div><div class="line"> std::cout << name; <span class="comment">// prints "AlignHCenter"</span></div><div class="line"> </div><div class="line"> <a class="code" href="classrttr_1_1variant.html">variant</a> var = enum_align.<a class="code" href="classrttr_1_1enumeration.html#ae5c72df6db7319bcd85b52a689e72dfd">name_to_value</a>(name);</div><div class="line"> E_Alignment <a class="code" href="namespacerttr.html#a54ecd8bad715cbc451e7aa8491667d4a">value</a> = var.<a class="code" href="classrttr_1_1variant.html#aa3a9f7e07cdc4d922a4e09882c5c0574">get_value</a><E_Alignment>(); <span class="comment">// stores value 'AlignHCenter'</span></div><div class="line">}</div></div><!-- fragment --><dl class="section remark"><dt>Remarks</dt><dd>You can also use the <a class="el" href="classrttr_1_1variant.html">variant</a> class to convert from an enum value to is integral or string representation. <div class="fragment"><div class="line">variant var = E_Alignment::AlignHCenter;</div><div class="line">std::cout << var.<a class="code" href="classrttr_1_1variant.html#ae5acffcd7dcbe87d0d976e37a815ab43">to_int</a>() << std::endl; <span class="comment">// prints '4'</span></div><div class="line">std::cout << var.to_string() << std::endl; <span class="comment">// prints 'AlignHCenter'</span></div></div><!-- fragment --> <hr/> </dd></dl> <div type="button" class="btn btn-default doxy-button"><a class="el" href="register_properties_page.html">previous</a></div><div class="btn btn-default doxy-button"><a class="el" href="register_variant_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>