VR-Forces 5.0.3 Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtBinaryFileIo.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2013 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #ifndef DtBinaryFileIo_H_
11 #define DtBinaryFileIo_H_
12 
13 #include <makArchives/makArchives.h>
14 
15 #include <boost/archive/binary_iarchive.hpp>
16 #include <boost/archive/binary_oarchive.hpp>
17 #include <iostream>
18 #include <fstream>
19 
20 namespace makArchives
21 {
22 
26  {
27 
28  public:
29 
33  template<typename T>
34  static bool write(const std::string& filePath, const T& t, const std::string& tagName = "Record")
35  {
36  try
37  {
39  std::ofstream ofs(filePath.c_str(), std::ios::out|std::ios::binary);
40  if(!ofs.is_open())
41  {
42  return false;
43  }
44 
45  assert(ofs.good());
46  boost::archive::binary_oarchive oa(ofs);
47  oa << boost::serialization::make_nvp(tagName.c_str(), t);
48  return true;
49  }
50  catch(...)
51  {
52  return false;
53  }
54  }
55 
59  template<typename T>
60  static bool read(const std::string& filePath, T& t, const std::string& tagName = "Record")
61  {
62  try
63  {
65  std::ifstream ifs(filePath.c_str(), std::ios::in|std::ios::binary);
66  if(!ifs.is_open())
67  {
68  return false;
69  }
70 
71  assert(ifs.good());
72  boost::archive::binary_iarchive ia(ifs);
74  ia >> boost::serialization::make_nvp(tagName.c_str(), t);
75  return true;
76  }
77  catch(...)
78  {
79  return false;
80  }
81  }
82 
83 
84  private:
85 
88 
89  };
90 }
91 
92 #endif
93 
static bool write(const std::string &filePath, const T &t, const std::string &tagName="Record")
Definition: DtBinaryFileIo.h:34
Contains DLL export macros.
A DtBinaryFileIo has the static functions for reading and writing to an Binary archive.
Definition: DtBinaryFileIo.h:25
static bool read(const std::string &filePath, T &t, const std::string &tagName="Record")
Definition: DtBinaryFileIo.h:60
#define DT_DLL_MAKARCHIVES
Definition: makArchives.h:31

Document ID: Generated on Thu Jun 1 17:58:13 EDT 2023 from SVN revision 255404
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)