VR-Forces 5.0.2 Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtXmlFileIo.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2017 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #ifndef DtXmlFileIo_H_
11 #define DtXmlFileIo_H_
12 
13 #include <makArchives/makArchives.h>
14 
15 #include <boost/archive/xml_iarchive.hpp>
16 #include <boost/archive/xml_oarchive.hpp>
17 #include <iostream>
18 #include <string>
19 #include <fstream>
20 
21 #include <boost/iostreams/device/mapped_file.hpp>
22 #include <boost/iostreams/stream.hpp>
23 
24 namespace makArchives
25 {
26 
30  {
31 
32  public:
33 
37  template<typename T>
38  static bool write(const std::string& filePath, const T& t, const std::string& tagName = "Record")
39  {
40  try
41  {
43  std::ofstream ofs(filePath.c_str());
44  if(!ofs.is_open())
45  {
46  return false;
47  }
48 
49  assert(ofs.good());
50  boost::archive::xml_oarchive oa(ofs);
51  oa << boost::serialization::make_nvp(tagName.c_str(), t);
52  return true;
53  }
54  catch(...)
55  {
56  return false;
57  }
58  }
59 
63  template<typename T>
64  static bool read(const std::string& filePath, T& t, const std::string& tagName = "Record")
65  {
66  try
67  {
69  std::ifstream ifs(filePath.c_str());
70  if (!ifs.is_open())
71  {
72  return false;
73  }
74 
75  assert(ifs.good());
76  boost::archive::xml_iarchive ia(ifs);
78  ia >> boost::serialization::make_nvp(tagName.c_str(), t);
79  return true;
80  }
81  catch (boost::archive::archive_exception& ex)
82  {
83  std::cerr << "Archive Exception during deserializing:" << filePath << std::endl;
84  std::cerr << ex.what() << std::endl;
85  return false;
86  }
87  catch (...)
88  {
89  return false;
90  }
91  }
92 
93  private:
94 
96  DtXmlFileIo();
97 
98  };
99 
100 }
101 
102 #endif
103 
Contains DLL export macros.
static bool read(const std::string &filePath, T &t, const std::string &tagName="Record")
Definition: DtXmlFileIo.h:64
A DtXmlFileIo has the static functions for reading and writing to an XML archive. ...
Definition: DtXmlFileIo.h:29
#define DT_DLL_MAKARCHIVES
Definition: makArchives.h:31
static bool write(const std::string &filePath, const T &t, const std::string &tagName="Record")
Definition: DtXmlFileIo.h:38

Document ID: Generated on Sun Dec 4 20:22:03 EST 2022 from SVN revision 249613
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)