VR-Forces 4.3.1 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 <string>
22 #include <fstream>
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(), std::ios::out|std::ios::binary);
44  if(!ofs.is_open())
45  {
46  return false;
47  }
48 
49  assert(ofs.good());
50  boost::archive::binary_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(), std::ios::in|std::ios::binary);
70  if(!ifs.is_open())
71  {
72  return false;
73  }
74 
75  assert(ifs.good());
76  boost::archive::binary_iarchive ia(ifs);
78  ia >> boost::serialization::make_nvp(tagName.c_str(), t);
79  return true;
80  }
81  catch(...)
82  {
83  return false;
84  }
85  }
86 
87 
88  private:
89 
92 
93  };
94 }
95 
96 #endif
97 

Document ID: Generated on Wed Jul 29 00:55:00 EDT 2015 from SVN revision 155257
Copyright © 2005-2015 VT MÄK. All Rights Reserved (www.mak.com)