Skip to content

Commit 3a63a71

Browse files
Doc
1 parent 1a8af87 commit 3a63a71

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

dev-docs/source/EnumeratedString.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ However, this is not allowed under C++.
2121

2222
The ``EnumeratedString`` objects allow for binding an ``enum`` or ``enum class`` to a vector of strings, allowing for much
2323
of the same behavior. This allows for easy-to-read ``if`` and ``switch`` statements, as well as easy conversions and assignments
24-
with strings from the allowed set. This further adds an additional layer of validation for string properties, in additon to the
24+
with strings from the allowed set. This further adds an additional layer of validation for string properties, in addition to the
2525
``StringListValidator`` used in the property declaration.
2626

2727
How to use the EnumeratedString
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
.. _EnumeratedStringProperty:
2+
3+
What is EnumeratedStringProperty?
4+
---------------------------------
5+
6+
``EnumeratedStringProperty`` allows the use of ``EnumeratedString`` objects within the Property structure framework.
7+
8+
How to use the EnumeratedStringProperty
9+
---------------------------------------
10+
11+
Include the ``EnumeratedStringProperty.h`` header file. Set up the ``EnumeratedStringProperty`` as follows:
12+
13+
.. code-block:: cpp
14+
15+
namespace {
16+
const std::vector<std::string> binningModeNames{"Default", "Linear", "Logarithmic", "ReverseLogarithmic", "Power"};
17+
enum class BinningMode { DEFAULT, LINEAR, LOGARITHMIC, REVERSELOG, POWER, enum_count };
18+
typedef Mantid::Kernel::EnumeratedString<BinningMode, &binningModeNames> BINMODE;
19+
} // namespace
20+
21+
Declare property:
22+
23+
.. code-block:: cpp
24+
25+
declareProperty(
26+
std::make_unique<EnumeratedStringProperty<BinningMode, &binningModeNames>>("PropertyName"),
27+
"Description"
28+
);
29+
30+
Use declared property:
31+
32+
.. code-block:: cpp
33+
34+
BINMODE binMode = someName;
35+
if (binMode == BinningMode::LINEAR)
36+
do_something();
37+
else if (binMode != "Default")
38+
do_something_else();
39+
40+
Determining and using pre-set mode, if present, or using the default setting:
41+
42+
.. code-block:: cpp
43+
44+
BINMODE binMode;
45+
if (existsProperty("PropertyName"))
46+
Mode = getPropertyValue("PropertyName");
47+
else
48+
Mode = "Default";
49+
50+
Example Use of EnumeratedString
51+
-------------------------------
52+
53+
Please see examples of usage in ``Rebin.cpp``, ``CalculateDIFC.cpp``, and ``AddSampleLog.cpp``.

dev-docs/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ Component Overviews
273273

274274
BatchWidget/index
275275
EnumeratedString
276+
EnumeratedStringProperty
276277
EventWorkspaceDev
277278
HandlingXML
278279
IndexProperty

0 commit comments

Comments
 (0)