![]() |
VR-Forces 4.0.4 Class Documentation
|
00001 /****************************************************************************** 00002 ** Copyright (c) 2007 MAK Technologies, Inc. 00003 ** All rights reserved. 00004 ******************************************************************************/ 00005 /****************************************************************************** 00006 ** $RCSfile: DtXmlFileIo.h,v $ $Revision: 1.7 $ $State: Exp $ 00007 ******************************************************************************/ 00008 00012 00013 #ifndef DtXmlFileIo_H_ 00014 #define DtXmlFileIo_H_ 00015 00016 #include <makArchives/makArchives.h> 00017 00018 #include <boost/archive/xml_iarchive.hpp> 00019 #include <boost/archive/xml_oarchive.hpp> 00020 #include <iostream> 00021 #include <string> 00022 #include <fstream> 00023 00024 namespace makArchives 00025 { 00026 00029 class DT_DLL_MAKARCHIVES DtXmlFileIo 00030 { 00031 00032 public: 00033 00037 template<typename T> 00038 static bool write(const std::string& filePath, const T& t, const std::string& tagName = "Record") 00039 { 00040 try 00041 { 00043 std::ofstream ofs(filePath.c_str()); 00044 if(!ofs.is_open()) 00045 { 00046 return false; 00047 } 00048 00049 assert(ofs.good()); 00050 boost::archive::xml_oarchive oa(ofs); 00051 oa << boost::serialization::make_nvp(tagName.c_str(), t); 00052 return true; 00053 } 00054 catch(...) 00055 { 00056 return false; 00057 } 00058 } 00059 00063 template<typename T> 00064 static bool read(const std::string& filePath, T& t, const std::string& tagName = "Record") 00065 { 00066 try 00067 { 00069 std::ifstream ifs(filePath.c_str()); 00070 if(!ifs.is_open()) 00071 { 00072 return false; 00073 } 00074 00075 assert(ifs.good()); 00076 boost::archive::xml_iarchive ia(ifs); 00078 ia >> boost::serialization::make_nvp(tagName.c_str(), t); 00079 return true; 00080 } 00081 catch(...) 00082 { 00083 return false; 00084 } 00085 } 00086 00087 00088 private: 00089 00091 DtXmlFileIo(); 00092 00093 }; 00094 00095 } 00096 00097 #endif 00098