tue_serialization
src
filesystem.cpp
Go to the documentation of this file.
1
#include "
tue/serialization/filesystem.h
"
2
3
#include "
tue/serialization/conversions.h
"
4
5
#include <
fstream
>
6
7
namespace
tue
8
{
9
namespace
serialization
10
{
11
12
// ----------------------------------------------------------------------------------------------------
13
14
bool
toFile
(
const
Archive
& a,
const
std::string
& filename)
15
{
16
// Open filestream
17
std::ofstream
f_out;
18
f_out.
open
(filename.
c_str
(), std::ifstream::binary);
19
20
if
(!f_out.
is_open
())
21
return
false
;
22
23
// Copy archive content to file
24
convert
(a, f_out);
25
26
// Close file
27
f_out.
close
();
28
29
return
true
;
30
}
31
32
// ----------------------------------------------------------------------------------------------------
33
34
bool
fromFile
(
const
std::string
& filename,
Archive
& a)
35
{
36
std::ifstream
f_in;
37
f_in.
open
(filename.
c_str
(), std::ifstream::binary);
38
39
if
(!f_in.
is_open
())
40
return
false
;
41
42
// Copy file content into archive
43
convert
(f_in, a);
44
45
// Close file
46
f_in.
close
();
47
48
return
true
;
49
}
50
51
}
52
53
}
filesystem.h
fstream
std::string
tue::serialization::fromFile
bool fromFile(const std::string &filename, Archive &a)
Definition:
filesystem.cpp:34
tue::serialization::toFile
bool toFile(const Archive &a, const std::string &filename)
Definition:
filesystem.cpp:14
conversions.h
tue::serialization::convert
void convert(Archive &a, std::vector< unsigned char > &data)
Definition:
conversions.cpp:13
std::ofstream
std::string::c_str
T c_str(T... args)
std::ofstream::close
T close(T... args)
std::ofstream::open
T open(T... args)
tue::serialization::Archive
Definition:
archive.h:14
std::ofstream::is_open
T is_open(T... args)
tue
Definition:
archive.h:9
std::ifstream
Generated on Sun Feb 23 2025 04:34:27 for tue_serialization by
1.8.17