source: nrEngine/include/FileStream.h @ 30

Revision 30, 4.7 KB checked in by art, 12 years ago (diff)

::std wurde durch std ueberall ersetzt!

Line 
1/***************************************************************************
2 *                                                                         *
3 *   (c) Art Tevs, MPI Informatik Saarbruecken                             *
4 *       mailto: <tevs@mpi-sb.mpg.de>                                      *
5 *                                                                         *
6 *   This program is free software; you can redistribute it and/or modify  *
7 *   it under the terms of the GNU General Public License as published by  *
8 *   the Free Software Foundation; either version 2 of the License, or     *
9 *   (at your option) any later version.                                   *
10 *                                                                         *
11 ***************************************************************************/
12
13
14#ifndef _NR_FILE_STREAM_H_
15#define _NR_FILE_STREAM_H_
16
17
18//----------------------------------------------------------------------------------
19// Includes
20//----------------------------------------------------------------------------------
21#include "Prerequisities.h"
22#include "IStream.h"
23#include "Resource.h"
24
25namespace nrEngine{
26
27        //! Derived class from IStream to provide streaming from files
28        /**
29        * FileStream is derived class from IStream and IResource. It provides
30        * the functionality of streaming the files from the disk. We use the
31        * std::ifstream class to do this work.
32        *
33        * This class is a simple file class which provide the user only
34        * with nessary methods. You should use plugins to extend the functionality
35        * for working with compressed, encrypted etc. file archives.
36        *
37        * Because each file is also a resource, so you can open the files through
38        * the resource manager. This will call the appropriate resource loader
39        * (in our case file loader) to provide you with the file you requested.
40        * The type of such a resource is "File"
41        * Plugins can add new types like "ZipFile", "ZipArchive", ...
42        *
43        * \ingroup vfs
44        **/
45        class _NRExport FileStream : public IStream, public IResource {
46        public:
47
48                /**
49                * Constructor of the file stream. The loader should
50                * specify all neccessary properties of this object to allow
51                * opening of the file.
52                **/
53                FileStream();
54
55                /**
56                * Virtual destructor allows to derive new classes from this interface
57                **/
58                virtual ~FileStream();
59
60
61                /**
62                 * Open a file as a stream without using of underlying resource system.
63                 **/
64                virtual Result open (const std::string& fileName);
65
66                //------------------------------------------------------------
67                //              IStream Interface
68                //------------------------------------------------------------
69
70                /**
71                * Return the name of the stream. The name of the stream is the same
72                * as the name of the underlying resource used for the file storing.
73                **/
74                const std::string& getName()    const { return getResName(); }
75
76                /**
77                * @copydoc IStream::read()
78                **/
79                virtual size_t read(void *buf, size_t size, size_t nmemb);
80
81                /**
82                * @copydoc IStream::readDelim()
83                **/
84                virtual size_t readDelim(void* buf, size_t count, const std::string& delim = std::string("\n"));
85
86                /**
87                * @copydoc IStream::tell()
88                **/
89                virtual size_t tell() const;
90
91                /**
92                * @copydoc IStream::eof()
93                **/
94                virtual bool eof() const;
95
96                /**
97                * @copydoc IStream::getData()
98                **/
99                virtual byte* getData(size_t& count) const;
100
101                /**
102                * @copydoc IStream::seek()
103                **/
104                virtual bool seek(int32 offset, int32 whence = IStream::CURRENT);
105
106                /**
107                *  @copydoc IStream::close()
108                **/
109                virtual void close ();
110
111        private:
112
113                //! The file stream loader should be able to change the data of this object
114                friend class FileStreamLoader;
115
116                //! Stream used to read the file
117                SharedPtr< std::ifstream > mStream;
118
119                Result unloadRes();
120        };
121
122
123        //! Empty file stream to represent empty files
124        /**
125         * This is  file stream which loads an empty file. You will
126         * need this to get ResourceManagment working corectly. Any
127         * access to a resource instantiated from this class have
128         * no effect.
129         *
130         * \ingroup vfs
131         **/
132        class _NRExport EmptyFileStream : public FileStream {
133
134        public:
135                //! Initialize the empty file
136                EmptyFileStream();
137
138                //! Deinitilize the empty file object
139                ~EmptyFileStream();
140
141                //! Read data from the empty file returns nothing
142                size_t read(void *buf, size_t size, size_t nmemb);
143
144                //! Read until we fund a delimeter
145                size_t readDelim(void* buf, size_t count, const std::string& delim = "\n");
146
147                //! What is the position of the empty file reading cursor
148                size_t tell() const;
149
150                //! Are we on the end of file. For empty files it is always true
151                bool eof() const;
152
153                //! Returns no data from the empty file
154                byte* getData(size_t& count) const;
155
156                //! Seek or not to seek? That is the question!
157                bool seek(int32 offset, int32 whence = IStream::CURRENT);
158
159                //! Close the empty file
160                void close ();
161
162        };
163
164
165}; // end namespace
166
167#endif
Note: See TracBrowser for help on using the repository browser.