The Vish Visualization Shell 0.3
Vish
Public Member Functions | List of all members
Wizt::Enum Struct Reference

Enumeration type. More...

#include <ocean/shrimp/VEnum.hpp>

Inheritance diagram for Wizt::Enum:
MemCore::StrongPtr< Object, ObjectBase > MemCore::WeakPtr< Object, ObjectBase > MemCore::DynPtr< Object, ObjectBase >

Public Member Functions

bool addCase (const string &s)
 Add a possible choice to this enum. Usually only used during construction.
 
template<typename... Arguments>
bool addCase (const string &Value, Arguments... parameters)
 Recursive handling of parameter pack.
 
int 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 char *s8=0, const char *s9=0, const char *sa=0) const
 Find the enum entry in the given list of possible values, return the number in the entries.
 
 Enum ()
 Empy enum.
 
 Enum (const char *entries[], unsigned howmany)
 Initialize Enumeration type from list of strings.
 
 Enum (const MemCore::StringList &SL)
 Construct from a given string list.
 
 Enum (const string &path, char delimiter)
 Construct from a given string with delimiter character.
 
template<typename... Arguments>
 Enum (const string &s1, Arguments... parameters)
 
template<typename... Arguments>
 Enum (unsigned i, const string &s1, Arguments... parameters)
 
bool Equal (const string &what) const
 Check if the enumeration has the given value.
 
int iCase (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 char *s8=0, const char *s9=0, const char *sa=0) const
 Same as Case(), but using stricmp()
 
bool iEqual (const string &what) const
 Check if the enumeration has the given value, ignoring upper/lower case.
 
string operator() () const
 Get the currently selected enumeration string.
 
int operator() (const char *entries[], unsigned howmany) const
 Find the enum entry in the given list of possible values, return the number in the entries.
 
int operator() (const RefPtr< StringList > &SL) const
 Find the enum entry in the given list of possible values, return the number in the entries.
 
bool operator() (const string &what) const
 Check if the enumeration has the given value Same as calling Equal()
 
- Public Member Functions inherited from MemCore::StrongPtr< Object, ObjectBase >
StrongPtrassignStrong (const DynPtr_t &other)
 assign a strong pointer from a weak pointer
 
StrongPtrassignStrong (const ReferenceBase< ObjectBase_t > *Obj)
 assign a strong pointer from a native pointer
 
StrongPtrassignStrong (const std::nullptr_t &)
 Assign nullptr to a strong pointer, which will remove the referenced object if its counter reaches zero, but the pointer will remain a valid weak pointer with sustained hash value (the referer will still be around).
 
template<typename... Arguments>
auto operator() (Arguments...parameters) const -> decltype((*this->getPtrValue())(parameters...))
 Function call operator forwarding.
 
refvalue_t & operator* () const
 The dereferencing *-operator.
 
pointer_t operator-> () const
 The pointer operator.
 
StrongPtroperator= (const DynPtr_t &other)
 Assignment operator, same as assignStrong()
 
StrongPtroperator= (const ReferenceBase< ObjectBase_t > *Obj)
 Assignment from object base class pointer.
 
StrongPtroperator= (const std::initializer_list< StrongPtr > &other)
 Syntactic sugar: Allows assignment with {} to create a nullptr.
 
StrongPtroperator= (const std::nullptr_t &)
 Assignment operator with nullptr, invalidate.
 
StrongPtroperator= (const StrongPtr &other)
 Assignment operator, same as assignStrong()
 
template<class IndexType >
auto operator[] (const IndexType &I) const -> decltype((*this->getPtrValue())[I])
 Index operator forwarding.
 
 StrongPtr ()
 Default constructor (makes a NULL pointer)
 
 StrongPtr (const ReferenceBase< ObjectBase_t > *Obj)
 Strong pointer from reference base of object, eg. via new operator.
 
 StrongPtr (const ReferenceBase< ObjectBase_t > *Obj, const NotNullPtr &)
 Strong pointer from reference base of object, eg. via new operator.
 
 StrongPtr (const std::nullptr_t &)
 Explicitely construct a nullptr pointer.
 
template<class ChildObject >
 StrongPtr (const StrongPtr< ChildObject, ObjectBase > &Other)
 Reference pointer with dynamic type identification.
 
 StrongPtr (const StrongPtr< Object, ObjectBase > &Other)
 Copy constructor.
 
template<class ChildObject >
 StrongPtr (const WeakPtr< ChildObject, ObjectBase_t > &Other)
 Reference pointer with dynamic type identification.
 
 ~StrongPtr ()
 Destructor, the last one cleans up and destructs the object itself.
 
- Public Member Functions inherited from MemCore::WeakPtr< Object, ObjectBase >
pointer_t getPtrValue () const
 The pointer value, checked for null.
 
pointer_t operator-> () const
 The pointer operator.
 
refvalue_toperator* () const
 The dereferencing *-operator.
 
