mbo::enumset

Author:
Marcus Boerger (http://marcus-boerger.de/)

Name: enumset.hpp

The template class mbo::enumset has been tested under:

  • Linux with GCC 2.96 and 3.2
  • Cygwin GCC 3.2
  • WinXP with MSVC.NET

Note:
This file is distributed under the following license enumset License .

You can download the actual version of this file here:
http://marcus-boerger.de/cpp/enumset/enumset.tar.bz2

If you do not have doxygen you can also download this documentation as a chm file here:
http://marcus-boerger.de/cpp/enumset/doc/enumset.chm
or view it online here:
marcus-boerger.de/cpp/enumset/doc/html/

Generated on Wed Jan 15 18:34:06 2003 for Enumset by doxygen 1.3-rc2


enumset.hpp File Reference

template mbo::enumset: a set template that works with enum types. More...

#include <stdarg.h>
#include <exception>

Include dependency graph for enumset.hpp:

Include dependency graph

Go to the source code of this file.

Namespaces

namespace | mbo

Defines

#define | _Ty_list_default size_t
#define | _Ty_args_default int

Detailed Description

template mbo::enumset: a set template that works with enum types.

Author:
Marcus Boerger (http://marcus-boerger.de/)

Name: enumset.hpp

The template class mbo::enumset has been tested under:

  • Linux with GCC 2.96 and 3.2
  • Cygwin GCC 3.2
  • WinXP with MSVC.NET

Note:
This file is distributed under the following license enumset License .

You can download the actual version of this file here:
http://marcus-boerger.de/cpp/enumset/enumset.tar.bz2

If you do not have doxygen you can also download this documentation as a chm file here:
http://marcus-boerger.de/cpp/enumset/doc/enumset.chm
or view it online here:
marcus-boerger.de/cpp/enumset/doc/html/

Define Documentation

#define _Ty_args_default int

default type used for parameter transport in '...' function calls

See also:
mbo::enumset

#define _Ty_list_default size_t

default type internally used to represent the set of enum values

See also:
mbo::enumset

Generated on Wed Jan 15 18:34:07 2003 for Enumset by doxygen 1.3-rc2


mbo::demap_value_exception Class Reference

base for exceptions thrown in mbo::enumset::to_enum More...

#include <enumset.hpp>

Inheritance diagram for mbo::demap_value_exception:

[legend]
Collaboration diagram for mbo::demap_value_exception:

[legend]

Detailed Description

base for exceptions thrown in mbo::enumset::to_enum

this exception is thrown when an mbo::enumset instance which does not hold exactly one value is going to be converted to its enum type

The documentation for this class was generated from the following file:
  • enumset.hpp
Generated on Wed Jan 15 18:34:07 2003 for Enumset by doxygen 1.3-rc2


mbo::empty_value_exception Class Reference

exception thrown in mbo::enumset conversion More...

#include <enumset.hpp>

Inheritance diagram for mbo::empty_value_exception:

[legend]
Collaboration diagram for mbo::empty_value_exception:

[legend]

Detailed Description

exception thrown in mbo::enumset conversion

this exception is thrown when an empty mbo::enumset instance (one which holds none of the set values) is going to be converted to its enum type

The documentation for this class was generated from the following file:
  • enumset.hpp
Generated on Wed Jan 15 18:34:08 2003 for Enumset by doxygen 1.3-rc2


Templatembo::enumset< _TEnum, _Ty_list, _Ty_args > class Reference

mbo::enumset< _TEnum, _Ty_list, _Ty_args > Class Template Reference

A set template that works with enum types. More...

#include <enumset.hpp>

List of all members.

Public Types

typedef _TEnum | TEnum
typedef _Ty_list | Ty_list
typedef _Ty_args | Ty_args

Public Methods

enumset ()
enumset (const enumset &set)
enumset (size_t count,...) throw (input_range_exception)
enumset (const TEnum &value) throw (input_range_exception)
bool | contains (const TEnum &value) const
bool | contains (const enumset &set) const
int | count () const
enumset & | clear ()
enumset & | operator= (const TEnum &value) throw (input_range_exception)
enumset & | operator= (const enumset &set)
enumset & | operator+= (const TEnum &value) throw (input_range_exception)
enumset & | operator+= (const enumset &set)
enumset | operator+ (const TEnum &value) const
enumset | operator+ (const enumset &set) const
enumset & | operator-= (const TEnum &value) throw (input_range_exception)
enumset & | operator-= (const enumset &set)
enumset | operator- (const TEnum &value) const
enumset | operator- (const enumset &set) const
enumset & | operator *= (const TEnum &value) throw (input_range_exception)
enumset & | operator *= (const enumset &set)
enumset | operator * (const TEnum &value) const
enumset | operator * (const enumset &set) const
enumset & | operator^= (const TEnum &value) throw (input_range_exception)
enumset & | operator^= (const enumset &set)
enumset | operator^ (const TEnum &value) const
enumset | operator^ (const enumset &set) const
bool | operator & (const TEnum &value) const throw (input_range_exception)
bool | operator & (const enumset &set) const
bool | operator== (const TEnum &value) const throw (input_range_exception)
bool | operator== (const enumset &set) const
bool | operator!= (const TEnum &value) const throw (input_range_exception)
bool | operator!= (const enumset &set) const
bool | operator< (const TEnum &value) const throw (input_range_exception)
bool | operator< (const enumset &set) const
bool | operator<= (const TEnum &value) const throw (input_range_exception)
bool | operator<= (const enumset &set) const
bool | operator> (const TEnum &value) const throw (input_range_exception)
bool | operator> (const enumset &set) const
bool | operator>= (const TEnum &value) const throw (input_range_exception)
bool | operator>= (const enumset &set) const
Ty_list | to_set () const
operator Ty_list () const
TEnum | to_enum () const throw (demap_value_exception, multi_value_exception, multi_value_exception)
operator TEnum () const throw (demap_value_exception, multi_value_exception, multi_value_exception)

Private Methods

enumset & | operator~ (void) throw (operator_na_exception)
Ty_list | map (Ty_list value) const throw (input_range_exception)
Ty_list | demap (Ty_list value) const throw (demap_value_exception, multi_value_exception, empty_value_exception)

Private Attributes

Ty_list list

Detailed Description

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
class mbo::enumset< _TEnum, _Ty_list, _Ty_args >

A set template that works with enum types.

Note:
This template class is distributed under the following license enumset License .
operators: + - * = += -= *=

  • + : OR, union
  • - : exception/minus
  • * : AND, intersection
  • ^ : XOR

boolean operators: < <= > >= == !=

The boolean operators are overloaded to behave as known from set theory.

There are two possible number (scalar) conversions:

  • you may want to convert the instance to the numberic value internally used by calling to_set.
  • it is also possible to convert the instance back to the enum value by use of to_enum which requires the instance holds exactly one value.

All operators accept same mbo::enumset type as well as any enum value of the enum type used to construct the class.

Note:
The maximum value in TEnum must be less than or equal to the number of bits in type _Ty_list which defaults to size_t (platform dependant: 16, 32 or 64 bits).
When using numeric constants with mbo::enumset derived by enum the compiler generates warnings of type 'no match ... candidates'. The behaviour of passing non enum types or non scalar types as template type is neither intended nor tested.

Note:
The operator ~ is missing because the constructor cannot be informed about all set members available.
Example:
  #include "enumset.hpp"

  typedef enum {a,b,c} TEnum;
  typedef mbo::enumset<TEnum> TSet;

  TSet es;       // []

  es += a;       // [a]    addition, union
  es  = es + b;  // [a,b]
  es += es;      // [a,b]
  es *= b;       // [b]    intersection
  es  = es + c;  // [b,c]
  es -= b;       // [c]    minus
  es.clear();    // []
  printf("%d", (int)es);   // since size_t converts to int automatically

Note:
You can find more complex examples in enumset example 1 and enumset example 2 .
Parameters:
_TEnum Specifies the enum type used to construct the class.
_Ty_list Defaults to size_t. You may want to either override this type for selective template instances or globally by defining the macro _Ty_list_default before including the header file enumset.hpp.
For example you may want to use the type long long to be able to use 64 values if a) your compiler knows that type and b) size_t only uses 4 bytes which allows only 32 values.
_Ty_args Defaults to int. It my be necessary to override the type used to transport parameters in '...' functions. Normally the compiler uses the type int for enum types but most compilers allow to overwrite this behaviour.
It may be necessary to override this type for selective classes or globally by defining the macro _Ty_args_default before including the file enumset.hpp.

