-
Notifications
You must be signed in to change notification settings - Fork 51
/
fstream.h
124 lines (101 loc) · 3.9 KB
/
fstream.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#ifndef K3DSDK_FSTREAM_H
#define K3DSDK_FSTREAM_H
// K-3D
// Copyright (c) 1995-2005, Timothy M. Shead
//
// Contact: [email protected]
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
/** \file
\author Tim Shead ([email protected])
*/
#include <k3dsdk/path.h>
#include <fstream>
namespace k3d
{
namespace filesystem
{
/// Convenience wrapper for standard fstream that opens a k3d::filesystem::path in binary mode
template< class charT, class traits = std::char_traits<charT> >
class basic_ifstream : public std::basic_ifstream<charT,traits>
{
public:
basic_ifstream()
{
}
explicit basic_ifstream(const path& file, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::binary) :
std::basic_ifstream<charT,traits>(file.native_filesystem_string().c_str(), mode)
{
}
virtual ~basic_ifstream()
{
}
void open(const path& file, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::binary)
{
std::basic_ifstream<charT,traits>::open(file.native_filesystem_string().c_str(), mode);
}
};
/// Convenience wrapper for standard fstream that opens a k3d::filesystem::path in binary mode
typedef basic_ifstream<char> ifstream;
// typedef basic_ifstream<wchar_t> wifstream; // Why do you want to use this? It isn't portable, and you should be using UTF-8!
/// Convenience wrapper for standard fstream that opens a k3d::filesystem::path in binary mode
template < class charT, class traits = std::char_traits<charT> >
class basic_ofstream : public std::basic_ofstream<charT,traits>
{
public:
basic_ofstream()
{
}
explicit basic_ofstream(const path& file, std::ios_base::openmode mode = std::ios_base::out | std::ios_base::binary) :
std::basic_ofstream<charT,traits>(file.native_filesystem_string().c_str(), mode)
{
}
virtual ~basic_ofstream()
{
}
void open(const path& file, std::ios_base::openmode mode = std::ios_base::out | std::ios_base::binary)
{
std::basic_ofstream<charT,traits>::open(file.native_filesystem_string().c_str(), mode);
}
};
/// Convenience wrapper for standard fstream that opens a k3d::filesystem::path in binary mode
typedef basic_ofstream<char> ofstream;
// typedef basic_ofstream<wchar_t> wofstream; // Why do you want to use this? It isn't portable, and you should be using UTF-8!
/// Convenience wrapper for standard fstream that opens a k3d::filesystem::path in binary mode
template < class charT, class traits = std::char_traits<charT> >
class basic_fstream : public std::basic_fstream<charT,traits>
{
public:
basic_fstream()
{
}
explicit basic_fstream(const path& file, std::ios_base::openmode mode = std::ios_base::in|std::ios_base::out | std::ios_base::binary) :
std::basic_fstream<charT,traits>(file.native_filesystem_string(), mode)
{
}
virtual ~basic_fstream()
{
}
void open(const path& file, std::ios_base::openmode mode = std::ios_base::in|std::ios_base::out | std::ios_base::binary)
{
std::basic_fstream<charT,traits>::open(file.native_filesystem_string().c_str(), mode);
}
};
/// Convenience wrapper for standard fstream that opens a k3d::filesystem::path in binary mode
typedef basic_fstream<char> fstream;
// typedef basic_fstream<wchar_t> wfstream; // Why do you want to use this? It isn't portable, and you should be using UTF-8!
} // namespace filesystem
} // namespace k3d
#endif // !K3DSDK_FSTREAM_H