PTLib Version 2.12.9

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Macros | Functions
bitwise_enum.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Classes
class | PBitwiseEnum< BaseEnum, MaxValue, BaseInt >
| This class defines a set of operators for a bit wise enumeration. More...
class | PStreamableBitwiseEnum< BaseEnum, MaxValue, BaseInt >

## Macros
#define | P_BITWISE_ENUM_INTERNAL_OP1(op) (static_cast<IntType>(m_enum) op static_cast<IntType>(rhs))
#define | P_BITWISE_ENUM_INTERNAL_OP2(op) static_cast<Enumeration>(P_BITWISE_ENUM_INTERNAL_OP1(op))
#define | P_DECLARE_BITWISE_ENUM_1(_0, _1) _0=0,_1=1
#define | P_DECLARE_BITWISE_ENUM_2(_0, _1, _2) P_DECLARE_BITWISE_ENUM_1(_0,_1),_2=2
#define | P_DECLARE_BITWISE_ENUM_3(_0, _1, _2, _3) P_DECLARE_BITWISE_ENUM_2(_0,_1,_2),_3=4
#define | P_DECLARE_BITWISE_ENUM_4(_0, _1, _2, _3, _4) P_DECLARE_BITWISE_ENUM_3(_0,_1,_2,_3),_4=8
#define | P_DECLARE_BITWISE_ENUM_5(_0, _1, _2, _3, _4, _5) P_DECLARE_BITWISE_ENUM_4(_0,_1,_2,_3,_4),_5=16
#define | P_DECLARE_BITWISE_ENUM_6(_0, _1, _2, _3, _4, _5, _6) P_DECLARE_BITWISE_ENUM_5(_0,_1,_2,_3,_4,_5),_6=32
#define | P_DECLARE_BITWISE_ENUM_7(_0, _1, _2, _3, _4, _5, _6, _7) P_DECLARE_BITWISE_ENUM_6(_0,_1,_2,_3,_4,_5,_6),_7=64
#define | P_DECLARE_BITWISE_ENUM_8(_0, _1, _2, _3, _4, _5, _6, _7, _8) P_DECLARE_BITWISE_ENUM_7(_0,_1,_2,_3,_4,_5,_6,_7),_8=128
#define | P_DECLARE_BITWISE_ENUM_9(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9) P_DECLARE_BITWISE_ENUM_8(_0,_1,_2,_3,_4,_5,_6,_7,_8),_9=256
#define | P_DECLARE_BITWISE_NAMES_1(_0, _1) #_0,#_1
#define | P_DECLARE_BITWISE_NAMES_2(_0, _1, _2) P_DECLARE_BITWISE_NAMES_1(_0,_1),#_2
#define | P_DECLARE_BITWISE_NAMES_3(_0, _1, _2, _3) P_DECLARE_BITWISE_NAMES_2(_0,_1,_2),#_3
#define | P_DECLARE_BITWISE_NAMES_4(_0, _1, _2, _3, _4) P_DECLARE_BITWISE_NAMES_3(_0,_1,_2,_3),#_4
#define | P_DECLARE_BITWISE_NAMES_5(_0, _1, _2, _3, _4, _5) P_DECLARE_BITWISE_NAMES_4(_0,_1,_2,_3,_4),#_5
#define | P_DECLARE_BITWISE_NAMES_6(_0, _1, _2, _3, _4, _5, _6) P_DECLARE_BITWISE_NAMES_5(_0,_1,_2,_3,_4,_5),#_6
#define | P_DECLARE_BITWISE_NAMES_7(_0, _1, _2, _3, _4, _5, _6, _7) P_DECLARE_BITWISE_NAMES_6(_0,_1,_2,_3,_4,_5,_6),#_7
#define | P_DECLARE_BITWISE_NAMES_8(_0, _1, _2, _3, _4, _5, _6, _7, _8) P_DECLARE_BITWISE_NAMES_7(_0,_1,_2,_3,_4,_5,_6,_7),#_8
#define | P_DECLARE_BITWISE_NAMES_9(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9) P_DECLARE_BITWISE_NAMES_8(_0,_1,_2,_3,_4,_5,_6,_7,_8),#_9
#define | P_DECLARE_BITWISE_ENUM_FRIENDS(name)
#define | P_DECLARE_BITWISE_ENUM_END(name, count)
#define | P_DECLARE_BITWISE_ENUM(name, count, values)
| This macro can be used to declare a bit wise enumeration, using the PBitWiseEnum template class. More...
#define | P_DECLARE_BITWISE_ENUM_EX(name, count, values,...)
| This macro can be used to declare a bit wise enumeration, using the PBitWiseEnum template class. More...
#define | P_DECLARE_STREAMABLE_BITWISE_ENUM_EX(name, count, values,...)
#define | P_DECLARE_STREAMABLE_BITWISE_ENUM(name, count, values) P_DECLARE_STREAMABLE_BITWISE_ENUM_EX(name, count, values, P_DECLARE_BITWISE_NAMES_##count values)

