VR-Forces 4.7 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtRecordSettingsBackup.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2010 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 /******************************************************************************
6 ** $RCSfile: DtRecordSettingsBackup.h,v $ $Revision: 1.16 $ $State: Exp $
7 ******************************************************************************/
8 
11 
12 #pragma once
13 
14 #ifndef DtRecordSettingsBackup_H
15 #define DtRecordSettingsBackup_H
16 
17 #include <vrvCore/DtDe.h>
21 
22 namespace makVrv
23 {
28  {
29  public:
30  DtRecordSettingsBackupInterface(DtDe& de, const std::string& classType, const std::string& descriptiveName)
31  : myDe(de)
32  , myClassType(classType)
33  , myDescriptiveName(descriptiveName)
34  , myCanBackup(true)
35  {
36  DtDeSettings* settings = DtDeSettingsManager::instance(myDe).findSettings(classType);
37  if (settings)
38  {
39  setFactoryFile(settings->factoryFilePath());
40  }
42  }
43 
45  : myDe(orig.myDe)
46  , myClassType(orig.myClassType)
47  , myCanBackup(orig.myCanBackup)
48  , myDescriptiveName(orig.myDescriptiveName)
49  {
50  }
51 
53  {
54  }
55 
56  std::string backupClassType() const
57  {
58  return myClassType;
59  }
60 
61  std::string backupName() const
62  {
63  return myDescriptiveName;
64  }
65 
66  virtual void backup()
67  {
68  if (canBackup())
69  {
71  }
72  }
73 
74  virtual void backupByDir()
75  {
76  if (canBackup())
77  {
79  }
80  }
81 
82  void setCanBackup(bool b)
83  {
84  myCanBackup = b;
85  }
86 
87  bool canBackup() const
88  {
89  return myCanBackup;
90  }
91 
92  protected:
94  std::string myClassType;
95  std::string myDescriptiveName;
97  };
98 
102  template <typename SettingsClass, typename ArchiveClass>
104  {
105  public:
106  DtRecordSettingsBackup(DtDe& de, SettingsClass* parent, const std::string& classType, const std::string& descriptiveName)
107  : DtRecordSettingsBackupInterface(de, classType, descriptiveName)
108  , myParent(parent)
109  {
110  }
111 
114  , myParent(orig.myParent)
115  {
116  }
117 
119  {
120  }
121 
122  void restore(const DtSettingsBackup* from)
123  {
124  bool can = canBackup();
125 
126  setCanBackup(false);
127 
128  myParent->setFromRecord(
130 
131  setCanBackup(can);
132  }
133 
135  {
137  }
138 
139  void write(boost::archive::xml_oarchive& ar)
140  {
141  ArchiveClass rec;
142 
143  myParent->getRecord(rec);
144 
145  ar << boost::serialization::make_nvp(myClassType.c_str(), rec);
146  }
147 
148  // Allocates the outStreamVec, delete after use - use vec<ptr> for Linux build
149  void writeDir(std::vector<std::ostringstream*>& outStreamVec, std::vector<std::string>& fileNames)
150  {
151  std::vector<ArchiveClass> rec;
152 
153  myParent->getSplitRecord(rec, fileNames);
154 
155  assert(rec.size() == fileNames.size());
156 
157  unsigned int recSize = rec.size();
158  outStreamVec.resize(recSize);
159 
160  for (unsigned int i = 0; i < recSize; ++i)
161  {
162  outStreamVec[i] = new std::ostringstream();
163  boost::archive::xml_oarchive oa(*(outStreamVec[i]));
164 
165  oa << boost::serialization::make_nvp(myClassType.c_str(), rec[i]);
166  }
167  }
168 
169  void readRecords(boost::archive::xml_iarchive& ar, ArchiveClass& recordsResult)
170  {
171  ar >> boost::serialization::make_nvp(myClassType.c_str(), recordsResult);
172  }
173 
174  void readIncremental(boost::archive::xml_iarchive& ar)
175  {
176  ArchiveClass rec;
177  ar >> boost::serialization::make_nvp(myClassType.c_str(), rec);
178  myParent->addRecords(rec, myRestoredRecord);
179  }
180 
181  void read(boost::archive::xml_iarchive& ar)
182  {
183  ar >> boost::serialization::make_nvp(myClassType.c_str(), myRestoredRecord);
184  }
185 
186  const ArchiveClass& restoredRecord() const
187  {
188  return myRestoredRecord;
189  }
190 
191  protected:
192  ArchiveClass myRestoredRecord;
193  SettingsClass* myParent;
194  };
195 
199  template <typename SettingsClass, typename ArchiveClass>
201  {
202  public:
203 
204  DtSharedRecordSettingsBackup(DtSharedSettingsManager& manager, const std::string& classType, const std::string& descriptiveName)
205  : myManager(manager)
206  , myClassType(classType)
207  , myCanBackup(true)
208  , myDescriptiveName(descriptiveName)
209  {
210  }
211 
213  {
214  }
215 
216  void restore(const DtSettingsBackup* from)
217  {
218  bool can = canBackup();
219 
220  myCanBackup = false;
221 
223 
225 
226  myCanBackup = can;
227  }
228 
229  std::string backupClassType() const
230  {
231  return myClassType;
232  }
233 
234  std::string backupName() const
235  {
236  return myDescriptiveName;
237  }
238 
240  {
242  }
243 
244  void write(boost::archive::xml_oarchive& ar)
245  {
246  ar << boost::serialization::make_nvp(backupClassType().c_str(), myRestoredRecord);
247  }
248 
249  void read(std::vector<boost::archive::xml_iarchive>& ar)
250  {
251  if (!ar.empty())
252  {
253  ar[0] >> boost::serialization::make_nvp(backupClassType().c_str(), myRestoredRecord);
254  }
255  }
256 
257  void read(boost::archive::xml_iarchive& ar)
258  {
259  ar >> boost::serialization::make_nvp(backupClassType().c_str(), myRestoredRecord);
260  }
261 
262  const ArchiveClass& restoredRecord() const
263  {
264  return myRestoredRecord;
265  }
266 
267  void backup(const ArchiveClass& rec)
268  {
269  if (myCanBackup)
270  {
271  myRestoredRecord = rec;
273  }
274  }
275 
276  void setCanBackup(bool b)
277  {
278  myCanBackup = b;
279  }
280 
281  bool canBackup() const
282  {
283  return myCanBackup;
284  }
285 
286  protected:
288  ArchiveClass myRestoredRecord;
290  std::string myClassType;
291  std::string myDescriptiveName;
292  };
293 }
294 
295 #endif

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)