VR-Forces 5.0.1 Developer's Guide
 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 }
virtual DtDeSettings * findSettings(const std::string &settingsType)
Get the settings object for a particular settings type. If the Settings of the given type does not ex...
virtual void loadDefaultSettings(bool loadOnlyFactorySettings)
Loads the default settings from disk. If loadOnlyFactorySettings is true, only the factory record wil...
Definition: DtBaseSettingsManager.h:189
Base class for (non-shared) settings managers. Extends the functionality provided by the DtCommonBase...
Definition: DtBaseSettingsManager.h:271
Base class for shared settings managers. Extends the functionality provided by the DtCommonBaseSettin...
Definition: DtBaseSettingsManager.h:332
a read settings lock on a setting object. The object can only get read access aka const functions...
Definition: DtReadSettingsLock.h:48
virtual void initializeBackup()=0
Creates a backup of the settings&#39; current state (abstract).
virtual void addRecords(RecordType &rec, RecordType &combinedRec)
For directory support, when reading in a directory, add the records from each file to the combined re...
Definition: DtBaseSettingsManager.h:241
static DtDeSettingsManager & instance(DtDe &de)
Get an instance of the settings manager.
bool myAutoSaveFlag
Definition: DtBaseSettingsManager.h:254
Virtual base class. Allows for RTTI and proper virtual destruction. Used by Creators, Factories, Providers, Assemblers and User Interfaces.
Definition: DtVirtualBaseClass.h:19
Interaction makVrv::DtWriteSettingsLock class.
virtual bool useDefaultSettingsRecord() const
Gets whether setting initialization should check for a default record. If set and a default record is...
Definition: DtBaseSettingsManager.h:100
virtual void setUseDefaultSettingsRecord(bool useit)
Sets whether setting initialization should check for a default record. If set and a default record is...
Definition: DtBaseSettingsManager.h:91
virtual void initializeBackup()
Creates a backup of the settings&#39; current state.
Definition: DtBaseSettingsManager.h:359
virtual void autoSaveIfNecessary()
Saves the current settings as defaults if autosave is enabled. This method is mainly provided to make...
Definition: DtBaseSettingsManager.h:65
virtual void getRecord(RecordType &record) const
Store the current settings&#39; state in the given record.
Definition: DtBaseSettingsManager.h:381
DtSignalConnectionManager myConnections
Definition: DtBaseSettingsManager.h:241
std::string myExtension
Definition: DtBaseSettingsManager.h:250
bool findDefaultSettingsRecord(const std::string &name, RecordType &record) const
Find a settings default records.
Definition: DtDeInitializer.h:362
Common base class for all types of settings managers. This class provides the interface for creating ...
Definition: DtBaseSettingsManager.h:35
virtual bool autoSave() const
Gets whether autosave is enabled for the settings manager. If autosave is enabled, the settings will be saved as they&#39;re changed.
Definition: DtBaseSettingsManager.h:82
virtual ~DtBaseSharedSettingsManager()
Virtual DTOR.
Definition: DtBaseSettingsManager.h:350
The makVrv::DtRecordSettingsBackup is a templaced class that settings records will use in order to ba...
Definition: DtRecordSettingsBackup.h:100
virtual void saveDefaultSettings()
Saves the current settings&#39; state as the default (on disk).
Definition: DtBaseSettingsManager.h:179
bool readDefaultRecord(RecordType &r)
Read a record from the default settings.
DtSharedRecordSettingsBackup< SettingsType, RecordType > SharedRecordBackupType
Definition: DtBaseSettingsManager.h:337
Contains DLL export macros.
DtSettingsBackup * mySettingsBackup
Definition: DtBaseSettingsManager.h:256
void setFactoryFile(const std::string &s)
Definition: DtSettingsBackup.h:170
virtual void getRecord(RecordType &record) const =0
Store the current settings&#39; state in the given record (abstract).
bool writeRecordTo(const RecordType &r, const std::string &exportFileName) const
Write a record to a specific location.
Contains makVrv::DtVirtualBaseClass class.
DtDe & myDe
Definition: DtBaseSettingsManager.h:258
virtual DtSettingsBackup * settingsBackup()
Accessor for the manager&#39;s settings backup.
Definition: DtBaseSettingsManager.h:132
DtBaseSettingsManager(DtDe &de, const std::string &name, const std::string &displayName, const std::string &ext)
CTOR.
Definition: DtBaseSettingsManager.h:282
std::string myDisplayName
Definition: DtBaseSettingsManager.h:251
bool myUseDefaultSettingsRecordFlag
Definition: DtBaseSettingsManager.h:253
virtual void initializeBackup()
Creates a backup of the settings&#39; current state.
Definition: DtBaseSettingsManager.h:298
Class to manage disconnection of boost connections on deletion.
Definition: DtSignalConnectionManager.h:20
static DtSharedSettingsManager & instance(DtDe &)
Get an instance of the shared settings manager from the DtDe;.
Provides a method of doign settings backup.
Definition: DtSettingsBackup.h:23
std::string myName
Definition: DtBaseSettingsManager.h:249
a write settings lock on a setting object. The object can be read and modified, but no other threads ...
Definition: DtWriteSettingsLock.h:47
virtual ~DtBaseSettingsManager()
Virtual DTOR.
Definition: DtBaseSettingsManager.h:289
virtual void getSplitRecord(std::vector< RecordType > &rec, std::vector< std::string > &fileNames)
For directory support, split the main record into different sub-records and give them each a file nam...
Definition: DtBaseSettingsManager.h:236
DtCommonBaseSettingsManager(DtDe &de, const std::string &name, const std::string &displayName, const std::string &ext)
CTOR The name, displayName, and extension parameters are used for creating the settings object (DtDeS...
Definition: DtBaseSettingsManager.h:43
Contains makVrv::DtReadSettingsLock class.
virtual void createSettings(const std::string &settingsType, const std::string &settingsExt)
Create a settings object with a name and extension.
bool readFactoryDefaultRecord(RecordType &r)
virtual void importSettings(const std::string &filePath)
Load the settings&#39; state from the given file.
Definition: DtBaseSettingsManager.h:210
Base class to provide boost signal/slot management.
virtual DtDeSettings * settings()
Accessor for the manager&#39;s DtDeSettings object.
Definition: DtBaseSettingsManager.h:107
Settings class for reading and writing settings to/from files.
Definition: DtDeSettings.h:29
virtual void backup()
Backs up settings to backup file. If file does not exist, will create. Emits signal_backedUp when thi...
DtBaseSharedSettingsManager(DtDe &de, const std::string &name, const std::string &displayName, const std::string &ext)
CTOR.
Definition: DtBaseSettingsManager.h:343
virtual void loadDefaults()
Initializes the settings and creates a backup. If the useDefaultSettingsRecord is enabled and a defau...
Definition: DtBaseSettingsManager.h:150
virtual void registerSettingsBackup(DtSettingsBackup *backup)
Registers the settings class with the manager. If the name supplied for registration already exists...
virtual void setFromRecord(const RecordType &record)=0
Set the current settings&#39; state from the given record (abstract).
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer, DtDeCommunicator, as well as a DtDisplay and other things.
Definition: DtDe.h:70
virtual const DtSettingsBackup * settingsBackup() const
Accessor for the manager&#39;s settings backup (const).
Definition: DtBaseSettingsManager.h:138
virtual void setAutoSave(bool doit)
Sets whether autosave is enabled for the settings manager. If autosave is enabled, the settings will be saved as they&#39;re changed.
Definition: DtBaseSettingsManager.h:75
virtual void getRecord(RecordType &record) const =0
Store the current settings&#39; state in the given record (abstract).
virtual void setFromRecord(const RecordType &record)
Set the current settings&#39; state from the given record.
Definition: DtBaseSettingsManager.h:370
virtual ~DtCommonBaseSettingsManager()
Virtual DTOR.
Definition: DtBaseSettingsManager.h:58
virtual void exportSettings(const std::string &filePath) const
Save the current settings&#39; state to the given file.
Definition: DtBaseSettingsManager.h:221
virtual const DtDeInitializer & deInitializer() const
Return the DtDeInitializer.
The makVrv::DtSharedRecordSettingsBackup is a templaced class that settings records will use in order...
Definition: DtRecordSettingsBackup.h:197
DtRecordSettingsBackup< DtBaseSettingsManager< RecordType >, RecordType > RecordBackupType
Definition: DtBaseSettingsManager.h:276
bool writeDefaultRecord(const RecordType &r)
Write a record as the default settings.
virtual void setFromRecord(const RecordType &record)=0
Set the current settings&#39; state from the given record (abstract).
virtual const DtDeSettings * settings() const
Accessor for the manager&#39;s DtDeSettings object (const).
Definition: DtBaseSettingsManager.h:120
static DtSettingsBackupManager & instance(DtDe &de)
Get an instance of the settings manager.

Document ID: Generated on Mon Jun 20 00:38:30 EDT 2022 from SVN revision 244029
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)