filedevice.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2007 Laurentiu-Gheorghe Crisan
3  * Copyright (C) 2006-2007 Marc Boris Duerner
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * As a special exception, you may use this file as part of a free
11  * software library without restriction. Specifically, if other files
12  * instantiate templates or use macros or inline functions from this
13  * file, or you compile this file and link it with other files to
14  * produce an executable, this file does not by itself cause the
15  * resulting executable to be covered by the GNU General Public
16  * License. This exception does not however invalidate any other
17  * reasons why the executable file might be covered by the GNU Library
18  * General Public License.
19  *
20  * This library is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23  * Lesser General Public License for more details.
24  *
25  * You should have received a copy of the GNU Lesser General Public
26  * License along with this library; if not, write to the Free Software
27  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28  */
29 #ifndef cxxtools_System_FileDevice_h
30 #define cxxtools_System_FileDevice_h
31 
32 #include <cxxtools/iodevice.h>
33 #include <cxxtools/api.h>
34 
35 namespace cxxtools
36 {
37 
39 {
40  friend class FileDeviceImpl;
41 
42  private:
43  class FileDeviceImpl* _impl;
44 
45  public:
46  FileDevice();
47 
48  FileDevice( const std::string& path, IODevice::OpenMode mode, bool inherit = true);
49 
50  ~FileDevice();
51 
52  void open( const std::string& path, IODevice::OpenMode mode, bool inherit = true);
53 
54  const char* path() const
55  { return _path.c_str(); }
56 
57  size_t size() const;
58 
59  protected:
60  size_t onBeginRead(char* buffer, size_t n, bool& eof);
61 
62  size_t onEndRead(bool& eof);
63 
64  size_t onBeginWrite(const char* buffer, size_t n);
65 
66  size_t onEndWrite();
67 
68  void onClose();
69 
70  void onSetTimeout(size_t timeout);
71 
72  bool onSeekable() const
73  { return true; }
74 
75  pos_type onSeek(off_type offset, std::ios::seekdir sd);
76 
77  size_t onRead(char* buffer, size_t count, bool& eof);
78 
79  size_t onWrite(const char* buffer, size_t count);
80 
81  void onCancel();
82 
83  size_t onPeek(char* buffer, size_t count);
84 
85  void onSync() const;
86 
87  private:
88  std::string _path;
89 };
90 
91 } // namespace cxxtools
92 
93 #endif