## Functions
void | PPrintBitwiseEnum (std::ostream &strm, unsigned bits, char const *const *names)
unsigned | PReadBitwiseEnum (std::istream &strm, char const *const *names, bool continueOnError=false)

## Macro Definition Documentation

#define P_BITWISE_ENUM_INTERNAL_OP1 | ( |  | op | ) | (static_cast<IntType>(m_enum) op static_cast<IntType>(rhs))

Referenced by PBitwiseEnum< BaseEnum, MaxValue, BaseInt >::operator&(), PBitwiseEnum< BaseEnum, MaxValue, BaseInt >::operator<=(), PBitwiseEnum< BaseEnum, MaxValue, BaseInt >::operator==(), and PBitwiseEnum< BaseEnum, MaxValue, BaseInt >::operator>=().

#define P_BITWISE_ENUM_INTERNAL_OP2 | ( |  | op | ) | static_cast<Enumeration>(P_BITWISE_ENUM_INTERNAL_OP1(op))

Referenced by PBitwiseEnum< BaseEnum, MaxValue, BaseInt >::operator+(), PBitwiseEnum< BaseEnum, MaxValue, BaseInt >::operator+=(), PBitwiseEnum< BaseEnum, MaxValue, BaseInt >::operator-(), PBitwiseEnum< BaseEnum, MaxValue, BaseInt >::operator-=(), PBitwiseEnum< BaseEnum, MaxValue, BaseInt >::operator^(), PBitwiseEnum< BaseEnum, MaxValue, BaseInt >::operator^=(), PBitwiseEnum< BaseEnum, MaxValue, BaseInt >::operator|(), and PBitwiseEnum< BaseEnum, MaxValue, BaseInt >::operator|=().

#define P_DECLARE_BITWISE_ENUM | ( |  | name,
|  |  | count,
|  |  | values
| ) |  |

Value:
enum name##_Bits { P_DECLARE_BITWISE_ENUM_##count values }; \
P_DECLARE_BITWISE_ENUM_END(name, count)

This macro can be used to declare a bit wise enumeration, using the PBitWiseEnum template class.

Example: P_DECLARE_BITWISE_ENUM(MyBitWiseEnum, 3, (ZeroValue, FirstBit, SecondBit, ThirdBit));

Which will decclare the values for an enum MyBitWiseEnum_Bits of ZeroValue = 0, FirstBit = 1, SecondBit = 2, ThirdBit = 4. And the PBitWiseEnum template class will have a typedef to `name`.

#define P_DECLARE_BITWISE_ENUM_1 | ( |  | _0,
|  |  | _1
| ) |  | _0=0,_1=1

#define P_DECLARE_BITWISE_ENUM_2 | ( |  | _0,
|  |  | _1,
|  |  | _2
| ) |  | P_DECLARE_BITWISE_ENUM_1(_0,_1),_2=2

#define P_DECLARE_BITWISE_ENUM_3 | ( |  | _0,
|  |  | _1,
|  |  | _2,
|  |  | _3
| ) |  | P_DECLARE_BITWISE_ENUM_2(_0,_1,_2),_3=4

