Skip to content

Commit

Permalink
Automatic update of developer site
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-builder committed Oct 16, 2023
1 parent 5d9e236 commit e23cf63
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions EnumeratedString.html
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ <h2><a class="toc-backref" href="#id2" role="doc-backlink">Why EnumeratedString?
</pre></div>
</div>
<p>However, this is not allowed under C++.</p>
<p>The <code class="docutils literal notranslate"><span class="pre">EnumeratedString</span></code> objects allow for binding an <code class="docutils literal notranslate"><span class="pre">enum</span> <span class="pre">class</span></code> to a C-style static array of strings, allowing for much
<p>The <code class="docutils literal notranslate"><span class="pre">EnumeratedString</span></code> objects allow for binding an <code class="docutils literal notranslate"><span class="pre">enum</span></code> or <code class="docutils literal notranslate"><span class="pre">enum</span> <span class="pre">class</span></code> to a vector of strings, allowing for much
of the same behavior. This allows for easy-to-read <code class="docutils literal notranslate"><span class="pre">if</span></code> and <code class="docutils literal notranslate"><span class="pre">switch</span></code> statements, as well as easy conversions and assignments
with strings from the allowed set. This further adds an additional layer of validation for string properties, in additon to the
<code class="docutils literal notranslate"><span class="pre">StringListValidator</span></code> used in the property declaration.</p>
Expand Down Expand Up @@ -160,6 +160,12 @@ <h2><a class="toc-backref" href="#id3" role="doc-backlink">How to use the Enumer
<p>Notice that the final element of the <code class="docutils literal notranslate"><span class="pre">enum</span></code> is called <code class="code docutils literal notranslate"><span class="pre">enum_count</span></code>. This is mandatory. This element indicates the
number of elements inside the <code class="docutils literal notranslate"><span class="pre">enum</span></code>, and used for verifying compatibility with the vector of strings. A compiler error
will be triggered if this is not included.</p>
<p>Further, the <code class="docutils literal notranslate"><span class="pre">enum</span></code> <em>must</em> have elements in order from 0 to <code class="code docutils literal notranslate"><span class="pre">enum_count</span></code>. That is, you <em>CANNOT</em> set them like so:
.. code-block:: cpp</p>
<blockquote>
<div><p>enum class CakeTypeEnum : char {LEMON=’l’, BUNDT=’b’, POUND=’p’, enum_count=3}; // NOT ALLOWED</p>
</div></blockquote>
<p>as this will break validation features inside the class.</p>
<p>Notice the use of the reference operator, <code class="code docutils literal notranslate"><span class="pre">&amp;cakeTypeNames</span></code>, and <em>not</em> <code class="code docutils literal notranslate"><span class="pre">cakeTypeNames</span></code>.</p>
<p>In the above code, a <code class="code docutils literal notranslate"><span class="pre">CAKETYPE</span></code> object can be created either from a <code class="code docutils literal notranslate"><span class="pre">CakeTypeEnum</span></code>, or from one of the strings
in the <code class="code docutils literal notranslate"><span class="pre">cakeTypeNames</span></code> array (either by the literal, or by accessig it in the array), or from another <code class="code docutils literal notranslate"><span class="pre">CAKETYPE</span></code>
Expand Down Expand Up @@ -190,7 +196,7 @@ <h2><a class="toc-backref" href="#id4" role="doc-backlink">Example Use of Enumer

<span class="kt">void</span><span class="w"> </span><span class="nf">BakeCake::exec</span><span class="p">()</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="c1">// this will assign cakeType from the string property</span>
<span class="w"> </span><span class="n">CAKETYPE</span><span class="w"> </span><span class="n">cakeType</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">getProperty</span><span class="p">(</span><span class="s">&quot;CakeType&quot;</span><span class="p">);</span>
<span class="w"> </span><span class="n">CAKETYPE</span><span class="w"> </span><span class="n">cakeType</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">getPropertyValue</span><span class="p">(</span><span class="s">&quot;CakeType&quot;</span><span class="p">);</span>

<span class="w"> </span><span class="c1">// logic can branch on cakeType comparing to the enum</span>
<span class="w"> </span><span class="k">switch</span><span class="p">(</span><span class="n">cakeType</span><span class="p">){</span>
Expand Down
2 changes: 1 addition & 1 deletion searchindex.js

Large diffs are not rendered by default.

0 comments on commit e23cf63

Please sign in to comment.