VR-Forces 4.6 Class Documentation
 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 /******************************************************************************
6 ** $RCSfile: DtBinaryFileIo.h,v $ $Revision: 1.7 $ $State: Exp $
7 ******************************************************************************/
8 
12 
13 #ifndef DtBinaryFileIo_H_
14 #define DtBinaryFileIo_H_
15 
16 #include <makArchives/makArchives.h>
17 
18 #include <boost/archive/binary_iarchive.hpp>
19 #include <boost/archive/binary_oarchive.hpp>
20 #include <iostream>
21 #include <fstream>
22 
23 namespace makArchives
24 {
25 
29  {
30 
31  public:
32 
36  template<typename T>
37  static bool write(const std::string& filePath, const T& t, const std::string& tagName = "Record")
38  {
39  try
40  {
42  std::ofstream ofs(filePath.c_str(), std::ios::out|std::ios::binary);
43  if(!ofs.is_open())
44  {
45  return false;
46  }
47 
48  assert(ofs.good());
49  boost::archive::binary_oarchive oa(ofs);
50  oa << boost::serialization::make_nvp(tagName.c_str(), t);
51  return true;
52  }
53  catch(...)
54  {
55  return false;
56  }
57  }
58 
62  template<typename T>
63  static bool read(const std::string& filePath, T& t, const std::string& tagName = "Record")
64  {
65  try
66  {
68  std::ifstream ifs(filePath.c_str(), std::ios::in|std::ios::binary);
69  if(!ifs.is_open())
70  {
71  return false;
72  }
73 
74  assert(ifs.good());
75  boost::archive::binary_iarchive ia(ifs);
77  ia >> boost::serialization::make_nvp(tagName.c_str(), t);
78  return true;
79  }
80  catch(...)
81  {
82  return false;
83  }
84  }
85 
86 
87  private:
88 
91 
92  };
93 }
94 
95 #endif
96 

Document ID: Generated on Thu Apr 12 03:15:37 EDT 2018 from SVN revision 187986
Copyright © 2005-2018 VT MÄK. All Rights Reserved (www.mak.com)