Member Typedef Documentation

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
typedef _TEnum mbo::enumset< _TEnum, _Ty_list, _Ty_args >::TEnum

the enum type used to instanciate the template

see notes on template parameters

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
typedef _Ty_args mbo::enumset< _TEnum, _Ty_list, _Ty_args >::Ty_args

type used for parameter transport in '...' function calls

see notes on template parameters

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
typedef _Ty_list mbo::enumset< _TEnum, _Ty_list, _Ty_args >::Ty_list

type internally used to represent the set of enum values

see notes on template parameters

Constructor & Destructor Documentation

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
mbo::enumset< _TEnum, _Ty_list, _Ty_args >::enumset ( ) [inline]

empty constructor

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
mbo::enumset< _TEnum, _Ty_list, _Ty_args >::enumset ( const enumset< _TEnum, _Ty_list, _Ty_args > & set ) [inline]

copy constructor

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
mbo::enumset< _TEnum, _Ty_list, _Ty_args >::enumset | ( | size_t | count,
 |  | ... |
 | ) | throw (input_range_exception) [inline, explicit]

dynamic construction

Parameters:
count numer of enum values that follow
... enum parameters, count times

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
mbo::enumset< _TEnum, _Ty_list, _Ty_args >::enumset ( const TEnum & value ) throw (input_range_exception) [inline]

constructor using a const type reference

Parameters:
value Value to store in the instance

Member Function Documentation

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
enumset& mbo::enumset< _TEnum, _Ty_list, _Ty_args >::clear ( ) [inline]

Clear the mbo::enumset (make it empty)

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
bool mbo::enumset< _TEnum, _Ty_list, _Ty_args >::contains ( const enumset< _TEnum, _Ty_list, _Ty_args > & set ) const [inline]

Check whether or not the value of another mbo::enumset is contained in the mbo::enumset

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
bool mbo::enumset< _TEnum, _Ty_list, _Ty_args >::contains ( const TEnum & value ) const [inline]

Check whether or not a specific value is contained in the mbo::enumset

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
int mbo::enumset< _TEnum, _Ty_list, _Ty_args >::count ( ) const [inline]

Number of single values held by the mbo::enumset

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
Ty_list mbo::enumset< _TEnum, _Ty_list, _Ty_args >::demap ( Ty_list value ) const throw (demap_value_exception, multi_value_exception, empty_value_exception) [inline, private]

converts a value into mapping represenation

Parameters:
value to convert
Returns:
map representation used internally
Exceptions:
multi_value_exception | if the set contains more than one enum values
empty_value_exception | if the set is empty
Note:
you may use demap_value_exception to write a combined handler

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
Ty_list mbo::enumset< _TEnum, _Ty_list, _Ty_args >::map ( Ty_list value ) const throw (input_range_exception) [inline, private]

converts a value into mapping represenation

Parameters:
value to convert
Returns:
map representation used internally
Exceptions:
input_range_exception if input exceeds allowed range

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
bool mbo::enumset< _TEnum, _Ty_list, _Ty_args >::operator & ( const enumset< _TEnum, _Ty_list, _Ty_args > & set ) const [inline]

Check whether or not the mbo::enumset is empty

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
bool mbo::enumset< _TEnum, _Ty_list, _Ty_args >::operator & ( const TEnum & value ) const throw (input_range_exception) [inline]

Check whether or not the mbo::enumset is empty

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
enumset mbo::enumset< _TEnum, _Ty_list, _Ty_args >::operator * ( const enumset< _TEnum, _Ty_list, _Ty_args > & set ) const [inline]

Intersection

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
enumset mbo::enumset< _TEnum, _Ty_list, _Ty_args >::operator * ( const TEnum & value ) const [inline]

Intersection

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
enumset& mbo::enumset< _TEnum, _Ty_list, _Ty_args >::operator *= ( const enumset< _TEnum, _Ty_list, _Ty_args > & set ) [inline]

Intersection assignment

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
enumset& mbo::enumset< _TEnum, _Ty_list, _Ty_args >::operator *= ( const TEnum & value ) throw (input_range_exception) [inline]

Intersection assignment

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
mbo::enumset< _TEnum, _Ty_list, _Ty_args >::operator TEnum ( ) const throw (demap_value_exception, multi_value_exception, multi_value_exception) [inline]

Conversion to enum value

When working with enum's this method returns a single enum value of the type used to instanciate this template class.

See also:
to_enum()
Returns:
enum value
Exceptions:
multi_value_exception | if the set contains more than one enum values
empty_value_exception | if the set is empty
Note:
you may use demap_value_exception to write a combined handler

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
mbo::enumset< _TEnum, _Ty_list, _Ty_args >::operator Ty_list ( ) const [inline]

