3 Copyright (c) 2003, Arvid Norberg
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
10 * Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in
14 the documentation and/or other materials provided with the distribution.
15 * Neither the name of the author nor the names of its
16 contributors may be used to endorse or promote products derived
17 from this software without specific prior written permission.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 POSSIBILITY OF SUCH DAMAGE.
33 #ifndef TORRENT_FILE_HPP_INCLUDED
34 #define TORRENT_FILE_HPP_INCLUDED
41 #pragma warning(push, 1)
44 #include <boost/noncopyable.hpp>
45 #include <boost/filesystem/path.hpp>
51 #include "libtorrent/error_code.hpp"
52 #include "libtorrent/size_type.hpp"
53 #include "libtorrent/config.hpp"
57 namespace fs
= boost::filesystem
;
59 class TORRENT_EXPORT file
: public boost::noncopyable
67 seek_mode(int v
): m_val(v
) {}
71 static const seek_mode begin
;
72 static const seek_mode end
;
79 open_mode(): m_mask(0) {}
80 open_mode
operator|(open_mode m
) const
81 { return open_mode(m
.m_mask
| m_mask
); }
83 open_mode
operator&(open_mode m
) const
84 { return open_mode(m
.m_mask
& m_mask
); }
86 open_mode
operator|=(open_mode m
)
92 bool operator==(open_mode m
) const { return m_mask
== m
.m_mask
; }
93 bool operator!=(open_mode m
) const { return m_mask
!= m
.m_mask
; }
94 operator bool() const { return m_mask
!= 0; }
98 open_mode(int val
): m_mask(val
) {}
102 static const open_mode in
;
103 static const open_mode out
;
106 file(fs::path
const& p
, open_mode m
, error_code
& ec
);
109 bool open(fs::path
const& p
, open_mode m
, error_code
& ec
);
110 bool is_open() const;
112 bool set_size(size_type size
, error_code
& ec
);
114 size_type
write(const char*, size_type num_bytes
, error_code
& ec
);
115 size_type
read(char*, size_type num_bytes
, error_code
& ec
);
117 size_type
seek(size_type pos
, seek_mode m
, error_code
& ec
);
118 size_type
tell(error_code
& ec
);
122 #ifdef TORRENT_WINDOWS
123 HANDLE m_file_handle
;
128 open_mode m_open_mode
;
135 #endif // TORRENT_FILE_HPP_INCLUDED