VR-Forces 4.7 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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 
236  virtual void getSplitRecord(std::vector<RecordType>& rec,
237  std::vector<std::string>& fileNames) {};
238 
241  virtual void addRecords(RecordType& rec, RecordType& combinedRec) {};
242 
244 
245  protected:
246 
248 
249  std::string myName;
250  std::string myExtension;
251  std::string myDisplayName;
252 
255 
257 
259 
260  };
261 
262 
270  template <typename RecordType>
272  {
273  protected:
274 
277 
278  public:
279 
282  DtBaseSettingsManager( DtDe& de, const std::string& name,
283  const std::string& displayName, const std::string& ext )
284  : DtCommonBaseSettingsManager<RecordType>( de, name, displayName, ext )
285  {
286  }
287 
290  {
291  DtDELETE( this->mySettingsBackup );
292  }
293 
296 
298  virtual void initializeBackup()
299  {
300  DtDELETE( this->mySettingsBackup );
301  this->mySettingsBackup = new RecordBackupType( this->myDe, this, this->myName, this->myDisplayName );
302  this->mySettingsBackup->setFactoryFile( this->settings()->factoryFilePath() );
304  this->mySettingsBackup->backup();
305  }
306 
308  virtual void setFromRecord( const RecordType& record ) = 0;
309 
311  virtual void getRecord( RecordType& record ) const = 0;
312 
314 
315  };
316 
317 
331  template <typename RecordType,typename SettingsType>
333  {
334  protected:
335 
338 
339  public:
340 
343  DtBaseSharedSettingsManager( DtDe& de, const std::string& name,
344  const std::string& displayName, const std::string& ext )
345  : DtCommonBaseSettingsManager<RecordType>( de, name, displayName, ext )
346  {
347  }
348 
351  {
352  // Don't delete the settings backup (it's owned by the settings object).
353  }
354 
357 
359  virtual void initializeBackup()
360  {
362  writeSettings( DtSharedSettingsManager::instance(this->myDe) );
363  this->mySettingsBackup = writeSettings->settingsBackup();
364  this->mySettingsBackup->setFactoryFile( this->settings()->factoryFilePath() );
366  writeSettings->backup();
367  }
368 
370  virtual void setFromRecord( const RecordType& record )
371  {
372  {
375  settings->setFromRecord( record );
376  }
377  this->saveDefaultSettings();
378  }
379 
381  virtual void getRecord( RecordType& record ) const
382  {
385  settings->getRecord( record );
386  }
387 
389 
390  };
391 
392 }

Document ID: Generated on Fri Apr 26 21:53:14 EDT 2019 from SVN revision 197883
Copyright © 2005-2019 VT MAK. All Rights Reserved (www.mak.com)