size_t operator~ () const
 Convenience operator to easily retrieve the object count ID of the referenced object, a unique number for each instance.
 
 WeakPtr ()
 Default constructor, makes a NULL pointer.
 
 WeakPtr (const std::nullptr_t &)
 Explicitely construct NULL pointer.
 
 WeakPtr (const ReferenceBase< ObjectBase > *Obj)
 Weak pointer from reference base of object.
 
 WeakPtr (const ReferenceBase< ObjectBase > *Obj, const NotNullPtr &)
 Weak pointer from reference base of object which must not be null.
 
template<class AnyObject >
 WeakPtr (const WeakPtr< AnyObject, ObjectBase > &Other)
 Weak pointer from pointer to another class.
 
 WeakPtr (const WeakPtr &Other)
 Copy constructor.
 
 ~WeakPtr ()
 Default destructor, removes weak references to the object, the last one cleans up the referrer proxy object.
 
WeakPtrassignWeak (const WeakPtr &other)
 Assign a weak pointer (explicit function call, same as assignment operator for weak pointers)
 
WeakPtroperator= (const WeakPtr &other)
 Assignment operator (same as assignWeak() )
 
- Public Member Functions inherited from MemCore::DynPtr< Object, ObjectBase >
const DynPtrgetDynPtr () const noexcept
 Convenience type cast to dynamic pointer class.
 
const type_info & getType () const noexcept
 Return type info of associated object, typeid(NullPtr) or typeid(void) if none.
 
bool isAssignable (const DynPtr< ObjectBase, ObjectBase > &Other) const noexcept
 Check whether a given pointer to a base class may be assigned to a pointer of the derived class.
 
 operator void * () const noexcept
 Check if the pointer is valid.
 
bool operator! () const noexcept
 Check if the pointer is invalid.
 
void speak (const char *s, const char *prefix="") const noexcept
 Print some debug messages to the console.
 

Additional Inherited Members

- Public Types inherited from MemCore::StrongPtr< Object, ObjectBase >
typedef WeakPtr< Object, ObjectBase >::ObjectBase_t ObjectBase_t
 Exporting the base class of the reference counted objects.
 
- Public Types inherited from MemCore::WeakPtr< Object, ObjectBase >
typedef Object object_t
 Exporting the type of the derived class.
 
typedef ObjectBase ObjectBase_t
 Exporting the type of the base class.
 
typedef RefPtrTypeTrait< Object, ObjectBase >::ReferencePointerType pointer_t
 The result type of the pointer operator, may be changed with the RefPtrTypeTrait<> class.
 
typedef RefPtrTypeTrait< Object, ObjectBase >::ReferenceValueType refvalue_t
 The result of the dereferencing operator, may be changed with the RefPtrTypeTrait<> class.
 
- Public Types inherited from MemCore::DynPtr< Object, ObjectBase >
typedef Object object_t
 Type of the associated object.
 
- Static Public Member Functions inherited from MemCore::WeakPtr< Object, ObjectBase >
- Static Public Member Functions inherited from MemCore::DynPtr< Object, ObjectBase >
static const DynPtrgetNullPtr () noexcept
 Associated static NullPtr - avoids creation of a temporary object when a reference is needed.
 
- Protected Member Functions inherited from MemCore::WeakPtr< Object, ObjectBase >
 WeakPtr (Object *that, const SelfInitialize &)
 Internal constructor used when initializing an object with its own self-reference.
 
- Protected Member Functions inherited from MemCore::DynPtr< Object, ObjectBase >
template<class AnyObject >
 DynPtr (const DynPtr< AnyObject, ObjectBase > &Other) noexcept
 Implicit type conversion within the same class hierarchy Any pointer.
 
 DynPtr (const std::nullptr_t &) noexcept
 Assign from nullptr.
 

Detailed Description

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) )
{}
bool update(VRequest&R, double precision) override
{
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") )
{
...
}
}
};

Constructor & Destructor Documentation

◆ Enum() [1/2]

template<typename... Arguments>
Wizt::Enum::Enum ( const string &  s1,
Arguments...  parameters 
)
inline
       Create an enum type with its possible selections given
       as strings, for instance:
Enum( "coarse", "fine", "both")
Enum()
Empy enum.
Definition VEnum.hpp:159

◆ Enum() [2/2]

template<typename... Arguments>
Wizt::Enum::Enum ( unsigned  i,
const string &  s1,
Arguments...  parameters 
)
inline
       Create an enum type with a value selected from its possible 
       selections given  as strings, for instance:
Enum(1, "coarse", "fine", "both")

This will set "fine" as pre-selection. Counting starts at zero, as in C.

Member Function Documentation

◆ Case()

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 char *  s8 = 0,
const char *  s9 = 0,
const char *  sa = 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
}
Enumeration type.
Definition VEnum.hpp:141
int 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 char *s8=0, const char *s9=0, const char *sa=0) const
Find the enum entry in the given list of possible values, return the number in the entries.
Definition VEnum.cpp:304