VR-Forces Development_Version Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
17 
20 
21 #include <vlutil/vlUtil.h>
22 
23 namespace makVrv
24 {
25 
34  template <typename RecordType>
36  {
37  public:
38 
43  DtCommonBaseSettingsManager( DtDe& de, const std::string& name,
44  const std::string& displayName, const std::string& ext )
45  : myName( name )
46  , myExtension( ext )
47  , myDisplayName( displayName )
49  , myAutoSaveFlag( true )
50  , mySettingsBackup( 0 )
51  , myDe( de )
52  {
53  // Create the settings object
55  }
56 
59  {
60  }
61 
65  virtual void autoSaveIfNecessary()
66  {
67  if ( autoSave() )
68  {
70  }
71  }
72 
75  virtual void setAutoSave( bool doit )
76  {
77  myAutoSaveFlag = doit;
78  }
79 
82  virtual bool autoSave() const
83  {
84  return myAutoSaveFlag;
85  }
86 
91  virtual void setUseDefaultSettingsRecord( bool useit )
92  {
94  }
95 
100  virtual bool useDefaultSettingsRecord() const
101  {
103  }
104 
108  {
109  DtDeSettings* deSettings =
111  if ( ! deSettings )
112  {
113  DtTHROW_NEW( DtCorruptedState, "DtDeSettings have gone missing!" );
114  }
115  return deSettings;
116  }
117 
120  virtual const DtDeSettings* settings() const
121  {
122  DtDeSettings* deSettings =
124  if ( ! deSettings )
125  {
126  DtTHROW_NEW( DtCorruptedState, "DtDeSettings have gone missing!" );
127  }
128  return deSettings;
129  }
130 
133  {
134  return mySettingsBackup;
135  }
136 
138  virtual const DtSettingsBackup* settingsBackup() const
139  {
140  return mySettingsBackup;
141  }
142 
145 
150  virtual void loadDefaults()
151  {
152  // Disable auto saving and store state.
153  bool autoSaved = autoSave();
154  setAutoSave( false );
155 
156  // Either set from the default record (if present) or load defaults.
157  RecordType record;
160  {
161  setFromRecord( record );
162  }
163  else
164  {
165  loadDefaultSettings( false );
166  }
167 
168  // Restore the auto save state.
169  setAutoSave( autoSaved );
170 
171  // Initialize the settings backup.
173  }
174 
176  virtual void initializeBackup() = 0;
177 
179  virtual void saveDefaultSettings()
180  {
181  RecordType record;
182  getRecord( record );
183  settings()->writeDefaultRecord( record );
184  }
185 
189  virtual void loadDefaultSettings( bool loadOnlyFactorySettings )
190  {
191  DtDeSettings* deSettings = settings();
192  RecordType record;
193  if ( loadOnlyFactorySettings )
194  {
195  if ( deSettings->readFactoryDefaultRecord(record) )
196  {
197  setFromRecord( record );
198  }
199  }
200  else
201  {
202  if ( deSettings->readDefaultRecord(record) )
203  {
204  setFromRecord( record );
205  }
206  }
207  }
208 
210  virtual void importSettings( const std::string& filePath )
211  {
212  RecordType record;
213  if ( settings()->readRecordFrom(record,filePath) )
214  {
215  setFromRecord( record );
217  }
218  }
219 
221  virtual void exportSettings( const std::string& filePath ) const
222  {
223  RecordType record;
224  getRecord( record );
225  settings()->writeRecordTo( record, filePath );
226  }
227 
229  virtual void setFromRecord( const RecordType& record ) = 0;
230 
232  virtual void getRecord( RecordType& record ) const = 0;
233 
235 
236  protected:
237 
239 
240  std::string myName;
241  std::string myExtension;
242  std::string myDisplayName;
243 
246 
248 
250 
251  };
252 
253 
261  template <typename RecordType>
263  {
264  protected:
265 
268 
269  public:
270 
273  DtBaseSettingsManager( DtDe& de, const std::string& name,
274  const std::string& displayName, const std::string& ext )
275  : DtCommonBaseSettingsManager<RecordType>( de, name, displayName, ext )
276  {
277  }
278 
281  {
282  DtDELETE( this->mySettingsBackup );
283  }
284 
287 
289  virtual void initializeBackup()
290  {
291  DtDELETE( this->mySettingsBackup );
292  this->mySettingsBackup = new RecordBackupType( this->myDe, this, this->myName, this->myDisplayName );
293  this->mySettingsBackup->setFactoryFile( this->settings()->factoryFilePath() );
295  this->mySettingsBackup->backup();
296  }
297 
299  virtual void setFromRecord( const RecordType& record ) = 0;
300 
302  virtual void getRecord( RecordType& record ) const = 0;
303 
305 
306  };
307 
308 
322  template <typename RecordType,typename SettingsType>
324  {
325  protected:
326 
329 
330  public:
331 
334  DtBaseSharedSettingsManager( DtDe& de, const std::string& name,
335  const std::string& displayName, const std::string& ext )
336  : DtCommonBaseSettingsManager<RecordType>( de, name, displayName, ext )
337  {
338  }
339 
342  {
343  // Don't delete the settings backup (it's owned by the settings object).
344  }
345 
348 
350  virtual void initializeBackup()
351  {
353  writeSettings( DtSharedSettingsManager::instance(this->myDe) );
354  this->mySettingsBackup = writeSettings->settingsBackup();
355  this->mySettingsBackup->setFactoryFile( this->settings()->factoryFilePath() );
357  writeSettings->backup();
358  }
359 
361  virtual void setFromRecord( const RecordType& record )
362  {
363  {
366  settings->setFromRecord( record );
367  }
368  this->saveDefaultSettings();
369  }
370 
372  virtual void getRecord( RecordType& record ) const
373  {
376  settings->getRecord( record );
377  }
378 
380 
381  };
382 
383 }

Document ID: Generated on Mon Jul 4 01:00:18 EDT 2016 from SVN revision 166489
Copyright © 2005-2015 VT MÄK. All Rights Reserved (www.mak.com)