VR-Forces 4.1.1 Class Documentation
DtBaseSettingsManager.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (c) 2012 MAK Technologies, Inc.
3  * All rights reserved.
4  *****************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vrvUtil/vrvUtil.h>
13 
18 
21 
22 namespace makVrv
23 {
24 
33  template <typename RecordType>
35  {
36  public:
37 
42  DtCommonBaseSettingsManager( DtDe& de, const std::string& name,
43  const std::string& displayName, const std::string& ext )
44  : myName( name )
45  , myExtension( ext )
46  , myDisplayName( displayName )
48  , myAutoSaveFlag( true )
49  , mySettingsBackup( 0 )
50  , myDe( de )
51  {
52  // Create the settings object
54  }
55 
58  {
59  }
60 
64  virtual void autoSaveIfNecessary()
65  {
66  if ( autoSave() )
67  {
69  }
70  }
71 
74  virtual void setAutoSave( bool doit )
75  {
76  myAutoSaveFlag = doit;
77  }
78 
81  virtual bool autoSave() const
82  {
83  return myAutoSaveFlag;
84  }
85 
90  virtual void setUseDefaultSettingsRecord( bool useit )
91  {
93  }
94 
99  virtual bool useDefaultSettingsRecord() const
100  {
102  }
103 
107  {
108  DtDeSettings* deSettings =
110  if ( ! deSettings )
111  {
112  DtTHROW_NEW( DtCorruptedState, "DtDeSettings have gone missing!" );
113  }
114  return deSettings;
115  }
116 
119  virtual const DtDeSettings* settings() const
120  {
121  DtDeSettings* deSettings =
123  if ( ! deSettings )
124  {
125  DtTHROW_NEW( DtCorruptedState, "DtDeSettings have gone missing!" );
126  }
127  return deSettings;
128  }
129 
132  {
133  return mySettingsBackup;
134  }
135 
137  virtual const DtSettingsBackup* settingsBackup() const
138  {
139  return mySettingsBackup;
140  }
141 
144 
149  virtual void loadDefaults()
150  {
151  // Disable auto saving and store state.
152  bool autoSaved = autoSave();
153  setAutoSave( false );
154 
155  // Either set from the default record (if present) or load defaults.
156  RecordType record;
159  {
160  setFromRecord( record );
161  }
162  else
163  {
164  loadDefaultSettings( false );
165  }
166 
167  // Restore the auto save state.
168  setAutoSave( autoSaved );
169 
170  // Initialize the settings backup.
172  }
173 
175  virtual void initializeBackup() = 0;
176 
178  virtual void saveDefaultSettings()
179  {
180  RecordType record;
181  getRecord( record );
182  settings()->writeDefaultRecord( record );
183  }
184 
188  virtual void loadDefaultSettings( bool loadOnlyFactorySettings )
189  {
190  DtDeSettings* deSettings = settings();
191  RecordType record;
192  if ( loadOnlyFactorySettings )
193  {
194  if ( deSettings->readFactoryDefaultRecord(record) )
195  {
196  setFromRecord( record );
197  }
198  }
199  else
200  {
201  if ( deSettings->readDefaultRecord(record) )
202  {
203  setFromRecord( record );
204  }
205  }
206  }
207 
209  virtual void importSettings( const std::string& filePath )
210  {
211  RecordType record;
212  if ( settings()->readRecordFrom(record,filePath) )
213  {
214  setFromRecord( record );
216  }
217  }
218 
220  virtual void exportSettings( const std::string& filePath ) const
221  {
222  RecordType record;
223  getRecord( record );
224  settings()->writeRecordTo( record, filePath );
225  }
226 
228  virtual void setFromRecord( const RecordType& record ) = 0;
229 
231  virtual void getRecord( RecordType& record ) const = 0;
232 
234 
235  protected:
236 
238 
239  std::string myName;
240  std::string myExtension;
241  std::string myDisplayName;
242 
245 
247 
249 
250  };
251 
252 
260  template <typename RecordType>
262  {
263  protected:
264 
267 
268  public:
269 
272  DtBaseSettingsManager( DtDe& de, const std::string& name,
273  const std::string& displayName, const std::string& ext )
274  : DtCommonBaseSettingsManager<RecordType>( de, name, displayName, ext )
275  {
276  }
277 
280  {
281  DtDELETE( this->mySettingsBackup );
282  }
283 
286 
288  virtual void initializeBackup()
289  {
290  DtDELETE( this->mySettingsBackup );
291  this->mySettingsBackup = new RecordBackupType( this->myDe, this, this->myName, this->myDisplayName );
292  this->mySettingsBackup->setFactoryFile( this->settings()->factoryFilePath() );
294  this->mySettingsBackup->backup();
295  }
296 
298  virtual void setFromRecord( const RecordType& record ) = 0;
299 
301  virtual void getRecord( RecordType& record ) const = 0;
302 
304 
305  };
306 
307 
321  template <typename RecordType,typename SettingsType>
323  {
324  protected:
325 
328 
329  public:
330 
333  DtBaseSharedSettingsManager( DtDe& de, const std::string& name,
334  const std::string& displayName, const std::string& ext )
335  : DtCommonBaseSettingsManager<RecordType>( de, name, displayName, ext )
336  {
337  }
338 
341  {
342  // Don't delete the settings backup (it's owned by the settings object).
343  }
344 
347 
349  virtual void initializeBackup()
350  {
352  writeSettings( DtSharedSettingsManager::instance(this->myDe) );
353  this->mySettingsBackup = writeSettings->settingsBackup();
354  this->mySettingsBackup->setFactoryFile( this->settings()->factoryFilePath() );
356  writeSettings->backup();
357  }
358 
360  virtual void setFromRecord( const RecordType& record )
361  {
362  {
365  settings->setFromRecord( record );
366  }
367  this->saveDefaultSettings();
368  }
369 
371  virtual void getRecord( RecordType& record ) const
372  {
375  settings->getRecord( record );
376  }
377 
379 
380  };
381 
382 }

Document ID: Generated on Mon Apr 8 19:24:01 EDT 2013 from SVN revision 125877
Copyright © 2005-2013 VT MÄK. All Rights Reserved (www.mak.com)