#define P_DECLARE_BITWISE_ENUM_4 | ( |  | _0,
|  |  | _1,
|  |  | _2,
|  |  | _3,
|  |  | _4
| ) |  | P_DECLARE_BITWISE_ENUM_3(_0,_1,_2,_3),_4=8

#define P_DECLARE_BITWISE_ENUM_5 | ( |  | _0,
|  |  | _1,
|  |  | _2,
|  |  | _3,
|  |  | _4,
|  |  | _5
| ) |  | P_DECLARE_BITWISE_ENUM_4(_0,_1,_2,_3,_4),_5=16

#define P_DECLARE_BITWISE_ENUM_6 | ( |  | _0,
|  |  | _1,
|  |  | _2,
|  |  | _3,
|  |  | _4,
|  |  | _5,
|  |  | _6
| ) |  | P_DECLARE_BITWISE_ENUM_5(_0,_1,_2,_3,_4,_5),_6=32

#define P_DECLARE_BITWISE_ENUM_7 | ( |  | _0,
|  |  | _1,
|  |  | _2,
|  |  | _3,
|  |  | _4,
|  |  | _5,
|  |  | _6,
|  |  | _7
| ) |  | P_DECLARE_BITWISE_ENUM_6(_0,_1,_2,_3,_4,_5,_6),_7=64

#define P_DECLARE_BITWISE_ENUM_8 | ( |  | _0,
|  |  | _1,
|  |  | _2,
|  |  | _3,
|  |  | _4,
|  |  | _5,
|  |  | _6,
|  |  | _7,
|  |  | _8
| ) |  | P_DECLARE_BITWISE_ENUM_7(_0,_1,_2,_3,_4,_5,_6,_7),_8=128

#define P_DECLARE_BITWISE_ENUM_9 | ( |  | _0,
|  |  | _1,
|  |  | _2,
|  |  | _3,
|  |  | _4,
|  |  | _5,
|  |  | _6,
|  |  | _7,
|  |  | _8,
|  |  | _9
| ) |  | P_DECLARE_BITWISE_ENUM_8(_0,_1,_2,_3,_4,_5,_6,_7,_8),_9=256

#define P_DECLARE_BITWISE_ENUM_END | ( |  | name,
|  |  | count
| ) |  |

Value:
P_DECLARE_BITWISE_ENUM_FRIENDS(name) \
typedef PBitwiseEnum<name##_Bits, (name##_Bits)(1<<(count-1))> name

#define P_DECLARE_BITWISE_ENUM_EX | ( |  | name,
|  |  | count,
|  |  | values,
|  |  | ...
| ) |  |

Value:
enum name##_Bits { P_DECLARE_BITWISE_ENUM_##count values , ##__VA_ARGS__ }; \
P_DECLARE_BITWISE_ENUM_END(name, count)

This macro can be used to declare a bit wise enumeration, using the PBitWiseEnum template class.

This si similar to P_DECLARE_BITWISE_ENUM but allows extra value to be added to the enum for bit combinations, for example: P_DECLARE_BITWISE_ENUM_EX(MyBitWiseEnum, 3, (ZeroValue, FirstBit, SecondBit, ThirdBit), LowBits = FirstBit|SecondBit, AllBits = FirstBit|SecondBit|ThirdBit);

#define P_DECLARE_BITWISE_ENUM_FRIENDS | ( |  | name | ) |

Value:
__inline friend name##_Bits operator+(name##_Bits lhs, name##_Bits rhs) \
{ return static_cast<name##_Bits>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs)); } \
__inline friend name##_Bits operator|(name##_Bits lhs, name##_Bits rhs) \
{ return static_cast<name##_Bits>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs)); } \
__inline friend name##_Bits operator-(name##_Bits lhs, name##_Bits rhs) \
{ return static_cast<name##_Bits>(static_cast<unsigned>(lhs) & ~static_cast<unsigned>(rhs)); }

#define P_DECLARE_BITWISE_NAMES_1 | ( |  | _0,
|  |  | _1
| ) |  | #_0,#_1

#define P_DECLARE_BITWISE_NAMES_2 | ( |  | _0,
|  |  | _1,
|  |  | _2
| ) |  | P_DECLARE_BITWISE_NAMES_1(_0,_1),#_2

#define P_DECLARE_BITWISE_NAMES_3 | ( |  | _0,
|  |  | _1,
|  |  | _2,
|  |  | _3
| ) |  | P_DECLARE_BITWISE_NAMES_2(_0,_1,_2),#_3