Conversion to a number

Returns:
internal representation

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
bool mbo::enumset< _TEnum, _Ty_list, _Ty_args >::operator!= ( const enumset< _TEnum, _Ty_list, _Ty_args > & set ) const [inline]

NE: NON-Equivalence operator

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
bool mbo::enumset< _TEnum, _Ty_list, _Ty_args >::operator!= ( const TEnum & value ) const throw (input_range_exception) [inline]

NE: NON-Equivalence operator

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
enumset mbo::enumset< _TEnum, _Ty_list, _Ty_args >::operator+ ( const enumset< _TEnum, _Ty_list, _Ty_args > & set ) const [inline]

Union/Addition

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
enumset mbo::enumset< _TEnum, _Ty_list, _Ty_args >::operator+ ( const TEnum & value ) const [inline]

Union/Addition

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
enumset& mbo::enumset< _TEnum, _Ty_list, _Ty_args >::operator+= ( const enumset< _TEnum, _Ty_list, _Ty_args > & set ) [inline]

Union/Append assignment

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
enumset& mbo::enumset< _TEnum, _Ty_list, _Ty_args >::operator+= ( const TEnum & value ) throw (input_range_exception) [inline]

Union/Append assignment

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
enumset mbo::enumset< _TEnum, _Ty_list, _Ty_args >::operator- ( const enumset< _TEnum, _Ty_list, _Ty_args > & set ) const [inline]

Exception

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
enumset mbo::enumset< _TEnum, _Ty_list, _Ty_args >::operator- ( const TEnum & value ) const [inline]

Exception

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
enumset& mbo::enumset< _TEnum, _Ty_list, _Ty_args >::operator-= ( const enumset< _TEnum, _Ty_list, _Ty_args > & set ) [inline]

Minus assignment

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
enumset& mbo::enumset< _TEnum, _Ty_list, _Ty_args >::operator-= ( const TEnum & value ) throw (input_range_exception) [inline]

Minus assignment

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
bool mbo::enumset< _TEnum, _Ty_list, _Ty_args >::operator< ( const enumset< _TEnum, _Ty_list, _Ty_args > & set ) const [inline]

LT: Less than operator

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
bool mbo::enumset< _TEnum, _Ty_list, _Ty_args >::operator< ( const TEnum & value ) const throw (input_range_exception) [inline]

LT: Less than operator

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
bool mbo::enumset< _TEnum, _Ty_list, _Ty_args >::operator<= ( const enumset< _TEnum, _Ty_list, _Ty_args > & set ) const [inline]

LE: Less than or Equal operator

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
bool mbo::enumset< _TEnum, _Ty_list, _Ty_args >::operator<= ( const TEnum & value ) const throw (input_range_exception) [inline]

LE: Less than or Equal operator

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
enumset& mbo::enumset< _TEnum, _Ty_list, _Ty_args >::operator= ( const enumset< _TEnum, _Ty_list, _Ty_args > & set ) [inline]

Assignment operator

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
enumset& mbo::enumset< _TEnum, _Ty_list, _Ty_args >::operator= ( const TEnum & value ) throw (input_range_exception) [inline]

Assignment operator

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
bool mbo::enumset< _TEnum, _Ty_list, _Ty_args >::operator== ( const enumset< _TEnum, _Ty_list, _Ty_args > & set ) const [inline]

EQ: Equivalence operator

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
bool mbo::enumset< _TEnum, _Ty_list, _Ty_args >::operator== ( const TEnum & value ) const throw (input_range_exception) [inline]

EQ: Equivalence operator

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
bool mbo::enumset< _TEnum, _Ty_list, _Ty_args >::operator> ( const enumset< _TEnum, _Ty_list, _Ty_args > & set ) const [inline]

GT: Greater than operator

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
bool mbo::enumset< _TEnum, _Ty_list, _Ty_args >::operator> ( const TEnum & value ) const throw (input_range_exception) [inline]

GT: Greater than operator

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
bool mbo::enumset< _TEnum, _Ty_list, _Ty_args >::operator>= ( const enumset< _TEnum, _Ty_list, _Ty_args > & set ) const [inline]

GE: Greater than or Equal operator

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
bool mbo::enumset< _TEnum, _Ty_list, _Ty_args >::operator>= ( const TEnum & value ) const throw (input_range_exception) [inline]

GE: Greater than or Equal operator

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
enumset mbo::enumset< _TEnum, _Ty_list, _Ty_args >::operator^ ( const enumset< _TEnum, _Ty_list, _Ty_args > & set ) const [inline]

XOR

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
enumset mbo::enumset< _TEnum, _Ty_list, _Ty_args >::operator^ ( const TEnum & value ) const [inline]

XOR

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
enumset& mbo::enumset< _TEnum, _Ty_list, _Ty_args >::operator^= ( const enumset< _TEnum, _Ty_list, _Ty_args > & set ) [inline]

XOR assignment

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
enumset& mbo::enumset< _TEnum, _Ty_list, _Ty_args >::operator^= ( const TEnum & value ) throw (input_range_exception) [inline]

XOR assignment

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
enumset& mbo::enumset< _TEnum, _Ty_list, _Ty_args >::operator~ ( void ) throw (operator_na_exception) [inline, private]

NOT POSSIBLE - READ ABOVE

For internal use only.

Note:
The operator ~ is missing because the constructor cannot be informed about all set members available.
Exceptions:
operator_na_exception allways thrown

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
TEnum mbo::enumset< _TEnum, _Ty_list, _Ty_args >::to_enum ( ) const throw (demap_value_exception, multi_value_exception, multi_value_exception) [inline]

Conversion to enum value

When working with enum's this method returns a single enum value of the type used to instanciate this template class.

The function requires the instance to hold exactly one enum value. You may test this with the function count or catch the thrown exception as illustrated in the following example:

#include <typeinfo>
#include <stdio.h>
#include "enumset.hpp"

enum TEnum {a=1,b,c};

typedef mbo::enumset<TEnum> TSet;

int main(int argc, void ** argv)
{
    try {
        TSet es;

        es = a;

        if (es.count()==1) {
            printf("es = %d\n", (TSet::TEnum)es);
        } else {
            printf("es is empty\n");
        }

        es +=b;
        printf("es = %d\n", (TSet::TEnum)es); // will display an exception
    }
    catch (mbo::demap_value_exception &e) {
        printf("illegal TSet value, count != 1\n");
    }
    catch (mbo::enumset_exception &e) {
        printf("enumset exception\n");
    }
    printf("test finished\n");
    return 0;
}

