source: NonGTP/Boost/boost/filesystem/fstream.hpp @ 857

Revision 857, 6.8 KB checked in by igarcia, 19 years ago (diff)
RevLine 
[857]1//  boost/filesystem/fstream.hpp  --------------------------------------------//
2
3//  Copyright Beman Dawes 2002.
4//  Use, modification, and distribution is subject to the Boost Software
5//  License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6//  http://www.boost.org/LICENSE_1_0.txt)
7
8//  See library home page at http://www.boost.org/libs/filesystem
9
10//----------------------------------------------------------------------------//
11
12#ifndef BOOST_FILESYSTEM_FSTREAM_HPP
13#define BOOST_FILESYSTEM_FSTREAM_HPP
14
15#include <boost/filesystem/path.hpp>  // includes <boost/filesystem/config.hpp>
16#include <boost/detail/workaround.hpp>
17
18#include <iosfwd>
19#include <fstream>
20
21#include <boost/config/abi_prefix.hpp> // must be the last header
22
23namespace boost
24{
25  namespace filesystem
26  {
27    template < class charT, class traits = std::char_traits<charT> >
28    class basic_filebuf : public std::basic_filebuf<charT,traits>
29    {
30    public:
31      virtual ~basic_filebuf() {}
32#if !BOOST_WORKAROUND( BOOST_MSVC, <= 1200 ) // VC++ 6.0 can't handle this
33      std::basic_filebuf<charT,traits> * open( const path & file_ph,
34        std::ios_base::openmode mode )
35      {
36        return std::basic_filebuf<charT,traits>::open(
37          file_ph.native_file_string().c_str(), mode );
38      }
39#endif
40    };
41
42    typedef basic_filebuf<char> filebuf;
43#   ifndef BOOST_NO_STD_WSTRING
44    typedef basic_filebuf<wchar_t> wfilebuf;
45#   endif
46
47    template < class charT, class traits = std::char_traits<charT> >
48    class basic_ifstream : public std::basic_ifstream<charT,traits>
49    {
50    public:
51      basic_ifstream() {}
52#if !BOOST_WORKAROUND( BOOST_MSVC, == 1310 )
53      explicit basic_ifstream( const path & file_ph,
54        std::ios_base::openmode mode = std::ios_base::in )
55        : std::basic_ifstream<charT,traits>(
56        file_ph.native_file_string().c_str(), mode ) {}
57#  if !BOOST_WORKAROUND( BOOST_MSVC, <= 1200 ) // VC++ 6.0 can't handle this
58      void open( const path & file_ph,
59        std::ios_base::openmode mode = std::ios_base::in )
60      {
61        std::basic_ifstream<charT,traits>::open(
62          file_ph.native_file_string().c_str(), mode );
63      }
64#  endif
65#else // workaround for VC++ 7.1 bug id VSWhidbey 38416
66      explicit basic_ifstream( const path & file_ph )
67        : std::basic_ifstream<charT,traits>(
68        file_ph.native_file_string().c_str(), std::ios_base::in ) {}
69      basic_ifstream( const path & file_ph,
70        std::ios_base::openmode mode )
71        : std::basic_ifstream<charT,traits>(
72        file_ph.native_file_string().c_str(), mode ) {}
73      void open( const path & file_ph )
74      {
75        std::basic_ifstream<charT,traits>::open(
76          file_ph.native_file_string().c_str(), std::ios_base::in );
77      }
78      void open( const path & file_ph,
79        std::ios_base::openmode mode )
80      {
81        std::basic_ifstream<charT,traits>::open(
82          file_ph.native_file_string().c_str(), mode );
83      }
84#endif
85      virtual ~basic_ifstream() {}
86    };
87
88    typedef basic_ifstream<char> ifstream;
89#   ifndef BOOST_NO_STD_WSTRING
90    typedef basic_ifstream<wchar_t> wifstream;
91#   endif
92
93    template < class charT, class traits = std::char_traits<charT> >
94    class basic_ofstream : public std::basic_ofstream<charT,traits>
95    {
96    public:
97      basic_ofstream() {}
98#if !BOOST_WORKAROUND( BOOST_MSVC, == 1310 )
99      explicit basic_ofstream( const path & file_ph,
100        std::ios_base::openmode mode = std::ios_base::out )
101        : std::basic_ofstream<charT,traits>(
102        file_ph.native_file_string().c_str(), mode ) {}
103#  if !BOOST_WORKAROUND( BOOST_MSVC, <= 1200 ) // VC++ 6.0 can't handle this
104      void open( const path & file_ph,
105        std::ios_base::openmode mode = std::ios_base::out )
106      {
107        std::basic_ofstream<charT,traits>::open(
108          file_ph.native_file_string().c_str(), mode );
109      }
110#  endif
111#else // workaround for VC++ 7.1 bug id VSWhidbey 38416
112      explicit basic_ofstream( const path & file_ph )
113        : std::basic_ofstream<charT,traits>(
114        file_ph.native_file_string().c_str(), std::ios_base::out ) {}
115      basic_ofstream( const path & file_ph,
116        std::ios_base::openmode mode )
117        : std::basic_ofstream<charT,traits>(
118        file_ph.native_file_string().c_str(), mode ) {}
119      void open( const path & file_ph )
120      {
121        std::basic_ofstream<charT,traits>::open(
122          file_ph.native_file_string().c_str(), std::ios_base::out );
123      }
124      void open( const path & file_ph,
125        std::ios_base::openmode mode )
126      {
127        std::basic_ofstream<charT,traits>::open(
128          file_ph.native_file_string().c_str(), mode );
129      }
130#endif
131      virtual ~basic_ofstream() {}
132    };
133
134    typedef basic_ofstream<char> ofstream;
135#   ifndef BOOST_NO_STD_WSTRING
136    typedef basic_ofstream<wchar_t> wofstream;
137#   endif
138
139    template < class charT, class traits = std::char_traits<charT> >
140    class basic_fstream : public std::basic_fstream<charT,traits>
141    {
142    public:
143      basic_fstream() {}
144#if !BOOST_WORKAROUND( BOOST_MSVC, == 1310 )
145      explicit basic_fstream( const path & file_ph,
146        std::ios_base::openmode mode = std::ios_base::in|std::ios_base::out )
147        : std::basic_fstream<charT,traits>(
148        file_ph.native_file_string().c_str(), mode ) {}
149#  if !BOOST_WORKAROUND( BOOST_MSVC, <= 1200 ) // VC++ 6.0 can't handle this
150      void open( const path & file_ph,
151        std::ios_base::openmode mode = std::ios_base::in|std::ios_base::out )
152      {
153        std::basic_fstream<charT,traits>::open(
154          file_ph.native_file_string().c_str(), mode );
155      }
156#  endif
157#else // workaround for VC++ 7.1 bug id VSWhidbey 38416
158      explicit basic_fstream( const path & file_ph )
159        : std::basic_fstream<charT,traits>(
160        file_ph.native_file_string().c_str(),
161        std::ios_base::in|std::ios_base::out ) {}
162      basic_fstream( const path & file_ph,
163        std::ios_base::openmode mode )
164        : std::basic_fstream<charT,traits>(
165        file_ph.native_file_string().c_str(), mode ) {}
166      void open( const path & file_ph )
167      {
168        std::basic_fstream<charT,traits>::open(
169          file_ph.native_file_string().c_str(),
170          std::ios_base::in|std::ios_base::out );
171      }
172      void open( const path & file_ph,
173        std::ios_base::openmode mode )
174      {
175        std::basic_fstream<charT,traits>::open(
176          file_ph.native_file_string().c_str(), mode );
177      }
178#endif
179      virtual ~basic_fstream() {}
180    };
181 
182    typedef basic_fstream<char> fstream;
183#   ifndef BOOST_NO_STD_WSTRING
184    typedef basic_fstream<wchar_t> wfstream;
185#   endif
186  } // namespace filesystem
187
188} // namespace boost
189
190#include <boost/config/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
191#endif  // BOOST_FILESYSTEM_FSTREAM_HPP
Note: See TracBrowser for help on using the repository browser.