diff options
author | Antonio Juarez <antonio.maria.juarez@live.com> | 2014-03-03 22:07:58 +0000 |
---|---|---|
committer | Antonio Juarez <antonio.maria.juarez@live.com> | 2014-03-03 22:07:58 +0000 |
commit | 296ae46ed8f8f6e5f986f978febad302e3df231a (patch) | |
tree | 1629164454a239308f33c9e12afb22e7f3cd8eeb /src/common/boost_serialization_helper.h | |
parent | changed name (diff) | |
download | monero-296ae46ed8f8f6e5f986f978febad302e3df231a.tar.xz |
moved all stuff to github
Diffstat (limited to '')
-rw-r--r-- | src/common/boost_serialization_helper.h | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/common/boost_serialization_helper.h b/src/common/boost_serialization_helper.h new file mode 100644 index 000000000..74016ae75 --- /dev/null +++ b/src/common/boost_serialization_helper.h @@ -0,0 +1,44 @@ +// Copyright (c) 2012-2013 The Cryptonote developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#pragma once + +#include <boost/archive/binary_oarchive.hpp> +#include <boost/archive/binary_iarchive.hpp> + + +namespace tools +{ + template<class t_object> + bool serialize_obj_to_file(t_object& obj, const std::string& file_path) + { + TRY_ENTRY(); + std::ofstream data_file; + data_file.open( file_path , std::ios_base::binary | std::ios_base::out| std::ios::trunc); + if(data_file.fail()) + return false; + + boost::archive::binary_oarchive a(data_file); + a << obj; + + return !data_file.fail(); + CATCH_ENTRY_L0("serialize_obj_to_file", false); + } + + template<class t_object> + bool unserialize_obj_from_file(t_object& obj, const std::string& file_path) + { + TRY_ENTRY(); + + std::ifstream data_file; + data_file.open( file_path, std::ios_base::binary | std::ios_base::in); + if(data_file.fail()) + return false; + boost::archive::binary_iarchive a(data_file); + + a >> obj; + return !data_file.fail(); + CATCH_ENTRY_L0("unserialize_obj_from_file", false); + } +} |