Returns:
enum value
Exceptions:
multi_value_exception | if the set contains more than one enum values
empty_value_exception | if the set is empty
Note:
you may use demap_value_exception to write a combined handler

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
Ty_list mbo::enumset< _TEnum, _Ty_list, _Ty_args >::to_set ( ) const [inline]

Conversion to a number

Returns:
internal representation

Member Data Documentation

template<typename _TEnum, typename _Ty_list = size_t, typename _Ty_args = int>
Ty_list mbo::enumset< _TEnum, _Ty_list, _Ty_args >::list [private]

Internal set representation (used as bit field)

The documentation for this class was generated from the following file:
  • enumset.hpp
Generated on Wed Jan 15 18:34:08 2003 for Enumset by doxygen 1.3-rc2


mbo::enumset_exception Class Reference

base for exceptions thrown in mbo::enumset More...

#include <enumset.hpp>

Inheritance diagram for mbo::enumset_exception:

[legend]

Detailed Description

base for exceptions thrown in mbo::enumset

The documentation for this class was generated from the following file:
  • enumset.hpp
Generated on Wed Jan 15 18:34:09 2003 for Enumset by doxygen 1.3-rc2


mbo::input_range_exception Class Reference

exception thrown for illegal input to mbo::enumset More...

#include <enumset.hpp>

Inheritance diagram for mbo::input_range_exception:

[legend]
Collaboration diagram for mbo::input_range_exception:

[legend]

Detailed Description

exception thrown for illegal input to mbo::enumset

The documentation for this class was generated from the following file:
  • enumset.hpp
Generated on Wed Jan 15 18:34:10 2003 for Enumset by doxygen 1.3-rc2


mbo::multi_value_exception Class Reference

exception thrown in mbo::enumset conversion s More...

#include <enumset.hpp>

Inheritance diagram for mbo::multi_value_exception:

[legend]
Collaboration diagram for mbo::multi_value_exception:

[legend]

Detailed Description

exception thrown in mbo::enumset conversion s

this exception is thrown when an mbo::enumset instance which holds more than one set value is going to be converted to its enum type

The documentation for this class was generated from the following file:
  • enumset.hpp
Generated on Wed Jan 15 18:34:10 2003 for Enumset by doxygen 1.3-rc2


mbo::operator_na_exception Class Reference

exception thrown on illegal mbo::enumset operators More...

#include <enumset.hpp>

Inheritance diagram for mbo::operator_na_exception:

[legend]
Collaboration diagram for mbo::operator_na_exception:

[legend]

Detailed Description

exception thrown on illegal mbo::enumset operators

this is exception is thrown when an illegal operator was accessed from within a class derived from mbo::enumset.

The documentation for this class was generated from the following file:
  • enumset.hpp
Generated on Wed Jan 15 18:34:11 2003 for Enumset by doxygen 1.3-rc2


Compound Member Index

Enumset Compound Members

Here is a list of all class members with links to the classes they belong to:
  • clear() : mbo::enumset< _TEnum, _Ty_list, _Ty_args >
  • contains() : mbo::enumset< _TEnum, _Ty_list, _Ty_args >
  • count() : mbo::enumset< _TEnum, _Ty_list, _Ty_args >
  • demap() : mbo::enumset< _TEnum, _Ty_list, _Ty_args >
  • enumset() : mbo::enumset< _TEnum, _Ty_list, _Ty_args >
  • list : mbo::enumset< _TEnum, _Ty_list, _Ty_args >
  • map() : mbo::enumset< _TEnum, _Ty_list, _Ty_args >
  • operator &() : mbo::enumset< _TEnum, _Ty_list, _Ty_args >
  • operator *() : mbo::enumset< _TEnum, _Ty_list, _Ty_args >
  • operator *=() : mbo::enumset< _TEnum, _Ty_list, _Ty_args >
  • operator TEnum() : mbo::enumset< _TEnum, _Ty_list, _Ty_args >
  • operator Ty_list() : mbo::enumset< _TEnum, _Ty_list, _Ty_args >
  • operator!=() : mbo::enumset< _TEnum, _Ty_list, _Ty_args >
  • operator+() : mbo::enumset< _TEnum, _Ty_list, _Ty_args >
  • operator+=() : mbo::enumset< _TEnum, _Ty_list, _Ty_args >
  • operator-() : mbo::enumset< _TEnum, _Ty_list, _Ty_args >
  • operator-=() : mbo::enumset< _TEnum, _Ty_list, _Ty_args >
  • operator<() : mbo::enumset< _TEnum, _Ty_list, _Ty_args >
  • operator<=() : mbo::enumset< _TEnum, _Ty_list, _Ty_args >
  • operator=() : mbo::enumset< _TEnum, _Ty_list, _Ty_args >
  • operator==() : mbo::enumset< _TEnum, _Ty_list, _Ty_args >
  • operator>() : mbo::enumset< _TEnum, _Ty_list, _Ty_args >
  • operator>=() : mbo::enumset< _TEnum, _Ty_list, _Ty_args >
  • operator^() : mbo::enumset< _TEnum, _Ty_list, _Ty_args >
  • operator^=() : mbo::enumset< _TEnum, _Ty_list, _Ty_args >
  • operator~() : mbo::enumset< _TEnum, _Ty_list, _Ty_args >
  • TEnum : mbo::enumset< _TEnum, _Ty_list, _Ty_args >
  • to_enum() : mbo::enumset< _TEnum, _Ty_list, _Ty_args >
  • to_set() : mbo::enumset< _TEnum, _Ty_list, _Ty_args >
  • Ty_args : mbo::enumset< _TEnum, _Ty_list, _Ty_args >
  • Ty_list : mbo::enumset< _TEnum, _Ty_list, _Ty_args >
Generated on Wed Jan 15 18:34:07 2003 for Enumset by doxygen 1.3-rc2


mbo Namespace Reference

Compounds

class | demap_value_exception
base for exceptions thrown in mbo::enumset::to_enum More...

class | empty_value_exception
exception thrown in mbo::enumset conversion More...

class | enumset
A set template that works with enum types. More...

class | enumset_exception
base for exceptions thrown in mbo::enumset More...

class | input_range_exception
exception thrown for illegal input to mbo::enumset More...

class | multi_value_exception
exception thrown in mbo::enumset conversion s More...

class | operator_na_exception
exception thrown on illegal mbo::enumset operators More...

Detailed Description

contains template class mbo::enumset

Generated on Wed Jan 15 18:34:07 2003 for Enumset by doxygen 1.3-rc2


File Member Index

Enumset File Members

