VISH
0.2
|
Enumeration type. More...
#include </home/werner/origo/vish/ocean/shrimp/VEnum.hpp>
Enumeration type.
Enumeration types are a list of strings out of which one element can be selected. Application code needs to check for the existence of a specific string. Note that enumeration types can be shared with any other enumeration type, so the requested match might possibly not be contained in the input list. As of now there is no way to prevent connecting incompatible enumeration types.
To ease the use of enum's some mechanisms are provided that allow using the enumeration value as part of a switch() statement similar to a native string.
static const char* operations[] = { "add", "sub", "mult", "div", "pow", "max", "min" }; enum { ADD , SUB , MULT , DIV , POW , MAX , MIN }; class MyObject : public VObject { TypedSlot<Enum> Operation; public: MyObject(...) : VObject(...) , Operation(this, "operation", Enum( operations, 7) ) {} override bool update(VRequest&R, double precision) { Enum operation; Operation << R >> operation; switch( operation(operations, 7) ) { case ADD: r = x + m; break; case SUB: r = x - m; break; case MULT: r = x * m; break; case DIV: r = x / m; break; case POW: r = pow(x, m); break; case MAX: r = (x > m)? x:m; break; case MIN: r = (x < m)? x:m; break; default: break; } if (operation("add") ) { ... } } };
int Wizt::Enum::Case | ( | const char * | s0, |
const char * | s1 = 0 , |
||
const char * | s2 = 0 , |
||
const char * | s3 = 0 , |
||
const char * | s4 = 0 , |
||
const char * | s5 = 0 , |
||
const char * | s6 = 0 , |
||
const char * | s7 = 0 |
||
) | const |
Find the enum entry in the given list of possible values, return the number in the entries.
VEnum enumValue; switch(enumValue.Case("a", "b", "c") ) { case 0: // a case 1: // b case 2: // c case -1: // not found }