VR-Forces 4.0.4 Class Documentation
include/vrvCore/DtRecordSettingsBackup.h
Go to the documentation of this file.
00001 /****************************************************************************** 
00002 ** Copyright (c) 2010 MAK Technologies, Inc. 
00003 ** All rights reserved. 
00004 ******************************************************************************/ 
00005 /****************************************************************************** 
00006 ** $RCSfile: DtRecordSettingsBackup.h,v $ $Revision: 1.16 $ $State: Exp $ 
00007 ******************************************************************************/ 
00008  
00011  
00012 #pragma once
00013  
00014 #include <vrvCore/vrvCore.h> 
00015 #include <vrvCore/DtDe.h>
00016 #include <vrvCore/DtDeSettingsManager.h>
00017 #include <vrvCore/DtSettingsBackupManager.h>
00018 #include <vrvCore/DtSharedSettingsManager.h>
00019 #include <vrvCore/DtDeSettings.h>
00020 #include <vrvCore/DtWriteSettingsLock.h>
00021 
00022 namespace makVrv 
00023 {
00027    class DT_DLL_VRVCORE DtRecordSettingsBackupInterface : public DtSettingsBackup
00028    {
00029    public:
00030       DtRecordSettingsBackupInterface(DtDe& de, const std::string& classType, const std::string& descriptiveName)
00031       : myDe(de)
00032       , myClassType(classType)
00033       , myDescriptiveName(descriptiveName)
00034       , myCanBackup(true)
00035       {
00036          DtDeSettings* settings = DtDeSettingsManager::instance(myDe).findSettings(classType);
00037          if (settings)
00038          {
00039             setFactoryFile(settings->factoryFilePath());
00040          }
00041          DtSettingsBackupManager::instance(myDe).registerSettingsBackup(this);
00042       }
00043 
00044       DtRecordSettingsBackupInterface(const DtRecordSettingsBackupInterface& orig)
00045       : myDe(orig.myDe)
00046       , myClassType(orig.myClassType)
00047       , myCanBackup(orig.myCanBackup)
00048       , myDescriptiveName(orig.myDescriptiveName)
00049       {
00050       }
00051 
00052       virtual ~DtRecordSettingsBackupInterface()
00053       {
00054       }
00055 
00056       std::string backupClassType() const
00057       {
00058          return myClassType;
00059       }
00060       
00061       std::string backupName() const
00062       {
00063          return myDescriptiveName;
00064       }
00065 
00066       virtual void backup()
00067       {
00068          if (canBackup())
00069          {
00070             DtSettingsBackup::backup();
00071          }
00072       }
00073 
00074       void setCanBackup(bool b)
00075       {
00076          myCanBackup = b;
00077       }
00078 
00079       bool canBackup() const
00080       {
00081          return myCanBackup;
00082       }
00083 
00084    protected:
00085       DtDe&          myDe;
00086       std::string    myClassType;
00087       std::string    myDescriptiveName;
00088       bool           myCanBackup;
00089    };
00090 
00094    template <typename SettingsClass, typename ArchiveClass>
00095    class DtRecordSettingsBackup : public DtRecordSettingsBackupInterface
00096    { 
00097    public:
00098       DtRecordSettingsBackup(DtDe& de, SettingsClass* parent, const std::string& classType, const std::string& descriptiveName)
00099       : DtRecordSettingsBackupInterface(de, classType, descriptiveName)
00100       , myParent(parent)
00101       {
00102       }
00103 
00104       DtRecordSettingsBackup(const DtRecordSettingsBackup& orig)
00105       : DtRecordSettingsBackupInterface(orig)
00106       , myParent(orig.myParent)
00107       {
00108       }
00109 
00110       virtual ~DtRecordSettingsBackup()
00111       {
00112       }
00113 
00114       void restore(const DtSettingsBackup* from)
00115       {
00116          bool can = canBackup();
00117 
00118          setCanBackup(false);
00119 
00120          myParent->setFromRecord(
00121             ((DtRecordSettingsBackup<SettingsClass, ArchiveClass>*)from)->restoredRecord());
00122 
00123          setCanBackup(can);
00124       }
00125       
00126       DtSettingsBackup* create() const
00127       {
00128          return new DtRecordSettingsBackup<SettingsClass, ArchiveClass>(*this);
00129       }
00130 
00131       void write(boost::archive::xml_oarchive& ar)
00132       {
00133          ArchiveClass rec;
00134 
00135          myParent->getRecord(rec);
00136 
00137          ar << boost::serialization::make_nvp(myClassType.c_str(), rec);
00138       }
00139 
00140       void read(boost::archive::xml_iarchive& ar)
00141       {
00142          ar >> boost::serialization::make_nvp(myClassType.c_str(), myRestoredRecord);
00143       }
00144 
00145       const ArchiveClass& restoredRecord() const
00146       {
00147          return myRestoredRecord;
00148       }
00149 
00150    protected:
00151       ArchiveClass   myRestoredRecord;
00152       SettingsClass* myParent;
00153    };
00154 
00158    template <typename SettingsClass, typename ArchiveClass>
00159    class DtSharedRecordSettingsBackup : public DtSettingsBackup
00160    { 
00161    public:
00162 
00163       DtSharedRecordSettingsBackup(DtSharedSettingsManager& manager, const std::string& classType, const std::string& descriptiveName)
00164       : myManager(manager)
00165       , myClassType(classType)
00166       , myCanBackup(true)
00167       , myDescriptiveName(descriptiveName)
00168       {
00169       }
00170 
00171       virtual ~DtSharedRecordSettingsBackup()
00172       {
00173       }
00174 
00175       void restore(const DtSettingsBackup* from)
00176       {
00177          bool can = canBackup();
00178 
00179          myCanBackup = false;
00180 
00181          DtWriteSettingsLock<SettingsClass> settings(myManager);
00182 
00183          settings->setFromRecord(((DtSharedRecordSettingsBackup<SettingsClass, ArchiveClass>*)from)->restoredRecord());
00184 
00185          myCanBackup = can;
00186       }
00187 
00188       std::string backupClassType() const
00189       {
00190          return myClassType;
00191       }
00192       
00193       std::string backupName() const
00194       {
00195          return myDescriptiveName;
00196       }
00197 
00198       DtSettingsBackup* create() const
00199       {
00200          return new DtSharedRecordSettingsBackup<SettingsClass, ArchiveClass>(myManager, myClassType, myDescriptiveName);
00201       }
00202 
00203       void write(boost::archive::xml_oarchive& ar)
00204       {
00205          ar << boost::serialization::make_nvp(backupClassType().c_str(), myRestoredRecord);
00206       }
00207 
00208       void read(boost::archive::xml_iarchive& ar)
00209       {
00210          ar >> boost::serialization::make_nvp(backupClassType().c_str(), myRestoredRecord);
00211       }
00212 
00213       const ArchiveClass& restoredRecord() const
00214       {
00215          return myRestoredRecord;
00216       }
00217 
00218       void backup(const ArchiveClass& rec)
00219       {
00220          if (myCanBackup)
00221          {
00222             myRestoredRecord = rec;
00223             DtSettingsBackup::backup();
00224          }
00225       }
00226 
00227       void setCanBackup(bool b)
00228       {
00229          myCanBackup = b;
00230       }
00231 
00232       bool canBackup() const
00233       {
00234          return myCanBackup;
00235       }
00236 
00237    protected:
00238       DtSharedSettingsManager&   myManager;
00239       ArchiveClass               myRestoredRecord;
00240       bool                       myCanBackup;
00241       std::string                myClassType;
00242       std::string                myDescriptiveName;
00243    };
00244 } 

Document ID: Generated on Fri Jun 29 16:33:32 EDT 2012 from SVN revision 116588
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)