Here is a list of all file members with links to the files they belong to:
  • _Ty_args_default : enumset.hpp
  • _Ty_list_default : enumset.hpp
Generated on Wed Jan 15 18:34:11 2003 for Enumset by doxygen 1.3-rc2


enumset License

* Copyright (c) 2001 - 2003 Marcus Boerger.  All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
*    notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
*    notice, this list of conditions and the following disclaimer in
*    the documentation and/or other materials provided with the
*    distribution.
*
* 3. All advertising materials mentioning features or use of this
*    software must display the following acknowledgment:
*    "This product includes software developed by Marcus Boerger
*    (http://marcus-boerger.de/)."
*
* 4. The name "Marcus Boerger" must not be used to endorse or promote
*    products derived from this software without prior written permission.
*
* 5. Redistributions of any form whatsoever must retain the following
*    acknowledgment:
*    "This product includes software developed by Marcus Boerger
*    (http://marcus-boerger.de/)."
*
* 6. This is only intended to be used with enum or scalar types.
*
* THIS SOFTWARE IS PROVIDED BY MARCUS BOERGER ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL ``MARCUS BOERGER'' OR HIS
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
Generated on Wed Jan 15 18:34:07 2003 for Enumset by doxygen 1.3-rc2


enumset example 1

This example shows several enumset operators in action.

It uses the macro Execute to simplyfy the code. The macro serves two two purposes. First it executes the given expression and second it prints both the expression and the result using set notation through the function result().

#include <stdio.h>
#include "enumset.hpp"

enum TEnum {a=01, b=04, c=010};

typedef mbo::enumset<TEnum> TSet;

char * result(const TSet & es) {
    if (!es.count())       return "[]";
    if (es==TSet(1,a))     return "[a]";
    if (es==TSet(1,b))     return "[b]";
    if (es==TSet(1,c))     return "[c]";
    if (es==TSet(2,a,b))   return "[ab]";
    if (es==TSet(2,a,c))   return "[ac]";
    if (es==TSet(2,b,c))   return "[bc]";
    if (es==TSet(3,a,b,c)) return "[abc]";
    return "illegal: more than a+b+c";
}

#define Execute(st) \
  st;\
  printf( "%-17s=> %s\n", # st, result(es))

int main(int argc, void ** argv)
{
    try {
        TSet es;                     // []

        Execute( ;                ); // []
        Execute( es += a          ); // [a]    addition, union
        Execute( es  = es + b     ); // [a,b]  ditto
        Execute( es += es         ); // [a,b]  ditto
        Execute( es *= b          ); // [b]    intersection
        Execute( es  = es + c     ); // [b,c]  addition
        Execute( es -= b          ); // [c]    minus
        Execute( es.clear()       ); // []     clear
        Execute( es = TSet(0)     ); // []     dynamic creation
        Execute( es = TSet(2,a,c) ); // [a,c]  dynamic creation
        Execute( es = TEnum(es)   ); // throws multi_value_exception
    }
    catch (mbo::demap_value_exception &e) {
        printf("illegal TSet value, count != 1\n");
    }
    catch (mbo::enumset_exception &e) {
        printf("enumset exception\n");
    }
}

You can find another eample here enumset example 2

Generated on Wed Jan 15 18:34:07 2003 for Enumset by doxygen 1.3-rc2


enumset example 2

This example shows several enumset operators in action.

While sd has no specific value the other sd<n> values have <n> as their value after each block. This way you can simply control the results.

The comparison operators are called from parameters of a printf call. Each of these lines show the statement to be executed, the expected result and the actual result of the operator. So again you can easily check the results.

#include <typeinfo>
#include <stdio.h>
#include "enumset.hpp"

typedef enum _Tenum {a=0, b, c} Tenum;

typedef mbo::enumset<int> Tset;

int main(int argc,char **argv)
{
    // create a set of doubles
    try {
        Tset	sd, sd0, sd1, sd2, sd3, sd4, sd5, sd6, sd7;

        printf("sd0:%d\n", (size_t)sd0);

        sd  = Tset(a);
        sd += b;
        sd += c;
        sd -= b;
        sd5 = sd;

        sd  = sd + b;
        sd  = sd - c;
        sd3 = sd;
        sd7 = sd3 + sd5;

        printf("sd3:%d\n", (size_t)sd3);
        printf("sd5:%d\n", (size_t)sd5);
        printf("sd7:%d\n", (size_t)sd7);

        printf("\n");
        sd2 = b;
        sd4 = c;
        sd6 = sd2 + c;
        sd.clear();
        sd += a;
        sd1 = sd0 + sd;
        printf("sd :%d\n", (size_t)sd);
        printf("sd1:%d\n", (size_t)sd1);
        printf("sd2:%d\n", (size_t)sd2);
        printf("sd4:%d\n", (size_t)sd4);
        printf("sd6:%d\n", (size_t)sd6);

        printf("\n");
        sd2 = sd3 * sd6;
        sd4 = sd6;
        sd4*= sd5;
        sd  = sd4 * sd6;
        printf("sd :%d\n", (size_t)sd);
        printf("sd1:%d\n", (size_t)sd1);
        printf("sd2:%d\n", (size_t)sd2);
        printf("sd3:%d\n", (size_t)sd3);
        printf("sd4:%d\n", (size_t)sd4);
        printf("sd5:%d\n", (size_t)sd5);
        printf("sd6:%d\n", (size_t)sd6);

        printf("\n");
        printf("sd2 & sd4        == false: %s\n", sd2&sd            ? "true" : "false");
        printf("sd2 & sd3        == true : %s\n", sd2&sd3           ? "true" : "false");
        printf("sd2 & sd5        == false: %s\n", sd2&sd5           ? "true" : "false");
        printf("sd2 & a          == false: %s\n", sd2&a             ? "true" : "false");
        printf("sd2 & b          == true : %s\n", sd2&b             ? "true" : "false");
        printf("sd2 < sd3        == true : %s\n", sd2<sd3           ? "true" : "false");
        printf("sd2 < sd4        == false: %s\n", sd2<sd4           ? "true" : "false");
        printf("sd3 <= sd2       == false: %s\n", sd3<=sd2          ? "true" : "false");
        printf("sd2 >= sd2       == true : %s\n", sd2>=sd2          ? "true" : "false");
        printf("sd3 >= sd2       == true : %s\n", sd3>=sd2          ? "true" : "false");
        printf("sd2 <= sd2       == true : %s\n", sd2<=sd2          ? "true" : "false");
        printf("sd2 >= sd5       == false: %s\n", sd2>=sd5          ? "true" : "false");
        printf("sd3 >= sd2       == true : %s\n", sd3>=sd2          ? "true" : "false");
        printf("sd3 <= sd5       == false: %s\n", sd3<=sd5          ? "true" : "false");
        printf("sd5 >= sd3       == false: %s\n", sd5>=sd3          ? "true" : "false");
        printf("sd2 >= a         == false: %s\n", sd2>=a            ? "true" : "false");
        printf("sd2 >= b         == true : %s\n", sd2>=b            ? "true" : "false");
        printf("sd2 >= c         == false: %s\n", sd2>=c            ? "true" : "false");
        printf("sd1.contains(a)  == true : %s\n", sd1.contains(a)   ? "true" : "false");
        printf("sd1.contains(b)  == false: %s\n", sd1.contains(b)   ? "true" : "false");
        printf("sd1.contains(c)  == false: %s\n", sd1.contains(c)   ? "true" : "false");
        printf("sd3.contains(a)  == true : %s\n", sd3.contains(a)   ? "true" : "false");
        printf("sd3.contains(b)  == true : %s\n", sd3.contains(b)   ? "true" : "false");
        printf("sd3.contains(c)  == false: %s\n", sd3.contains(c)   ? "true" : "false");
        printf("sd4.contains(a)  == false: %s\n", sd4.contains(a)   ? "true" : "false");
        printf("sd4.contains(b)  == false: %s\n", sd4.contains(b)   ? "true" : "false");
        printf("sd4.contains(c)  == true : %s\n", sd4.contains(c)   ? "true" : "false");
        printf("sd6.contains(a)  == false: %s\n", sd6.contains(a)   ? "true" : "false");
        printf("sd6.contains(b)  == true : %s\n", sd6.contains(b)   ? "true" : "false");
        printf("sd6.contains(c)  == true : %s\n", sd6.contains(c)   ? "true" : "false");
        printf("sd3 != sd        == true : %s\n", sd3 != sd         ? "true" : "false");
        printf("sd3.contains(sd1)== true : %s\n", sd3.contains(sd1) ? "true" : "false");
        printf("sd6.contains(sd2)== true : %s\n", sd6.contains(sd2) ? "true" : "false");
        printf("sd1.contains(sd3)== false: %s\n", sd1.contains(sd3) ? "true" : "false");
        printf("sd3.contains(sd3)== true : %s\n", sd3.contains(sd3) ? "true" : "false");

    }
    catch (mbo::enumset_exception &e) {
        printf("1) %s", typeid(e).name());
    }

    return 0;
}

You can find another eample here enumset example 1

Generated on Wed Jan 15 18:34:07 2003 for Enumset by doxygen 1.3-rc2


Graphical Class Hierarchy

Enumset Graphical Class Hierarchy

Go to the textual class hierarchy

Generated on Wed Jan 15 18:34:12 2003 for Enumset by doxygen 1.3-rc2


Member List

mbo::enumset< _TEnum, _Ty_list, _Ty_args > Member List

This is the complete list of members for mbo::enumset< _TEnum, _Ty_list, _Ty_args >, including all inherited members.
clear() | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
contains(const TEnum &value) const | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
contains(const enumset &set) const | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
count() const | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
demap(Ty_list value) const | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline, private]
enumset() | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
enumset(const enumset &set) | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
enumset(size_t count,...) | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline, explicit]
enumset(const TEnum &value) | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
list | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [private]
map(Ty_list value) const | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline, private]
operator &(const TEnum &value) const | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
operator &(const enumset &set) const | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
operator *(const TEnum &value) const | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
operator *(const enumset &set) const | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
operator *=(const TEnum &value) | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
operator *=(const enumset &set) | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
operator TEnum() const | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
operator Ty_list() const | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
operator!=(const TEnum &value) const | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
operator!=(const enumset &set) const | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
operator+(const TEnum &value) const | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
operator+(const enumset &set) const | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
operator+=(const TEnum &value) | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
operator+=(const enumset &set) | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
operator-(const TEnum &value) const | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
operator-(const enumset &set) const | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
operator-=(const TEnum &value) | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
operator-=(const enumset &set) | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
operator<(const TEnum &value) const | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
operator<(const enumset &set) const | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
operator<=(const TEnum &value) const | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
operator<=(const enumset &set) const | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
operator=(const TEnum &value) | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
operator=(const enumset &set) | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
operator==(const TEnum &value) const | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
operator==(const enumset &set) const | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
operator>(const TEnum &value) const | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
operator>(const enumset &set) const | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
operator>=(const TEnum &value) const | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
operator>=(const enumset &set) const | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
operator^(const TEnum &value) const | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
operator^(const enumset &set) const | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
operator^=(const TEnum &value) | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
operator^=(const enumset &set) | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
operator~(void) | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline, private]
TEnum typedef | mbo::enumset< _TEnum, _Ty_list, _Ty_args > |
to_enum() const | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
to_set() const | mbo::enumset< _TEnum, _Ty_list, _Ty_args > | [inline]
Ty_args typedef | mbo::enumset< _TEnum, _Ty_list, _Ty_args > |
Ty_list typedef | mbo::enumset< _TEnum, _Ty_list, _Ty_args > |
Generated on Wed Jan 15 18:34:08 2003 for Enumset by doxygen 1.3-rc2


