GlsMenu
gls_menu_data.h
Go to the documentation of this file.
1 
41 #if !defined(GLS_MENUDATA_H)
42 #define GLS_MENUDATA_H
43 
44 #ifdef WIN32
45 #pragma warning (disable:4786)
46 #endif
47 
48 #include <string>
49 #include <iomanip>
50 #include <iostream>
51 #include <stdio.h>
52 #include "gls_functor.h"
53 
54 #include "disti_metadata.h"
55 
56 
57 //============================================================================
65 //============================================================================
66 class GlsMenuData : public disti::DistiAttributeBase
67 {
68 public:
69 
70  //------------------------------------------------------------------------
77  //------------------------------------------------------------------------
78  GlsMenuData(const std::string& name, bool localStorage);
79 
80  //------------------------------------------------------------------------
84  //------------------------------------------------------------------------
85  virtual ~GlsMenuData();
86 
87  //------------------------------------------------------------------------
92  //------------------------------------------------------------------------
93  virtual void Inc(long amount = 1);
94 
95 private:
96 }; // end GlsMenuData
97 
98 
99 //============================================================================
105 //============================================================================
106 template <class T>
108 {
109 public:
110 
111  //------------------------------------------------------------------------
116  //------------------------------------------------------------------------
117  GlsMenuData_T(const std::string& name, T* data);
118 
119  //------------------------------------------------------------------------
124  //------------------------------------------------------------------------
125  GlsMenuData_T(const std::string& name, const T& value);
126 
127  //------------------------------------------------------------------------
133  //------------------------------------------------------------------------
134  GlsMenuData_T(const std::string& name);
135 
136  //------------------------------------------------------------------------
140  //------------------------------------------------------------------------
141  virtual ~GlsMenuData_T();
142 
143  //------------------------------------------------------------------------
149  //------------------------------------------------------------------------
150  virtual void Attach(T*& data);
151 
152  //------------------------------------------------------------------------
158  //------------------------------------------------------------------------
159  virtual bool ReferTo(T& data);
160 
161  //------------------------------------------------------------------------
165  //------------------------------------------------------------------------
166  virtual bool ValueChanged();
167 
168  //------------------------------------------------------------------------
172  //------------------------------------------------------------------------
173  virtual void ResetValueChanged();
174 
175  //------------------------------------------------------------------------
179  //------------------------------------------------------------------------
180  virtual std::ostream& WriteValue(std::ostream& outstr);
181 
182  //------------------------------------------------------------------------
190  //------------------------------------------------------------------------
191  virtual std::istream& ReadValue(std::istream& instr);
192 
193  //------------------------------------------------------------------------
198  //------------------------------------------------------------------------
199  void SetPrecision(int outputPrecision);
200 
201  //------------------------------------------------------------------------
205  //------------------------------------------------------------------------
206  virtual const T& Value() const;
207 
208  //------------------------------------------------------------------------
212  //------------------------------------------------------------------------
213  virtual T& Value();
214 
215  //------------------------------------------------------------------------
219  //------------------------------------------------------------------------
220  virtual void Value(const T& val);
221 
222 
223 protected:
224 
226  T* _data;
227 
230 
233 
236 
237 }; // end GlsMenuData_T
238 
239 // Specializations for output of floats and doubles
240 template <>
241 inline std::ostream& GlsMenuData_T<float>::WriteValue(std::ostream& outstr)
242 {
243  outstr << std::fixed << std::showpoint
244  << std::setprecision(_precision) << Value();
245  return outstr;
246 };
247 template <>
248 inline std::ostream& GlsMenuData_T<double>::WriteValue(std::ostream& outstr)
249 {
250  outstr << std::fixed << std::showpoint
251  << std::setprecision(_precision) << Value();
252  return outstr;
253 };
254 
255 
256 //============================================================================
262 //============================================================================
263 template <class T>
265 {
266 public:
267 
268  //------------------------------------------------------------------------
273  //------------------------------------------------------------------------
274  GlsMenuDiscrete_T(const std::string& name, T* data);
275 
276  //------------------------------------------------------------------------
281  //------------------------------------------------------------------------
282  GlsMenuDiscrete_T(const std::string& name, const T& value);
283 
284  //------------------------------------------------------------------------
288  //------------------------------------------------------------------------
289  virtual ~GlsMenuDiscrete_T();
290 
291  //------------------------------------------------------------------------
295  //------------------------------------------------------------------------
296  virtual void Inc(long amount = 1);
297 
298 }; // end GlsMenuDiscrete_T
299 
300 
301 //============================================================================
308 //============================================================================
309 class GlsMenuLine : public GlsMenuData_T<std::string>
310 {
311 public:
312 
313  //------------------------------------------------------------------------
318  //------------------------------------------------------------------------
319  GlsMenuLine(const std::string& name, std::string* data);
320 
321  //------------------------------------------------------------------------
326  //------------------------------------------------------------------------
327  GlsMenuLine(const std::string& name, const std::string& initialVal = "");
328 
329  //------------------------------------------------------------------------
333  //------------------------------------------------------------------------
334  virtual ~GlsMenuLine();
335 
336  //------------------------------------------------------------------------
340  //------------------------------------------------------------------------
341  virtual bool OkToWrite();
342 
343  //------------------------------------------------------------------------
347  //------------------------------------------------------------------------
348  virtual std::istream& ReadValue(std::istream& instr);
349 
350 }; // end GlsMenuLine
351 
352 
353 //============================================================================
360 //============================================================================
361 template <class T>
363 {
364 public:
365 
366  //------------------------------------------------------------------------
371  //------------------------------------------------------------------------
372  GlsMenuDataContainer_T(const std::string& name, T* data);
373 
374  //------------------------------------------------------------------------
379  //------------------------------------------------------------------------
380  GlsMenuDataContainer_T(const std::string& name, const T& value);
381 
382  //------------------------------------------------------------------------
388  //------------------------------------------------------------------------
389  GlsMenuDataContainer_T(const std::string& name);
390 
391  //------------------------------------------------------------------------
395  //------------------------------------------------------------------------
396  virtual ~GlsMenuDataContainer_T();
397 
398  //------------------------------------------------------------------------
404  //------------------------------------------------------------------------
405  virtual void Attach(T*& data);
406 
407  //------------------------------------------------------------------------
413  //------------------------------------------------------------------------
414  virtual bool ReferTo(T& data);
415 
416  //------------------------------------------------------------------------
420  //------------------------------------------------------------------------
421  virtual bool ValueChanged();
422 
423  //------------------------------------------------------------------------
427  //------------------------------------------------------------------------
428  virtual void ResetValueChanged();
429 
430  //------------------------------------------------------------------------
434  //------------------------------------------------------------------------
435  virtual std::ostream& WriteValue(std::ostream& outstr);
436 
437  //------------------------------------------------------------------------
445  //------------------------------------------------------------------------
446  virtual std::istream& ReadValue(std::istream& instr);
447 
448  //------------------------------------------------------------------------
453  //------------------------------------------------------------------------
454  void SetPrecision(int outputPrecision);
455 
456  //------------------------------------------------------------------------
460  //------------------------------------------------------------------------
461  virtual const T& Value() const;
462 
463  //------------------------------------------------------------------------
467  //------------------------------------------------------------------------
468  virtual T& Value();
469 
470  //------------------------------------------------------------------------
474  //------------------------------------------------------------------------
475  virtual void Value(const T& val);
476 
477 
478 protected:
479 
481  T* _data;
482 
485 
488 
491 
492 }; // end GlsMenuDataContainer_T
493 
494 
495 //============================================================================
500 //============================================================================
501 template <class MapT>
503 {
504 public:
505 
506  //------------------------------------------------------------------------
511  //------------------------------------------------------------------------
513  const std::string& name,
514  MapT* map,
515  GlsFunctor_T<GlsMenuData*>& CreateFunction);
516 
517  //------------------------------------------------------------------------
523  //------------------------------------------------------------------------
525  const std::string& name,
526  GlsFunctor_T<GlsMenuData*>& CreateFunction);
527 
528  //------------------------------------------------------------------------
532  //------------------------------------------------------------------------
533  virtual ~GlsMenuDataMap_T();
534 
535  //------------------------------------------------------------------------
539  //------------------------------------------------------------------------
540  virtual std::ostream& WriteValue(std::ostream& outstr);
541 
542  //------------------------------------------------------------------------
550  //------------------------------------------------------------------------
551  virtual std::istream& ReadValue(std::istream& instr);
552 
553 
554 protected:
555 
557  MapT* _dataMap;
558 
561 
562 }; // end GlsMenuDataMap_T
563 
564 
565 //----------------------------------------------------------------------------
572 //----------------------------------------------------------------------------
573 bool GetQuoted(std::istream& instr, std::string &theString);
574 
575 
576 //============================================================================
577 // Include inline method definitions
578 //============================================================================
579 #include "gls_menu_data.inl"
580 
581 #endif
582 
virtual std::ostream & WriteValue(std::ostream &outstr)
GlsMenuDiscrete_T(const std::string &name, T *data)
void SetPrecision(int outputPrecision)
virtual void Attach(T *&data)
virtual std::ostream & WriteValue(std::ostream &outstr)
virtual std::ostream & WriteValue(std::ostream &outstr)
virtual const T & Value() const
virtual void Attach(T *&data)
virtual ~GlsMenuLine()
GlsMenuDataContainer_T(const std::string &name, T *data)
bool GetQuoted(std::istream &instr, std::string &theString)
virtual ~GlsMenuDataContainer_T()
T _prevValue
The previous meta-data value.
bool _prevValueValid
Whether or not the previous value should be considered.
virtual std::istream & ReadValue(std::istream &instr)
T _prevValue
The previous meta-data value.
virtual ~GlsMenuDataMap_T()
virtual bool ValueChanged()
virtual bool OkToWrite()
virtual std::istream & ReadValue(std::istream &instr)
GlsFunctor_T< GlsMenuData * > & CreateDataItem
Functor that creates new data items.
virtual bool ReferTo(T &data)
virtual std::istream & ReadValue(std::istream &instr)
virtual ~GlsMenuData_T()
virtual bool ValueChanged()
This file defines generic function object (functor) classes.
void SetPrecision(int outputPrecision)
T * _data
Storage for the meta-data.
virtual void Inc(long amount=1)
MapT * _dataMap
Map Storage for the meta-data.
virtual const T & Value() const
int _precision
Allows for setting of precision for floating point numbers.
GlsMenuDataMap_T(const std::string &name, MapT *map, GlsFunctor_T< GlsMenuData * > &CreateFunction)
GlsMenuData_T(const std::string &name, T *data)
virtual std::istream & ReadValue(std::istream &instr)
bool _prevValueValid
Whether or not the previous value should be considered.
GlsMenuLine(const std::string &name, std::string *data)
virtual void ResetValueChanged()
virtual void ResetValueChanged()
T * _data
Storage for the meta-data.
virtual bool ReferTo(T &data)
virtual ~GlsMenuDiscrete_T()
int _precision
Allows for setting of precision for floating point numbers.
virtual void Inc(long amount=1)
GlsMenuData(const std::string &name, bool localStorage)
virtual ~GlsMenuData()