GlsMenu
gls_menu_dictionary.h
Go to the documentation of this file.
1 
41 #if !defined( GLS_MENUDICTIONARY_H )
42 # define GLS_MENUDICTIONARY_H
43 
44 # include <iomanip>
45 # include <string>
46 
47 # include "disti_metadata.h"
48 # include "gls_menu_data.h"
49 
50 //============================================================================
60 //============================================================================
62 {
63 public:
64  //------------------------------------------------------------------------
77  //------------------------------------------------------------------------
78  std::string Expand(
79  const std::string& str,
80  const char* startDelim = "$(",
81  const char* endDelim = ")" );
82 
83  //------------------------------------------------------------------------
91  //------------------------------------------------------------------------
92  template<class T>
93  void Attach( const std::string& name, T*& t )
94  {
95  GlsMenuData_T<T>* data = dynamic_cast<GlsMenuData_T<T>*>( Get( disti::AttributeName( name ) ) );
96  if( data )
97  data->Attach( t );
98  }
99 
100  //------------------------------------------------------------------------
111  //------------------------------------------------------------------------
112  template<class T>
113  bool Refer( const std::string& name, T& t )
114  {
115  bool success( false );
116  GlsMenuData_T<T>* data = dynamic_cast<GlsMenuData_T<T>*>( Get( disti::AttributeName( name ) ) );
117  if( data )
118  success = data->ReferTo( t );
119  return success;
120  }
121 
122  //------------------------------------------------------------------------
134  //------------------------------------------------------------------------
135  template<class T>
136  bool ReferCopy( const std::string& name, T& t )
137  {
138  bool success( false );
139  GlsMenuData_T<T>* data = dynamic_cast<GlsMenuData_T<T>*>( Get( disti::AttributeName( name ) ) );
140  if( data )
141  {
142  T currentVal = data->Value();
143  success = data->ReferTo( t );
144  if( success )
145  {
146  data->Value( currentVal );
147  }
148  }
149  return success;
150  }
151 
153  // The following types and functions forward to DistiAttribDict, which was formerly the base
154  // class of the present class but which was made a non-polymorphic value class in the GLS core
155  // for efficiency. These are retained here for backwards compatibility with existing user code.
157 
158  typedef disti::DistiAttribDict::const_iterator const_iterator;
159  typedef disti::DistiAttribDict::iterator iterator;
160 
165  DISTI_DEPRECATED( "Renamed to CopyCommonValues() to better represent the action taken by this function." )
166  GlsMenuDictionary& operator=( const disti::DistiAttribDict& dict )
167  {
168  CopyCommonValues( dict );
169  return *this;
170  }
171 
172  DISTI_DEPRECATED( "Renamed to CopyCommonValues() to better represent the action taken by this function." )
173  GlsMenuDictionary& operator=( const GlsMenuDictionary& dict )
174  {
175  CopyCommonValues( dict );
176  return *this;
177  }
178 
181  void CopyCommonValues( const disti::DistiAttribDict& dict ) { _attribDict.CopyCommonValues( dict ); }
182  void CopyCommonValues( const GlsMenuDictionary& dict ) { _attribDict.CopyCommonValues( dict._attribDict ); }
183 
187  bool operator==( const disti::DistiAttribDict& other ) { return _attribDict == other; }
188  bool operator==( const GlsMenuDictionary& other ) { return _attribDict == other._attribDict; }
189 
194  virtual void Add( disti::DistiAttributeBase* attr ) { _attribDict.Add( attr ); }
195 
196  const_iterator Begin() const { return _attribDict.Begin(); }
197  const_iterator End() const { return _attribDict.End(); }
198  iterator Begin() { return _attribDict.Begin(); }
199  iterator End() { return _attribDict.End(); }
200 
202  int Count() const { return _attribDict.Count(); }
203 
205  int Count( const disti::AttributeName& name ) const { return _attribDict.Count( name ); }
206 
208  void Clear() { _attribDict.Clear(); }
209 
213  virtual void Delete( const disti::AttributeName& name ) { _attribDict.Delete( name ); }
214 
221  virtual void ReadStrings( std::istream& instr ) { _attribDict.ReadStrings( instr ); }
222 
228  virtual void Write( std::ostream& outstr, bool changedDataOnly = false ) { _attribDict.Write( outstr, changedDataOnly ); }
229 
233  virtual bool Read( std::istream& instr ) { return _attribDict.Read( instr ); }
234 
239  bool ReadAndCaptureMissing( std::istream& instr, std::stringstream* missingStream ) { return _attribDict.ReadAndCaptureMissing( instr, missingStream ); }
240 
244  virtual std::string ValueString( const disti::AttributeName& name ) const { return _attribDict.ValueString( name ); }
245 
248  virtual void ValueString( const disti::AttributeName& name, const std::string& val ) { _attribDict.ValueString( name, val ); }
249 
251  long ValueInt( const disti::AttributeName& name ) const { return _attribDict.ValueInt( name ); }
252 
254  void ValueInt( const disti::AttributeName& name, long val ) { _attribDict.ValueInt( name, val ); }
255 
257  virtual std::ostream& WriteValue( const disti::AttributeName& name, std::ostream& outstr ) { return _attribDict.WriteValue( name, outstr ); }
258 
260  virtual std::istream& ReadValue( const disti::AttributeName& name, std::istream& instr ) { return _attribDict.ReadValue( name, instr ); }
261 
264  virtual disti::DistiAttributeBase* Get( const disti::AttributeName& name ) const { return _attribDict.Get( name ); }
265 
269  virtual bool IsEqual( const disti::AttributeName& name, const long val ) const { return _attribDict.IsEqual( name, val ); }
270 
272  static void SpacingInc() { disti::DistiAttribDict::SpacingInc(); }
273 
275  static void SpacingDec() { disti::DistiAttribDict::SpacingDec(); }
276 
278  static void SpacingZero() { disti::DistiAttribDict::SpacingZero(); }
279 
281  static std::string SpacingString() { return disti::DistiAttribDict::SpacingString(); }
282 
286  static bool ScanToken( std::istream& instr, std::string& result ) { return disti::DistiAttribDict::ScanToken( instr, result ); }
287 
292  virtual void Remove( const disti::AttributeName& name ) { _attribDict.Remove( name ); }
293 
294 private:
295  disti::DistiAttribDict _attribDict;
296 };
297 
298 #endif // GLS_MENUDICTIONARY_H
This file defines all menu meta-data classes.
bool operator==(const disti::DistiAttribDict &other)
bool ReferCopy(const std::string &name, T &t)
static bool ScanToken(std::istream &instr, std::string &result)
void ValueInt(const disti::AttributeName &name, long val)
static void SpacingZero()
virtual const T & Value() const
virtual void Attach(T *&data)
const_iterator Begin() const
virtual void Write(std::ostream &outstr, bool changedDataOnly=false)
virtual void Add(disti::DistiAttributeBase *attr)
const_iterator End() const
disti::DistiAttribDict::const_iterator const_iterator
int Count(const disti::AttributeName &name) const
virtual bool IsEqual(const disti::AttributeName &name, const long val) const
virtual std::istream & ReadValue(const disti::AttributeName &name, std::istream &instr)
virtual disti::DistiAttributeBase * Get(const disti::AttributeName &name) const
long ValueInt(const disti::AttributeName &name) const
void CopyCommonValues(const disti::DistiAttribDict &dict)
virtual void ValueString(const disti::AttributeName &name, const std::string &val)
static std::string SpacingString()
disti::DistiAttribDict _attribDict
bool ReadAndCaptureMissing(std::istream &instr, std::stringstream *missingStream)
virtual bool ReferTo(T &data)
virtual std::string ValueString(const disti::AttributeName &name) const
void Attach(const std::string &name, T *&t)
bool operator==(const GlsMenuDictionary &other)
virtual void Delete(const disti::AttributeName &name)
disti::DistiAttribDict::iterator iterator
virtual void ReadStrings(std::istream &instr)
virtual bool Read(std::istream &instr)
virtual void Remove(const disti::AttributeName &name)
virtual std::ostream & WriteValue(const disti::AttributeName &name, std::ostream &outstr)
void CopyCommonValues(const GlsMenuDictionary &dict)
bool Refer(const std::string &name, T &t)
std::string Expand(const std::string &str, const char *startDelim="$(", const char *endDelim=")")
static void SpacingDec()
static void SpacingInc()