enumset.hpp Source File

enumset.hpp

Go to the documentation of this file.
00001 /****************************************************************************//* ====================================================================== */
00047
00048 /* ------------------------------------------------------------------------ */
00076 /* ------------------------------------------------------------------------ */
00077
00083 /* ------------------------------------------------------------------------ */
00084
00085 #ifndef _ENUMSET_HPP_
00086 #define _ENUMSET_HPP_
00087
00088 #ifdef __MSC_VER
00089 #pragma comment (exestr, "This software includes material by M.Boerger (http://marcus-boerger.de/)")
00090 #endif
00091
00092 #include <stdarg.h>
00093 #include <exception>
00094
00095 #ifndef _Ty_list_default
00096
00099 #define _Ty_list_default size_t
00100 #endif
00101
00102 #ifndef _Ty_args_default
00103
00106 #define _Ty_args_default int
00107 #endif
00108
00109 /* ------------------------------------------------------------------------ */
00114 namespace mbo {
00115
00118 class enumset_exception: public std::exception{};
00119
00122 class input_range_exception: public enumset_exception {};
00123
00129 class demap_value_exception: public enumset_exception {};
00130
00136 class multi_value_exception: public demap_value_exception {};
00137
00143 class empty_value_exception: public demap_value_exception {};
00144
00150 class operator_na_exception: public enumset_exception {};
00151
00152 /* ------------------------------------------------------------------------ */
00230 template < typename _TEnum
00231          , typename _Ty_list  = _Ty_list_default
00232          , typename _Ty_args  = _Ty_args_default
00233          >
00234 class enumset {
00235 public:
00236
00241     typedef _TEnum   TEnum;
00242
00247     typedef _Ty_list Ty_list;
00248
00253     typedef _Ty_args Ty_args;
00254
00257     inline enumset () : list(0)
00258     {
00259     }
00260
00263     inline enumset (const enumset & set)
00264     {
00265         list = set.list;
00266     }
00267
00273     inline explicit enumset (size_t count, ...)
00274         throw(input_range_exception)
00275         : list(0)
00276     {
00277         va_list   args;
00278         Ty_list   val;
00279
00280         va_start(args, count);
00281         while (count--) {
00282             val = (Ty_list)va_arg(args, Ty_args);
00283             list |= map(val);
00284         }
00285         va_end(args);
00286     }
00287
00291     inline enumset (const TEnum & value)
00292         throw(input_range_exception)
00293     {
00294         list = map(value);
00295     }
00296
00299     inline bool contains(const TEnum & value) const
00300     {
00301         return (*this >= value);
00302     }
00303
00307     inline bool contains(const enumset & set) const
00308     {
00309         return (*this >= set);
00310     }
00311
00314     inline int count() const
00315     {
00316         register int i = 0;
00317         register Ty_list p = 1;
00318
00319         while (p) {
00320             i += (list & p) ? 1 : 0;
00321             p *=2;
00322         }
00323         return i;
00324     }
00325
00328     inline enumset & clear()
00329     {
00330         list = 0;
00331         return *this;
00332     }
00333
00336     inline enumset & operator = (const TEnum & value)
00337         throw(input_range_exception)
00338     {
00339         list = map(value);
00340         return *this;
00341     }
00342
00345     inline enumset & operator = (const enumset & set)
00346     {
00347         list = set.list;
00348         return *this;
00349     }
00350
00353     inline enumset & operator += (const TEnum & value)
00354         throw(input_range_exception)
00355     {
00356         list |= map(value);
00357         return *this;
00358     }
00359
00362     inline enumset & operator += (const enumset & set)
00363     {
00364         list |= set.list;
00365         return *this;
00366     }
00367
00370     inline enumset operator + (const TEnum & value) const
00371     {
00372         register enumset ret = enumset(*this);
00373         ret += value;
00374         return ret;
00375     }
00376
00379     inline enumset operator + (const enumset & set) const
00380     {
00381         register enumset ret = enumset(*this);
00382         ret += set;
00383         return ret;
00384     }
00385
00388     inline enumset & operator -= (const TEnum &value)
00389         throw(input_range_exception)
00390     {
00391         list &= ~map(value);
00392         return *this;
00393     }
00394
00397     inline enumset & operator -= (const enumset &set)
00398     {
00399         list &= ~set.list;
00400         return *this;
00401     }
00402
00405     inline enumset operator - (const TEnum & value) const
00406     {
00407         enumset ret = enumset(*this);
00408         ret -= value;
00409         return ret;
00410     }
00411
00414     inline enumset operator - (const enumset & set) const
00415     {
00416         enumset ret = enumset(*this);
00417         ret -= set;
00418         return ret;
00419     }
00420
00423     inline enumset & operator *= (const TEnum &value)
00424         throw(input_range_exception)
00425     {
00426         list &= map(value);
00427         return *this;
00428     }
00429
00432     inline enumset & operator *= (const enumset &set)
00433     {
00434         list &= set.list;
00435         return *this;
00436     }
00437
00440     inline enumset operator * (const TEnum & value) const
00441     {
00442         register enumset ret = enumset(*this);
00443         ret *= value;
00444         return ret;
00445     }
00446
00449     inline enumset operator * (const enumset & set) const
00450     {
00451         register enumset ret = enumset(*this);
00452         ret *= set;
00453         return ret;
00454     }
00455
00458     inline enumset & operator ^= (const TEnum &value)
00459         throw(input_range_exception)
00460     {
00461         list ^= map(value);
00462         return *this;
00463     }
00464
00467     inline enumset & operator ^= (const enumset &set)
00468     {
00469         list ^= set.list;
00470         return *this;
00471     }
00472
00475     inline enumset operator ^ (const TEnum & value) const
00476     {
00477         register enumset ret = enumset(*this);
00478         ret ^= value;
00479         return ret;
00480     }
00481
00484     inline enumset operator ^ (const enumset & set) const
00485     {
00486         register enumset ret = enumset(*this);
00487         ret ^= set;
00488         return ret;
00489     }
00490
00493     inline bool operator & (const TEnum & value) const
00494         throw(input_range_exception)
00495     {
00496         return (list & map(value)) > 0;
00497     }
00498
00501     inline bool operator & (const enumset & set) const
00502     {
00503         return (list & set.list) > 0;
00504     }
00505
00508     inline bool operator == (const TEnum & value) const
00509         throw(input_range_exception)
00510     {
00511         return list == map(value);
00512     }
00513
00516     inline bool operator == (const enumset & set) const
00517     {
00518         return list == set.list;
00519     }
00520
00523     inline bool operator != (const TEnum & value) const
00524         throw(input_range_exception)
00525     {
00526         return list != map(value);
00527     }
00528
00531     inline bool operator != (const enumset & set) const
00532     {
00533         return list != set.list;
00534     }
00535
00538     inline bool operator < (const TEnum & value) const
00539         throw(input_range_exception)
00540     {
00541         register Ty_list comp = map(value);
00542         return ((list & comp) == list) && (list < comp);
00543     }
00544
00547     inline bool operator < (const enumset & set) const
00548     {
00549         return ((list & set.list) == list) && (list < set.list);
00550     }
00551
00554     inline bool operator <= (const TEnum & value) const
00555         throw(input_range_exception)
00556     {
00557         register Ty_list comp = map(value);
00558         return ((list & comp) == list) && (list <= comp);
00559     }
00560
00563     inline bool operator <= (const enumset & set) const
00564     {
00565         return ((list & set.list) == list) && (list <= set.list);
00566     }
00567
00570     inline bool operator > (const TEnum & value) const
00571         throw(input_range_exception)
00572     {
00573         register Ty_list comp = map(value);
00574         return ((list & comp) == comp) && (list > comp);
00575     }
00576
00579     inline bool operator > (const enumset & set) const
00580     {
00581         return ((list & set.list) == set.list) && (list > set.list);
00582     }
00583
00586     inline bool operator >= (const TEnum & value) const
00587         throw(input_range_exception)
00588     {
00589         register Ty_list comp = map(value);
00590         return ((list & comp) == comp) && (list >= comp);
00591     }
00592
00595     inline bool operator >= (const enumset & set) const
00596     {
00597         return ((list & set.list) == set.list) && (list >= set.list);
00598     }
00599
00604     inline Ty_list to_set() const
00605     {
00606         return list;
00607     }
00608
00611     inline operator Ty_list() const
00612     {
00613         return list;
00614     }
00615
00666     inline TEnum to_enum() const
00667         throw(demap_value_exception, multi_value_exception, multi_value_exception)
00668     {
00669         return (TEnum)demap(list);
00670     }
00671
00684     inline operator TEnum() const
00685         throw(demap_value_exception, multi_value_exception, multi_value_exception)
00686     {
00687         return (TEnum)demap(list);
00688     }
00689
00690 private:
00691
00699     inline enumset & operator ~(void)
00700         throw(operator_na_exception)
00701     {
00702         throw operator_na_exception();
00703     }
00704
00707     Ty_list list;
00708
00714     inline Ty_list map(Ty_list value) const
00715         throw(input_range_exception)
00716     {
00717         if (((size_t)value) >= (sizeof(Ty_list)*8)) {
00718             throw input_range_exception();
00719         }
00720         return (1L << value);
00721     }
00722
00731     inline Ty_list demap(Ty_list value) const
00732         throw(demap_value_exception, multi_value_exception, empty_value_exception)
00733     {
00734         register Ty_list i = 0;
00735         register Ty_list p = 1;
00736
00737         while (p) {
00738             if (list & p) {
00739                 if (list & (~p)) {
00740                     throw multi_value_exception();
00741                 }
00742                 return i;
00743             }
00744             i++;
00745             p <<= 1;
00746         }
00747         throw empty_value_exception();
00748         return 0;
00749     }
00750
00751 }; // template class enumset
00752
00753 /****************************************************************************//**************************************************************************/
00816
00817 /****************************************************************************//**************************************************************************/
00937
00938 }; // namespace mbo
00939
00940 #endif // _ENUMSET_HPP_
Generated on Wed Jan 15 18:34:06 2003 for Enumset by doxygen 1.3-rc2


