gramods
Eye.hh
1 
2 #ifndef GRAMODS_GRAPHICS_EYE
3 #define GRAMODS_GRAPHICS_EYE
4 
5 #include <gmGraphics/config.hh>
6 
7 #include <stdexcept>
8 #include <cstddef>
9 #include <sstream>
10 
11 BEGIN_NAMESPACE_GMGRAPHICS;
12 
20 struct Eye {
21 
25  size_t idx;
26 
30  size_t count;
31 
37  void validate() {
38  if (valid()) return;
39 
40  std::stringstream ss;
41  ss << "Eye index " << idx << " is larger or equal to count " << count <<".";
42  throw std::out_of_range(ss.str());
43  }
44 
48  bool valid() { return idx < count; }
49 
54  bool operator<(const gramods::gmGraphics::Eye &e2) const {
55  return count < e2.count || (count == e2.count && idx < e2.idx);
56  }
57 
61  bool operator==(const gramods::gmGraphics::Eye &e2) const {
62  return count == e2.count && idx == e2.idx;
63  }
64 
68  static const Eye MONO;
69 
73  static const Eye LEFT;
74 
78  static const Eye RIGHT;
79 };
80 
81 END_NAMESPACE_GMGRAPHICS;
82 
83 BEGIN_NAMESPACE_GRAMODS;
84 
89 std::istream& operator>> (std::istream &in, gmGraphics::Eye &e);
90 
91 END_NAMESPACE_GRAMODS;
92 
93 #endif
An indexed eye that can be rendered.
Definition: Eye.hh:20
size_t idx
The index of the specific eye, starting at zero (0).
Definition: Eye.hh:25
static const Eye LEFT
Pre-defined left Eye for stereoscopic rendering.
Definition: Eye.hh:73
bool valid()
Returns true iff idx is smaller than count.
Definition: Eye.hh:48
size_t count
The total count of eyes of which the specified eye is one.
Definition: Eye.hh:30
void validate()
Check if the internal states are valid and throw exception if idx is not smaller than count.
Definition: Eye.hh:37
static const Eye RIGHT
Pre-defined right Eye for stereoscopic rendering.
Definition: Eye.hh:78
static const Eye MONO
Pre-defined Eye for monoscopic rendering.
Definition: Eye.hh:68
bool operator==(const gramods::gmGraphics::Eye &e2) const
Equals operator, returns true if this is identical to the other.
Definition: Eye.hh:61
bool operator<(const gramods::gmGraphics::Eye &e2) const
Less than operator, returns true if this has lower count or lower idx than the other.
Definition: Eye.hh:54