|
| 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``. |
0 commit comments