Annotated Index

Enumset Compound List

Here are the classes, structs, unions and interfaces with brief descriptions:
mbo::demap_value_exception | Base for exceptions thrown in mbo::enumset::to_enum
mbo::empty_value_exception | Exception thrown in mbo::enumset conversion
mbo::enumset< _TEnum, _Ty_list, _Ty_args > | A set template that works with enum types
mbo::enumset_exception | Base for exceptions thrown in mbo::enumset
mbo::input_range_exception | Exception thrown for illegal input to mbo::enumset
mbo::multi_value_exception | Exception thrown in mbo::enumset conversion s
mbo::operator_na_exception | Exception thrown on illegal mbo::enumset operators
Generated on Wed Jan 15 18:34:07 2003 for Enumset by doxygen 1.3-rc2


Alphabetical index

Enumset Compound Index

D
mbo::empty_value_exception (mbo)
I
mbo::multi_value_exception (mbo)
mbo::demap_value_exception (mbo) mbo::enumset< _TEnum, _Ty_list, _Ty_args > (mbo) mbo::input_range_exception (mbo)
O
E
mbo::enumset_exception (mbo)
M
mbo::operator_na_exception (mbo)
Generated on Wed Jan 15 18:34:07 2003 for Enumset by doxygen 1.3-rc2


