pianod2
multisource multiuser scriptable networked music player
enum.h
Go to the documentation of this file.
1 
11 
12 #pragma once
13 
14 #include <assert.h>
15 
21 template <typename Enumeration, Enumeration end_element = Enumeration::Count>
22 class Enum {
23  static const Enumeration begin_element = static_cast <Enumeration> (0);
24  using enumeration_type = Enumeration;
25 public:
26  class Iterator {
28  public:
30  inline Iterator () { };
31 
33  inline Iterator (enumeration_type initial_value) :
34  value (initial_value)
35  { }
36 
37 
39  inline enumeration_type operator* (void) const
40  {
41  return value;
42  }
43 
46  {
47  value = enumeration_type (int (value) + 1);
48  assert (value <= end_element);
49  return value;
50  }
51 
54  {
55  enumeration_type old_value = value;
56  value = enumeration_type (int (value) + 1);
57  assert (value <= end_element);
58  return old_value;
59  }
60 
62  inline bool operator!=( Iterator compare_to )
63  {
64  return value != compare_to.value;
65  }
66 
68  inline bool operator==( Iterator compare_to )
69  {
70  return value == compare_to.value;
71  }
72  };
73 
75  inline static Iterator begin () {
76  return Iterator ();
77  }
78 
80  inline static Iterator end () {
81  return Iterator (end_element);
82  }
83 
84 #ifndef NDEBUG
85  inline bool isValid (Enumeration value) {
86  return (value < end_element);
87  }
88 #endif
89 
90 };
91 
Definition: enum.h:26
enumeration_type operator*(void) const
Get the current value of the iterator.
Definition: enum.h:39
bool operator==(Iterator compare_to)
Compare two iterators.
Definition: enum.h:68
enumeration_type value
Definition: enum.h:27
Iterator()
Create a new iterator, starting at value 0.
Definition: enum.h:30
enumeration_type operator++(void)
Move to the successor item (prefix form).
Definition: enum.h:45
Iterator(enumeration_type initial_value)
Create a new iterator, starting at a specified value.
Definition: enum.h:33
bool operator!=(Iterator compare_to)
Compare two iterators.
Definition: enum.h:62
Iteratate over the values of the enumeration.
Definition: enum.h:22
Enumeration enumeration_type
Definition: enum.h:24
static Iterator begin()
Get a new iterator for the first item of the enumeration.
Definition: enum.h:75
static Iterator end()
Get a new iterator for the terminator item of the enumeration.
Definition: enum.h:80
static const Enumeration begin_element
Definition: enum.h:23
bool isValid(Enumeration value)
Definition: enum.h:85
uint32_t value
Definition: audiooutput.cpp:68