1 /*
2 BStone: A Source port of
3 Blake Stone: Aliens of Gold and Blake Stone: Planet Strike
4 
5 Copyright (c) 1992-2013 Apogee Entertainment, LLC
6 Copyright (c) 2013-2015 Boris I. Bendovsky (bibendovsky@hotmail.com)
7 
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the
20 Free Software Foundation, Inc.,
21 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 */
23 
24 
25 //
26 // File stream.
27 //
28 
29 
30 #ifndef BSTONE_FILE_STREAM_INCLUDED
31 #define BSTONE_FILE_STREAM_INCLUDED
32 
33 
34 #include "bstone_istream.h"
35 
36 
37 namespace bstone {
38 
39 
40 // File stream.
41 class FileStream :
42     public IStream
43 {
44 public:
45     FileStream();
46 
47     FileStream(
48         const std::string& file_name,
49         StreamOpenMode open_mode = StreamOpenMode::read);
50 
51     FileStream(
52         const FileStream& that) = delete;
53 
54     FileStream& operator=(
55         const FileStream& that) = delete;
56 
57     virtual ~FileStream();
58 
59     bool open(
60         const std::string& file_name,
61         StreamOpenMode open_mode = StreamOpenMode::read);
62 
63     virtual void close();
64 
65     virtual bool is_open() const;
66 
67     virtual int64_t get_size();
68 
69     virtual bool set_size(
70         int64_t size);
71 
72     virtual int64_t seek(
73         int64_t offset,
74         StreamSeekOrigin origin);
75 
76     virtual int read(
77         void* buffer,
78         int count);
79 
80     virtual bool write(
81         const void* buffer,
82         int count);
83 
84     virtual bool can_read() const;
85 
86     virtual bool can_seek() const;
87 
88     virtual bool can_write() const;
89 
90     static bool is_exists(
91         const std::string& file_name);
92 
93 
94 private:
95     void* context_;
96     bool can_read_;
97     bool can_seek_;
98     bool can_write_;
99 }; // FileStream
100 
101 
102 } // bstone
103 
104 
105 #endif // BSTONE_FILE_STREAM_INCLUDED
106