File Index

Enumset File List

Here is a list of all files with brief descriptions:
enumset.hpp [code] Template mbo::enumset: a set template that works with enum types
Generated on Wed Jan 15 18:34:06 2003 for Enumset by doxygen 1.3-rc2


Graph Legend

 Consider the following example:

/*! Invisible class because of truncation */
class Invisible { };

/*! Truncated class, inheritance relation is hidden */
class Truncated : public Invisible { };

/* Class not documented with doxygen comments */
class Undocumented { };

/*! Class that is inherited using public inheritance */
class PublicBase : public Truncated { };

/*! A template class */
template<class T> class Templ { };

/*! Class that is inherited using protected inheritance */
class ProtectedBase { };

/*! Class that is inherited using private inheritance */
class PrivateBase { };

/*! Class that is used by the Inherited class */
class Used { };

/*! Super class that inherits a number of other classes */
class Inherited : public PublicBase,
                  protected ProtectedBase,
                  private PrivateBase,
                  public Undocumented
                  public Templ<int>
{
  private:
    Used *m_usedClass;
};
If the MAX_DOT_GRAPH_HEIGHT tag in the configuration file is set to 240 this will result in the following graph:

The boxes in the above graph have the following meaning:

  • A filled black box represents the struct or class for which the graph is generated.
  • A box with a black border denotes a documented struct or class.
  • A box with a grey border denotes an undocumented struct or class.
  • A box with a red border denotes a documented struct or class forwhich not all inheritance/containment relations are shown. A graph is truncated if it does not fit within the specified boundaries.
The arrows have the following meaning:
  • A dark blue arrow is used to visualize a public inheritance relation between two classes.
  • A dark green arrow is used for protected inheritance.
  • A dark red arrow is used for private inheritance.
  • A purple dashed arrow is used if a class is contained or used by another class. The arrow is labeled with the variable(s) through which the pointed class or struct is accessible.
  • A yellow dashed arrow denotes a relation between a template instance and the template class it was instantiated from. The arrow is labeled with the template parameters of the instance.
Generated by doxygen 1.3-rc2


Hierarchical Index

Enumset Class Hierarchy

Go to the graphical class hierarchy

This inheritance list is sorted roughly, but not completely, alphabetically:

  • mbo::enumset< _TEnum, _Ty_list, _Ty_args >
  • mbo::enumset_exception
    • mbo::demap_value_exception
      • mbo::empty_value_exception
      • mbo::multi_value_exception
    • mbo::input_range_exception
    • mbo::operator_na_exception
Generated on Wed Jan 15 18:34:07 2003 for Enumset by doxygen 1.3-rc2


Namespace Index

Enumset Namespace List

Here is a list of all namespaces with brief descriptions:
mbo
Generated on Wed Jan 15 18:34:07 2003 for Enumset by doxygen 1.3-rc2


Page Index

Enumset Related Pages

Here is a list of all related documentation pages:
  • enumset License
  • enumset example 1
  • enumset example 2
Generated on Wed Jan 15 18:34:11 2003 for Enumset by doxygen 1.3-rc2