GlsMenu
gls_mfd.h
Go to the documentation of this file.
1 
42 #ifndef GLS_MFD_H
43 #define GLS_MFD_H
44 
45 #ifdef WIN32
46 #pragma warning (disable:4786)
47 #endif
48 
49 #include <string>
50 #include <iostream>
51 
52 //----------------------------------------------------------------------------
57 //----------------------------------------------------------------------------
58 namespace GlsMFD
59 {
60  enum Side_t {TOP, BOTTOM, LEFT, RIGHT, LAST_SIDE = RIGHT};
61 
62  static const unsigned NUM_OF_SIDES = 4;
63 
64  struct MenuItemId_t
65  {
67  unsigned pos;
68 
70  side(TOP), pos(0) {}
71  MenuItemId_t(Side_t MFDSide, unsigned position) :
72  side(MFDSide), pos(position) {}
73  bool operator==(const MenuItemId_t& r)
74  {
75  return side == r.side && pos == r.pos;
76  }
77  };
78 
79 
80  //------------------------------------------------------------------------
81  inline std::string Name(Side_t side)
82  {
83  std::string name;
84 
85  if (side == LEFT)
86  name = "LEFT";
87  else if (side == RIGHT)
88  name = "RIGHT";
89 
90  return name;
91  }
92 
93 
94 } // end namespace GlsMFD
95 
96 //----------------------------------------------------------------------------
97 // Stream Operators for the enumerated types
98 //----------------------------------------------------------------------------
99 
100 
101 //----------------------------------------------------------------------------
102 inline std::istream& operator>>(std::istream& instr, GlsMFD::MenuItemId_t& id)
103 {
104  GlsMFD::Side_t side;
105  bool sideError(false);
106  char sideChar('\0');
107  unsigned pos(0);
108  instr >> sideChar >> pos;
109 
110  switch (sideChar)
111  {
112  case 'T':
113  side = GlsMFD::TOP;
114  break;
115  case 'B':
116  side = GlsMFD::BOTTOM;
117  break;
118  case 'L':
119  side = GlsMFD::LEFT;
120  break;
121  case 'R':
122  side = GlsMFD::RIGHT;
123  break;
124  default:
125  sideError = true;
126  }
127 
128  if (!sideError && pos != 0)
129  {
130  id.side = side;
131  id.pos = pos;
132  }
133 
134  return instr;
135 }
136 
137 //----------------------------------------------------------------------------
138 inline std::ostream& operator<<(std::ostream& outstr, GlsMFD::MenuItemId_t id)
139 {
140  char sideChar('\0');
141 
142  switch (id.side)
143  {
144  case GlsMFD::TOP:
145  sideChar = 'T';
146  break;
147  case GlsMFD::BOTTOM:
148  sideChar = 'B';
149  break;
150  case GlsMFD::LEFT:
151  sideChar = 'L';
152  break;
153  case GlsMFD::RIGHT:
154  sideChar = 'R';
155  break;
156  }
157 
158  outstr << sideChar << id.pos;
159 
160  return outstr;
161 }
162 
163 //----------------------------------------------------------------------------
164 inline std::istream& operator>>(std::istream& instr, GlsMFD::Side_t& side)
165 {
166  std::string sideString;
167  instr >> sideString;
168 
169  if (sideString == "TOP")
170  side = GlsMFD::TOP;
171  else if (sideString == "BOTTOM")
172  side = GlsMFD::BOTTOM;
173  else if (sideString == "LEFT")
174  side = GlsMFD::LEFT;
175  else if (sideString == "RIGHT")
176  side = GlsMFD::RIGHT;
177 
178  return instr;
179 }
180 
181 //----------------------------------------------------------------------------
182 inline std::ostream& operator<<(std::ostream& outstr, GlsMFD::Side_t side)
183 {
184  std::string sideString;
185 
186  switch (side)
187  {
188  case GlsMFD::TOP:
189  sideString = "TOP";
190  break;
191  case GlsMFD::BOTTOM:
192  sideString = "BOTTOM";
193  break;
194  case GlsMFD::LEFT:
195  sideString = "LEFT";
196  break;
197  case GlsMFD::RIGHT:
198  sideString = "RIGHT";
199  break;
200  }
201 
202  outstr << sideString;
203 
204  return outstr;
205 }
206 
207 #endif // GLS_MFD_H
std::istream & operator>>(std::istream &instr, GlsMFD::MenuItemId_t &id)
Definition: gls_mfd.h:102
Side_t
Definition: gls_mfd.h:60
bool operator==(const MenuItemId_t &r)
Definition: gls_mfd.h:73
MenuItemId_t(Side_t MFDSide, unsigned position)
Definition: gls_mfd.h:71
std::string Name(Side_t side)
Definition: gls_mfd.h:81
std::ostream & operator<<(std::ostream &outstr, GlsMFD::MenuItemId_t id)
Definition: gls_mfd.h:138
Definition: gls_mfd.h:58
static const unsigned NUM_OF_SIDES
Definition: gls_mfd.h:62