diff --git a/src_main/core/pivarianttypes.h b/src_main/core/pivarianttypes.h index 1a22682b..deced4e1 100644 --- a/src_main/core/pivarianttypes.h +++ b/src_main/core/pivarianttypes.h @@ -33,28 +33,92 @@ class PIPropertyStorage; namespace PIVariantTypes { + /** + * @brief name-value pair + */ struct PIP_EXPORT Enumerator { Enumerator(int v = 0, const PIString & n = PIString()): value(v), name(n) {} int value; PIString name; }; + /** + * @brief Collection of PIVariantTypes::Enumerator. It's replace classic c-style enum. + * Contains elements with unique name and not uniqueue values. + */ struct PIP_EXPORT Enum { Enum(const PIString & n = PIString()): enum_name(n) {} PIString toString() const {return selected;} // obsolete + + /** + * @brief Find selected value. + * @return selected value, otherwrise 0 + */ int selectedValue() const; + + /** + * @brief Get selected name + * @return selected name, otherwrise empty PIString + */ PIString selectedName() const {return selected;} + + /** + * @brief Select value if exists in Enum. If Enum contains several PIVariantTypes::Enumerator with same values, + * first PIVariantTypes::Enumerator will selected + * @param v value for selection + * @return true if value exists in Enum, false otherwrise + */ bool selectValue(int v); + + /** + * @brief Select name if exists in enum + * @param n name for selection + * @return true if name exists in Enum, false otherwrise + */ bool selectName(const PIString & n); + + /** + * @brief Find PIVariantTypes::Enumerator with specific name and return it value + * @param n name for search + * @return value of founded PIVariantTypes::Enumerator, 0 otherwrise + */ int value(const PIString & n) const; + + /** + * @brief Find first PIVariantTypes::Enumerator with specific value and return it name + * @param v value for search + * @return name of founded PIVariantTypes::Enumerator, empty string otherwrise + */ PIString name(int v) const; + + /** + * @brief Make vector of Enum values + */ PIVector values() const; + + /** + * @brief Make vector of Enum names + */ PIStringList names() const; PIString enum_name; PIString selected; PIVector enum_list; + + /** + * @brief Add PIVariantTypes::Enumerator to Enum + */ Enum & operator <<(const Enumerator & v); + + /** + * @brief Add PIVariantTypes::Enumerator element to Enum. Element contains specific name and value more per + * unit then last element. If the is no elements, contains zero value. + * @param v name for new PIVariantTypes::Enumerator element + */ Enum & operator <<(const PIString & v); + + /** + * @brief Add PIVariantTypes::Enumerator element for each name in vector + */ Enum & operator <<(const PIStringList & v); };