#define P_DECLARE_BITWISE_NAMES_4 | ( |  | _0,
|  |  | _1,
|  |  | _2,
|  |  | _3,
|  |  | _4
| ) |  | P_DECLARE_BITWISE_NAMES_3(_0,_1,_2,_3),#_4

#define P_DECLARE_BITWISE_NAMES_5 | ( |  | _0,
|  |  | _1,
|  |  | _2,
|  |  | _3,
|  |  | _4,
|  |  | _5
| ) |  | P_DECLARE_BITWISE_NAMES_4(_0,_1,_2,_3,_4),#_5

#define P_DECLARE_BITWISE_NAMES_6 | ( |  | _0,
|  |  | _1,
|  |  | _2,
|  |  | _3,
|  |  | _4,
|  |  | _5,
|  |  | _6
| ) |  | P_DECLARE_BITWISE_NAMES_5(_0,_1,_2,_3,_4,_5),#_6

#define P_DECLARE_BITWISE_NAMES_7 | ( |  | _0,
|  |  | _1,
|  |  | _2,
|  |  | _3,
|  |  | _4,
|  |  | _5,
|  |  | _6,
|  |  | _7
| ) |  | P_DECLARE_BITWISE_NAMES_6(_0,_1,_2,_3,_4,_5,_6),#_7

#define P_DECLARE_BITWISE_NAMES_8 | ( |  | _0,
|  |  | _1,
|  |  | _2,
|  |  | _3,
|  |  | _4,
|  |  | _5,
|  |  | _6,
|  |  | _7,
|  |  | _8
| ) |  | P_DECLARE_BITWISE_NAMES_7(_0,_1,_2,_3,_4,_5,_6,_7),#_8

#define P_DECLARE_BITWISE_NAMES_9 | ( |  | _0,
|  |  | _1,
|  |  | _2,
|  |  | _3,
|  |  | _4,
|  |  | _5,
|  |  | _6,
|  |  | _7,
|  |  | _8,
|  |  | _9
| ) |  | P_DECLARE_BITWISE_NAMES_8(_0,_1,_2,_3,_4,_5,_6,_7,_8),#_9

#define P_DECLARE_STREAMABLE_BITWISE_ENUM | ( |  | name,
|  |  | count,
|  |  | values
| ) |  | P_DECLARE_STREAMABLE_BITWISE_ENUM_EX(name, count, values, P_DECLARE_BITWISE_NAMES_##count values)

#define P_DECLARE_STREAMABLE_BITWISE_ENUM_EX | ( |  | name,
|  |  | count,
|  |  | values,
|  |  | ...
| ) |  |

Value:
enum name##_Bits { P_DECLARE_BITWISE_ENUM_##count values }; \
P_DECLARE_BITWISE_ENUM_FRIENDS(name) \
class name : public PStreamableBitwiseEnum<name##_Bits, (name##_Bits)(1<<count)>{ \
public: typedef PStreamableBitwiseEnum<name##_Bits, (name##_Bits)(1<<count)> BaseClass; \
__inline name(BaseClass::Enumeration e = BaseClass::Zero()) : BaseClass(e) { } \
__inline name(IteratorBounds b) : BaseClass(b) { } \
__inline explicit name(const PString & s) { FromString(s); } \
virtual char const * const * Names() const { static char const * const Strings[] = { __VA_ARGS__, NULL }; return Strings; } \
}

## Function Documentation

void PPrintBitwiseEnum | ( | std::ostream & | strm,
|  | unsigned | bits,
|  | char const *const * | names
| ) |  |

unsigned PReadBitwiseEnum | ( | std::istream & | strm,
|  | char const *const * | names,
|  | bool | continueOnError = `false`
| ) |  |

Referenced by PStreamableBitwiseEnum< BaseEnum, MaxValue, BaseInt >::FromString().