vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Enumeration.h
Go to the documentation of this file.
1 
13 // header definitions
14 #ifndef _ENUMERATION_H_
15 #define _ENUMERATION_H_
16 
17 // attributes description includes
18 #include "Range.h"
19 
20 // variable arguments count includes
21 #include <stdarg.h>
22 
23 // STL includes
24 #include <string>
25 #include <list>
26 #include <set>
27 
28 // namespaces used
29 using namespace std;
30 
31 // VRECKO namespace
32 namespace vrecko
33 {
34 
53 template <class tval, class tref = tval>
54 class Enumeration : public Range
55 {
56 public:
57 
64  Enumeration(unsigned int valuesCount, ...)
65  : Range(Range::RANGE_ENUMERATION)
66  {
67  // initialize argument pointer
68  va_list argumentPtr;
69  va_start(argumentPtr, valuesCount);
70 
71  // loop through all the arguments
72  for (unsigned int i = 1; i < valuesCount; i++)
73  {
74  // insert the value into both containers
75  valuesList.push_back(va_arg(argumentPtr, tref));
76  valuesSet.insert(valuesList.back());
77  }
78 
79  // perform cleanup
80  va_end(argumentPtr);
81  }
82 
88  inline unsigned int valuesCount() const
89  {
90  return valuesList.size();
91  }
92 
100  inline bool containsValue(tref value) const
101  {
102  return (valuesSet.find(value) != valuesSet.end());
103  }
104 
108  inline void startIteration()
109  {
110  valuesListIter = valuesList.begin();
111  }
112 
124  inline bool hasNextValue() const
125  {
126  return (valuesListIter != valuesList.end());
127  }
128 
140  inline tref nextValue()
141  {
142  return *valuesListIter++;
143  }
144 
145 private:
146 
147  // containers
148  list<tval> valuesList;
149  set<tref> valuesSet;
150 
151  // internal list iterator
152  typename list<tval>::iterator valuesListIter;
153 };
154 
162 
167 
168 // end of vrecko namespace
169 }
170 
171 // end header definitions
172 #endif
173