]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/file.h
transfer from internal tree r5311 branches/1.4-gpl
[xonotic/netradiant.git] / radiant / file.h
1 /*\r
2 Copyright (c) 2001, Loki software, inc.\r
3 All rights reserved.\r
4 \r
5 Redistribution and use in source and binary forms, with or without modification, \r
6 are permitted provided that the following conditions are met:\r
7 \r
8 Redistributions of source code must retain the above copyright notice, this list \r
9 of conditions and the following disclaimer.\r
10 \r
11 Redistributions in binary form must reproduce the above copyright notice, this\r
12 list of conditions and the following disclaimer in the documentation and/or\r
13 other materials provided with the distribution.\r
14 \r
15 Neither the name of Loki software nor the names of its contributors may be used \r
16 to endorse or promote products derived from this software without specific prior \r
17 written permission. \r
18 \r
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' \r
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE \r
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE \r
22 DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY \r
23 DIRECT,INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES \r
24 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; \r
25 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
26 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS \r
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \r
29 */\r
30 \r
31 //\r
32 //      file.h\r
33 ////////////////////////////////////////////////////\r
34 \r
35 #ifndef _FILE_H_\r
36 #define _FILE_H_\r
37 \r
38 //#include <stdio.h>\r
39 \r
40 class MemStream : public IDataStream\r
41 {\r
42 public:\r
43         MemStream();\r
44         MemStream(unsigned long nLen);\r
45         virtual ~MemStream();\r
46 \r
47         int refCount;\r
48         void IncRef() { refCount++; }\r
49         void DecRef() { refCount--; if (refCount <= 0) delete this; }\r
50 \r
51 protected:\r
52         // MemFile specific:\r
53         unsigned long m_nGrowBytes;\r
54         unsigned long m_nPosition;\r
55         unsigned long m_nBufferSize;\r
56         unsigned long m_nFileSize;\r
57         unsigned char* m_pBuffer;\r
58         bool m_bAutoDelete;\r
59         void GrowFile(unsigned long nNewLen);\r
60 \r
61 public:\r
62         unsigned long GetPosition() const;\r
63         unsigned long Seek(long lOff, int nFrom);\r
64         void SetLength(unsigned long nNewLen);\r
65         unsigned long GetLength() const;\r
66 \r
67         unsigned char* GetBuffer () const\r
68           { return m_pBuffer; }\r
69 \r
70         char* ReadString(char* pBuf, unsigned long nMax);\r
71         unsigned long Read(void* pBuf, unsigned long nCount);\r
72         unsigned long Write(const void* pBuf, unsigned long nCount);\r
73         int GetChar();\r
74         int PutChar(int c);\r
75   \r
76   void printf(const char*, ...); ///< \todo implement on MemStream\r
77 \r
78         void Abort();\r
79         void Flush();\r
80         void Close();\r
81         bool Open(const char *filename, const char *mode);\r
82 };\r
83 \r
84 class FileStream : public IDataStream\r
85 {\r
86 public:\r
87         FileStream();\r
88         virtual ~FileStream();\r
89 \r
90         int refCount;\r
91         void IncRef() { refCount++; }\r
92         void DecRef() { refCount--; if (refCount <= 0) delete this; }\r
93 \r
94 protected:\r
95         // DiscFile specific:\r
96         FILE* m_hFile;\r
97         bool m_bCloseOnDelete;\r
98 \r
99 public:\r
100         unsigned long GetPosition() const;\r
101         unsigned long Seek(long lOff, int nFrom);\r
102         void SetLength(unsigned long nNewLen);\r
103         unsigned long GetLength() const;\r
104 \r
105         char* ReadString(char* pBuf, unsigned long nMax);\r
106         unsigned long Read(void* pBuf, unsigned long nCount);\r
107         unsigned long Write(const void* pBuf, unsigned long nCount);\r
108         int GetChar();\r
109         int PutChar(int c);\r
110 \r
111   void printf(const char*, ...); ///< completely matches the usual printf behaviour\r
112 \r
113         void Abort();\r
114         void Flush();\r
115         void Close();\r
116         bool Open(const char *filename, const char *mode);\r
117 };\r
118 \r
119 #endif // _FILE_H_\r