Line data Source code
1 : // boost/filesystem/fstream.hpp ------------------------------------------------------//
2 :
3 : // Copyright Beman Dawes 2002
4 :
5 : // Distributed under the Boost Software License, Version 1.0.
6 : // See http://www.boost.org/LICENSE_1_0.txt
7 :
8 : // Library home page: http://www.boost.org/libs/filesystem
9 :
10 : //--------------------------------------------------------------------------------------//
11 :
12 : #ifndef BOOST_FILESYSTEM3_FSTREAM_HPP
13 : #define BOOST_FILESYSTEM3_FSTREAM_HPP
14 :
15 : #include <boost/config.hpp>
16 :
17 : # if defined( BOOST_NO_STD_WSTRING )
18 : # error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
19 : # endif
20 :
21 : #include <boost/filesystem/path.hpp>
22 : #include <iosfwd>
23 : #include <fstream>
24 :
25 : #include <boost/config/abi_prefix.hpp> // must be the last #include
26 :
27 : // on Windows, except for standard libaries known to have wchar_t overloads for
28 : // file stream I/O, use path::string() to get a narrow character c_str()
29 : #if defined(BOOST_WINDOWS_API) \
30 : && (!defined(_CPPLIB_VER) || _CPPLIB_VER < 405 || defined(_STLPORT_VERSION))
31 : // !Dinkumware || early Dinkumware || STLPort masquerading as Dinkumware
32 : # define BOOST_FILESYSTEM_C_STR string().c_str() // use narrow, since wide not available
33 : #else // use the native c_str, which will be narrow on POSIX, wide on Windows
34 : # define BOOST_FILESYSTEM_C_STR c_str()
35 : #endif
36 :
37 : #if defined(BOOST_MSVC)
38 : #pragma warning(push)
39 : // 'boost::filesystem::basic_fstream<charT>' : inherits 'std::basic_istream<_Elem,_Traits>::std::basic_istream<_Elem,_Traits>::_Add_vtordisp1' via dominance
40 : #pragma warning(disable: 4250)
41 : #endif
42 :
43 : namespace boost
44 : {
45 : namespace filesystem
46 : {
47 :
48 : //--------------------------------------------------------------------------------------//
49 : // basic_filebuf //
50 : //--------------------------------------------------------------------------------------//
51 :
52 : template < class charT, class traits = std::char_traits<charT> >
53 : class basic_filebuf : public std::basic_filebuf<charT,traits>
54 : {
55 : private: // disallow copying
56 : basic_filebuf(const basic_filebuf&);
57 : const basic_filebuf& operator=(const basic_filebuf&);
58 :
59 : public:
60 : basic_filebuf() {}
61 : virtual ~basic_filebuf() {}
62 :
63 : basic_filebuf<charT,traits>*
64 : open(const path& p, std::ios_base::openmode mode)
65 : {
66 : return std::basic_filebuf<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, mode)
67 : ? this : 0;
68 : }
69 : };
70 :
71 : //--------------------------------------------------------------------------------------//
72 : // basic_ifstream //
73 : //--------------------------------------------------------------------------------------//
74 :
75 : template < class charT, class traits = std::char_traits<charT> >
76 : class basic_ifstream : public std::basic_ifstream<charT,traits>
77 : {
78 : private: // disallow copying
79 : basic_ifstream(const basic_ifstream&);
80 : const basic_ifstream& operator=(const basic_ifstream&);
81 :
82 : public:
83 : basic_ifstream() {}
84 :
85 : // use two signatures, rather than one signature with default second
86 : // argument, to workaround VC++ 7.1 bug (ID VSWhidbey 38416)
87 :
88 0 : explicit basic_ifstream(const path& p)
89 0 : : std::basic_ifstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, std::ios_base::in) {}
90 :
91 : basic_ifstream(const path& p, std::ios_base::openmode mode)
92 : : std::basic_ifstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, mode) {}
93 :
94 : void open(const path& p)
95 : { std::basic_ifstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, std::ios_base::in); }
96 :
97 : void open(const path& p, std::ios_base::openmode mode)
98 : { std::basic_ifstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, mode); }
99 :
100 0 : virtual ~basic_ifstream() {}
101 : };
102 :
103 : //--------------------------------------------------------------------------------------//
104 : // basic_ofstream //
105 : //--------------------------------------------------------------------------------------//
106 :
107 : template < class charT, class traits = std::char_traits<charT> >
108 : class basic_ofstream : public std::basic_ofstream<charT,traits>
109 : {
110 : private: // disallow copying
111 : basic_ofstream(const basic_ofstream&);
112 : const basic_ofstream& operator=(const basic_ofstream&);
113 :
114 : public:
115 : basic_ofstream() {}
116 :
117 : // use two signatures, rather than one signature with default second
118 : // argument, to workaround VC++ 7.1 bug (ID VSWhidbey 38416)
119 :
120 : explicit basic_ofstream(const path& p)
121 : : std::basic_ofstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, std::ios_base::out) {}
122 :
123 : basic_ofstream(const path& p, std::ios_base::openmode mode)
124 : : std::basic_ofstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, mode) {}
125 :
126 : void open(const path& p)
127 : { std::basic_ofstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, std::ios_base::out); }
128 :
129 : void open(const path& p, std::ios_base::openmode mode)
130 : { std::basic_ofstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, mode); }
131 :
132 : virtual ~basic_ofstream() {}
133 : };
134 :
135 : //--------------------------------------------------------------------------------------//
136 : // basic_fstream //
137 : //--------------------------------------------------------------------------------------//
138 :
139 : template < class charT, class traits = std::char_traits<charT> >
140 : class basic_fstream : public std::basic_fstream<charT,traits>
141 : {
142 : private: // disallow copying
143 : basic_fstream(const basic_fstream&);
144 : const basic_fstream & operator=(const basic_fstream&);
145 :
146 : public:
147 : basic_fstream() {}
148 :
149 : // use two signatures, rather than one signature with default second
150 : // argument, to workaround VC++ 7.1 bug (ID VSWhidbey 38416)
151 :
152 : explicit basic_fstream(const path& p)
153 : : std::basic_fstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR,
154 : std::ios_base::in | std::ios_base::out) {}
155 :
156 : basic_fstream(const path& p, std::ios_base::openmode mode)
157 : : std::basic_fstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, mode) {}
158 :
159 : void open(const path& p)
160 : { std::basic_fstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR,
161 : std::ios_base::in | std::ios_base::out); }
162 :
163 : void open(const path& p, std::ios_base::openmode mode)
164 : { std::basic_fstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, mode); }
165 :
166 : virtual ~basic_fstream() {}
167 :
168 : };
169 :
170 : //--------------------------------------------------------------------------------------//
171 : // typedefs //
172 : //--------------------------------------------------------------------------------------//
173 :
174 : typedef basic_filebuf<char> filebuf;
175 : typedef basic_ifstream<char> ifstream;
176 : typedef basic_ofstream<char> ofstream;
177 : typedef basic_fstream<char> fstream;
178 :
179 : typedef basic_filebuf<wchar_t> wfilebuf;
180 : typedef basic_ifstream<wchar_t> wifstream;
181 : typedef basic_ofstream<wchar_t> wofstream;
182 : typedef basic_fstream<wchar_t> wfstream;
183 :
184 : } // namespace filesystem
185 : } // namespace boost
186 :
187 : #if defined(BOOST_MSVC)
188 : #pragma warning(pop)
189 : #endif
190 :
191 : #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
192 : #endif // BOOST_FILESYSTEM3_FSTREAM_HPP
|