root / CCV-HAND / libs / poco / include / Poco / FileStream.h @ 59
View | Annotate | Download (6.3 KB)
| 1 | //
|
|---|---|
| 2 | // FileStream.h
|
| 3 | //
|
| 4 | // $Id: //poco/1.3/Foundation/include/Poco/FileStream.h#1 $
|
| 5 | //
|
| 6 | // Library: Foundation
|
| 7 | // Package: Streams
|
| 8 | // Module: FileStream
|
| 9 | //
|
| 10 | // Definition of the FileStreamBuf, FileInputStream and FileOutputStream classes.
|
| 11 | //
|
| 12 | // Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
| 13 | // and Contributors.
|
| 14 | //
|
| 15 | // Permission is hereby granted, free of charge, to any person or organization
|
| 16 | // obtaining a copy of the software and accompanying documentation covered by
|
| 17 | // this license (the "Software") to use, reproduce, display, distribute,
|
| 18 | // execute, and transmit the Software, and to prepare derivative works of the
|
| 19 | // Software, and to permit third-parties to whom the Software is furnished to
|
| 20 | // do so, all subject to the following:
|
| 21 | //
|
| 22 | // The copyright notices in the Software and this entire statement, including
|
| 23 | // the above license grant, this restriction and the following disclaimer,
|
| 24 | // must be included in all copies of the Software, in whole or in part, and
|
| 25 | // all derivative works of the Software, unless such copies or derivative
|
| 26 | // works are solely in the form of machine-executable object code generated by
|
| 27 | // a source language processor.
|
| 28 | //
|
| 29 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 30 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 31 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
| 32 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
| 33 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
| 34 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
| 35 | // DEALINGS IN THE SOFTWARE.
|
| 36 | //
|
| 37 | |
| 38 | |
| 39 | #ifndef Foundation_FileStream_INCLUDED
|
| 40 | #define Foundation_FileStream_INCLUDED
|
| 41 | |
| 42 | |
| 43 | #include "Poco/Foundation.h" |
| 44 | #if defined(POCO_OS_FAMILY_WINDOWS)
|
| 45 | #include "FileStream_WIN32.h" |
| 46 | #else
|
| 47 | #include "FileStream_POSIX.h" |
| 48 | #endif
|
| 49 | #include <istream> |
| 50 | #include <ostream> |
| 51 | |
| 52 | |
| 53 | namespace Poco {
|
| 54 | |
| 55 | |
| 56 | class Foundation_API FileIOS: public virtual std::ios
|
| 57 | /// The base class for FileInputStream and FileOutputStream.
|
| 58 | ///
|
| 59 | /// This class is needed to ensure the correct initialization
|
| 60 | /// order of the stream buffer and base classes.
|
| 61 | ///
|
| 62 | /// Files are always opened in binary mode, a text mode
|
| 63 | /// with CR-LF translation is not supported. Thus, the
|
| 64 | /// file is always opened as if the std::ios::binary flag
|
| 65 | /// was specified.
|
| 66 | /// Use an InputLineEndingConverter or OutputLineEndingConverter
|
| 67 | /// if you require CR-LF translation.
|
| 68 | ///
|
| 69 | /// On Windows platforms, if POCO_WIN32_UTF8 is #define'd,
|
| 70 | /// UTF-8 encoded Unicode paths are correctly handled.
|
| 71 | {
|
| 72 | public:
|
| 73 | FileIOS(std::ios::openmode defaultMode); |
| 74 | /// Creates the basic stream.
|
| 75 | |
| 76 | ~FileIOS(); |
| 77 | /// Destroys the stream.
|
| 78 | |
| 79 | void open(const std::string& path, std::ios::openmode mode); |
| 80 | /// Opens the file specified by path, using the given mode.
|
| 81 | ///
|
| 82 | /// Throws a FileException (or a similar exception) if the file
|
| 83 | /// does not exist or is not accessible for other reasons and
|
| 84 | /// a new file cannot be created.
|
| 85 | |
| 86 | void close();
|
| 87 | /// Closes the file stream.
|
| 88 | |
| 89 | FileStreamBuf* rdbuf(); |
| 90 | /// Returns a pointer to the underlying streambuf.
|
| 91 | |
| 92 | protected:
|
| 93 | FileStreamBuf _buf; |
| 94 | std::ios::openmode _defaultMode; |
| 95 | }; |
| 96 | |
| 97 | |
| 98 | class Foundation_API FileInputStream: public FileIOS, public std::istream
|
| 99 | /// An input stream for reading from a file.
|
| 100 | ///
|
| 101 | /// Files are always opened in binary mode, a text mode
|
| 102 | /// with CR-LF translation is not supported. Thus, the
|
| 103 | /// file is always opened as if the std::ios::binary flag
|
| 104 | /// was specified.
|
| 105 | /// Use an InputLineEndingConverter if you require CR-LF translation.
|
| 106 | ///
|
| 107 | /// On Windows platforms, if POCO_WIN32_UTF8 is #define'd,
|
| 108 | /// UTF-8 encoded Unicode paths are correctly handled.
|
| 109 | {
|
| 110 | public:
|
| 111 | FileInputStream(); |
| 112 | /// Creates an unopened FileInputStream.
|
| 113 | |
| 114 | FileInputStream(const std::string& path, std::ios::openmode mode = std::ios::in);
|
| 115 | /// Creates the FileInputStream for the file given by path, using
|
| 116 | /// the given mode.
|
| 117 | ///
|
| 118 | /// The std::ios::in flag is always set, regardless of the actual
|
| 119 | /// value specified for mode.
|
| 120 | ///
|
| 121 | /// Throws a FileNotFoundException (or a similar exception) if the file
|
| 122 | /// does not exist or is not accessible for other reasons.
|
| 123 | |
| 124 | ~FileInputStream(); |
| 125 | /// Destroys the stream.
|
| 126 | }; |
| 127 | |
| 128 | |
| 129 | class Foundation_API FileOutputStream: public FileIOS, public std::ostream
|
| 130 | /// An output stream for writing to a file.
|
| 131 | ///
|
| 132 | /// Files are always opened in binary mode, a text mode
|
| 133 | /// with CR-LF translation is not supported. Thus, the
|
| 134 | /// file is always opened as if the std::ios::binary flag
|
| 135 | /// was specified.
|
| 136 | /// Use an OutputLineEndingConverter if you require CR-LF translation.
|
| 137 | ///
|
| 138 | /// On Windows platforms, if POCO_WIN32_UTF8 is #define'd,
|
| 139 | /// UTF-8 encoded Unicode paths are correctly handled.
|
| 140 | {
|
| 141 | public:
|
| 142 | FileOutputStream(); |
| 143 | /// Creats an unopened FileOutputStream.
|
| 144 | |
| 145 | FileOutputStream(const std::string& path, std::ios::openmode mode = std::ios::out | std::ios::trunc);
|
| 146 | /// Creates the FileOutputStream for the file given by path, using
|
| 147 | /// the given mode.
|
| 148 | ///
|
| 149 | /// The std::ios::out is always set, regardless of the actual
|
| 150 | /// value specified for mode.
|
| 151 | ///
|
| 152 | /// Throws a FileException (or a similar exception) if the file
|
| 153 | /// does not exist or is not accessible for other reasons and
|
| 154 | /// a new file cannot be created.
|
| 155 | |
| 156 | ~FileOutputStream(); |
| 157 | /// Destroys the FileOutputStream.
|
| 158 | }; |
| 159 | |
| 160 | |
| 161 | class Foundation_API FileStream: public FileIOS, public std::iostream
|
| 162 | /// A stream for reading from and writing to a file.
|
| 163 | ///
|
| 164 | /// Files are always opened in binary mode, a text mode
|
| 165 | /// with CR-LF translation is not supported. Thus, the
|
| 166 | /// file is always opened as if the std::ios::binary flag
|
| 167 | /// was specified.
|
| 168 | /// Use an InputLineEndingConverter or OutputLineEndingConverter
|
| 169 | /// if you require CR-LF translation.
|
| 170 | ///
|
| 171 | /// A seek (seekg() or seekp()) operation will always set the
|
| 172 | /// read position and the write position simultaneously to the
|
| 173 | /// same value.
|
| 174 | ///
|
| 175 | /// On Windows platforms, if POCO_WIN32_UTF8 is #define'd,
|
| 176 | /// UTF-8 encoded Unicode paths are correctly handled.
|
| 177 | {
|
| 178 | public:
|
| 179 | FileStream(); |
| 180 | /// Creats an unopened FileStream.
|
| 181 | |
| 182 | FileStream(const std::string& path, std::ios::openmode mode = std::ios::out | std::ios::in);
|
| 183 | /// Creates the FileStream for the file given by path, using
|
| 184 | /// the given mode.
|
| 185 | |
| 186 | ~FileStream(); |
| 187 | /// Destroys the FileOutputStream.
|
| 188 | }; |
| 189 | |
| 190 | |
| 191 | } // namespace Poco
|
| 192 | |
| 193 | |
| 194 | #endif // Foundation_FileStream_INCLUDED |
