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