diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/irrXML.cpp | 360 |
1 files changed, 180 insertions, 180 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/irrXML.cpp b/libraries/irrlicht-1.8/source/Irrlicht/irrXML.cpp index 9197348..06f87d7 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/irrXML.cpp +++ b/libraries/irrlicht-1.8/source/Irrlicht/irrXML.cpp | |||
@@ -1,180 +1,180 @@ | |||
1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt | 1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt |
2 | // This file is part of the "Irrlicht Engine" and the "irrXML" project. | 2 | // This file is part of the "Irrlicht Engine" and the "irrXML" project. |
3 | // For conditions of distribution and use, see copyright notice in irrlicht.h and/or irrXML.h | 3 | // For conditions of distribution and use, see copyright notice in irrlicht.h and/or irrXML.h |
4 | 4 | ||
5 | #include "irrXML.h" | 5 | #include "irrXML.h" |
6 | #include "irrString.h" | 6 | #include "irrString.h" |
7 | #include "irrArray.h" | 7 | #include "irrArray.h" |
8 | #include "fast_atof.h" | 8 | #include "fast_atof.h" |
9 | #include "CXMLReaderImpl.h" | 9 | #include "CXMLReaderImpl.h" |
10 | 10 | ||
11 | namespace irr | 11 | namespace irr |
12 | { | 12 | { |
13 | namespace io | 13 | namespace io |
14 | { | 14 | { |
15 | 15 | ||
16 | //! Implementation of the file read callback for ordinary files | 16 | //! Implementation of the file read callback for ordinary files |
17 | class CFileReadCallBack : public IFileReadCallBack | 17 | class CFileReadCallBack : public IFileReadCallBack |
18 | { | 18 | { |
19 | public: | 19 | public: |
20 | 20 | ||
21 | //! construct from filename | 21 | //! construct from filename |
22 | CFileReadCallBack(const char* filename) | 22 | CFileReadCallBack(const char* filename) |
23 | : File(0), Size(-1), Close(true) | 23 | : File(0), Size(-1), Close(true) |
24 | { | 24 | { |
25 | // open file | 25 | // open file |
26 | File = fopen(filename, "rb"); | 26 | File = fopen(filename, "rb"); |
27 | 27 | ||
28 | if (File) | 28 | if (File) |
29 | getFileSize(); | 29 | getFileSize(); |
30 | } | 30 | } |
31 | 31 | ||
32 | //! construct from FILE pointer | 32 | //! construct from FILE pointer |
33 | CFileReadCallBack(FILE* file) | 33 | CFileReadCallBack(FILE* file) |
34 | : File(file), Size(-1), Close(false) | 34 | : File(file), Size(-1), Close(false) |
35 | { | 35 | { |
36 | if (File) | 36 | if (File) |
37 | getFileSize(); | 37 | getFileSize(); |
38 | } | 38 | } |
39 | 39 | ||
40 | //! destructor | 40 | //! destructor |
41 | virtual ~CFileReadCallBack() | 41 | virtual ~CFileReadCallBack() |
42 | { | 42 | { |
43 | if (Close && File) | 43 | if (Close && File) |
44 | fclose(File); | 44 | fclose(File); |
45 | } | 45 | } |
46 | 46 | ||
47 | //! Reads an amount of bytes from the file. | 47 | //! Reads an amount of bytes from the file. |
48 | virtual int read(void* buffer, int sizeToRead) | 48 | virtual int read(void* buffer, int sizeToRead) |
49 | { | 49 | { |
50 | if (!File) | 50 | if (!File) |
51 | return 0; | 51 | return 0; |
52 | 52 | ||
53 | return (int)fread(buffer, 1, sizeToRead, File); | 53 | return (int)fread(buffer, 1, sizeToRead, File); |
54 | } | 54 | } |
55 | 55 | ||
56 | //! Returns size of file in bytes | 56 | //! Returns size of file in bytes |
57 | virtual long getSize() const | 57 | virtual long getSize() const |
58 | { | 58 | { |
59 | return Size; | 59 | return Size; |
60 | } | 60 | } |
61 | 61 | ||
62 | private: | 62 | private: |
63 | 63 | ||
64 | //! retrieves the file size of the open file | 64 | //! retrieves the file size of the open file |
65 | void getFileSize() | 65 | void getFileSize() |
66 | { | 66 | { |
67 | fseek(File, 0, SEEK_END); | 67 | fseek(File, 0, SEEK_END); |
68 | Size = ftell(File); | 68 | Size = ftell(File); |
69 | fseek(File, 0, SEEK_SET); | 69 | fseek(File, 0, SEEK_SET); |
70 | } | 70 | } |
71 | 71 | ||
72 | FILE* File; | 72 | FILE* File; |
73 | long Size; | 73 | long Size; |
74 | bool Close; | 74 | bool Close; |
75 | 75 | ||
76 | }; // end class CFileReadCallBack | 76 | }; // end class CFileReadCallBack |
77 | 77 | ||
78 | 78 | ||
79 | 79 | ||
80 | // FACTORY FUNCTIONS: | 80 | // FACTORY FUNCTIONS: |
81 | 81 | ||
82 | 82 | ||
83 | //! Creates an instance of an UFT-8 or ASCII character xml parser. | 83 | //! Creates an instance of an UFT-8 or ASCII character xml parser. |
84 | IRRLICHT_API IrrXMLReader* IRRCALLCONV createIrrXMLReader(const char* filename) | 84 | IRRLICHT_API IrrXMLReader* IRRCALLCONV createIrrXMLReader(const char* filename) |
85 | { | 85 | { |
86 | return createIrrXMLReader(new CFileReadCallBack(filename), true); | 86 | return createIrrXMLReader(new CFileReadCallBack(filename), true); |
87 | } | 87 | } |
88 | 88 | ||
89 | 89 | ||
90 | //! Creates an instance of an UFT-8 or ASCII character xml parser. | 90 | //! Creates an instance of an UFT-8 or ASCII character xml parser. |
91 | IRRLICHT_API IrrXMLReader* IRRCALLCONV createIrrXMLReader(FILE* file) | 91 | IRRLICHT_API IrrXMLReader* IRRCALLCONV createIrrXMLReader(FILE* file) |
92 | { | 92 | { |
93 | return createIrrXMLReader(new CFileReadCallBack(file), true); | 93 | return createIrrXMLReader(new CFileReadCallBack(file), true); |
94 | } | 94 | } |
95 | 95 | ||
96 | 96 | ||
97 | //! Creates an instance of an UFT-8 or ASCII character xml parser. | 97 | //! Creates an instance of an UFT-8 or ASCII character xml parser. |
98 | IRRLICHT_API IrrXMLReader* IRRCALLCONV createIrrXMLReader(IFileReadCallBack* callback, | 98 | IRRLICHT_API IrrXMLReader* IRRCALLCONV createIrrXMLReader(IFileReadCallBack* callback, |
99 | bool deleteCallback) | 99 | bool deleteCallback) |
100 | { | 100 | { |
101 | if (callback && (callback->getSize() >= 0)) | 101 | if (callback && (callback->getSize() >= 0)) |
102 | { | 102 | { |
103 | return new CXMLReaderImpl<char, IXMLBase>(callback, deleteCallback); | 103 | return new CXMLReaderImpl<char, IXMLBase>(callback, deleteCallback); |
104 | } | 104 | } |
105 | else | 105 | else |
106 | { | 106 | { |
107 | if(callback && deleteCallback) | 107 | if(callback && deleteCallback) |
108 | delete callback; | 108 | delete callback; |
109 | 109 | ||
110 | return 0; | 110 | return 0; |
111 | } | 111 | } |
112 | } | 112 | } |
113 | 113 | ||
114 | 114 | ||
115 | //! Creates an instance of an UTF-16 xml parser. | 115 | //! Creates an instance of an UTF-16 xml parser. |
116 | IRRLICHT_API IrrXMLReaderUTF16* IRRCALLCONV createIrrXMLReaderUTF16(const char* filename) | 116 | IRRLICHT_API IrrXMLReaderUTF16* IRRCALLCONV createIrrXMLReaderUTF16(const char* filename) |
117 | { | 117 | { |
118 | return createIrrXMLReaderUTF16(new CFileReadCallBack(filename), true); | 118 | return createIrrXMLReaderUTF16(new CFileReadCallBack(filename), true); |
119 | } | 119 | } |
120 | 120 | ||
121 | 121 | ||
122 | //! Creates an instance of an UTF-16 xml parser. | 122 | //! Creates an instance of an UTF-16 xml parser. |
123 | IRRLICHT_API IrrXMLReaderUTF16* IRRCALLCONV createIrrXMLReaderUTF16(FILE* file) | 123 | IRRLICHT_API IrrXMLReaderUTF16* IRRCALLCONV createIrrXMLReaderUTF16(FILE* file) |
124 | { | 124 | { |
125 | return createIrrXMLReaderUTF16(new CFileReadCallBack(file), true); | 125 | return createIrrXMLReaderUTF16(new CFileReadCallBack(file), true); |
126 | } | 126 | } |
127 | 127 | ||
128 | 128 | ||
129 | //! Creates an instance of an UTF-16 xml parser. | 129 | //! Creates an instance of an UTF-16 xml parser. |
130 | IRRLICHT_API IrrXMLReaderUTF16* IRRCALLCONV createIrrXMLReaderUTF16(IFileReadCallBack* callback, | 130 | IRRLICHT_API IrrXMLReaderUTF16* IRRCALLCONV createIrrXMLReaderUTF16(IFileReadCallBack* callback, |
131 | bool deleteCallback) | 131 | bool deleteCallback) |
132 | { | 132 | { |
133 | if (callback && (callback->getSize() >= 0)) | 133 | if (callback && (callback->getSize() >= 0)) |
134 | { | 134 | { |
135 | return new CXMLReaderImpl<char16, IXMLBase>(callback, deleteCallback); | 135 | return new CXMLReaderImpl<char16, IXMLBase>(callback, deleteCallback); |
136 | } | 136 | } |
137 | else | 137 | else |
138 | { | 138 | { |
139 | if(callback && deleteCallback) | 139 | if(callback && deleteCallback) |
140 | delete callback; | 140 | delete callback; |
141 | 141 | ||
142 | return 0; | 142 | return 0; |
143 | } | 143 | } |
144 | } | 144 | } |
145 | 145 | ||
146 | 146 | ||
147 | //! Creates an instance of an UTF-32 xml parser. | 147 | //! Creates an instance of an UTF-32 xml parser. |
148 | IRRLICHT_API IrrXMLReaderUTF32* IRRCALLCONV createIrrXMLReaderUTF32(const char* filename) | 148 | IRRLICHT_API IrrXMLReaderUTF32* IRRCALLCONV createIrrXMLReaderUTF32(const char* filename) |
149 | { | 149 | { |
150 | return createIrrXMLReaderUTF32(new CFileReadCallBack(filename), true); | 150 | return createIrrXMLReaderUTF32(new CFileReadCallBack(filename), true); |
151 | } | 151 | } |
152 | 152 | ||
153 | 153 | ||
154 | //! Creates an instance of an UTF-32 xml parser. | 154 | //! Creates an instance of an UTF-32 xml parser. |
155 | IRRLICHT_API IrrXMLReaderUTF32* IRRCALLCONV createIrrXMLReaderUTF32(FILE* file) | 155 | IRRLICHT_API IrrXMLReaderUTF32* IRRCALLCONV createIrrXMLReaderUTF32(FILE* file) |
156 | { | 156 | { |
157 | return createIrrXMLReaderUTF32(new CFileReadCallBack(file), true); | 157 | return createIrrXMLReaderUTF32(new CFileReadCallBack(file), true); |
158 | } | 158 | } |
159 | 159 | ||
160 | 160 | ||
161 | //! Creates an instance of an UTF-32 xml parser. | 161 | //! Creates an instance of an UTF-32 xml parser. |
162 | IRRLICHT_API IrrXMLReaderUTF32* IRRCALLCONV createIrrXMLReaderUTF32( | 162 | IRRLICHT_API IrrXMLReaderUTF32* IRRCALLCONV createIrrXMLReaderUTF32( |
163 | IFileReadCallBack* callback, bool deleteCallback) | 163 | IFileReadCallBack* callback, bool deleteCallback) |
164 | { | 164 | { |
165 | if (callback && (callback->getSize() >= 0)) | 165 | if (callback && (callback->getSize() >= 0)) |
166 | { | 166 | { |
167 | return new CXMLReaderImpl<char32, IXMLBase>(callback, deleteCallback); | 167 | return new CXMLReaderImpl<char32, IXMLBase>(callback, deleteCallback); |
168 | } | 168 | } |
169 | else | 169 | else |
170 | { | 170 | { |
171 | if(callback && deleteCallback) | 171 | if(callback && deleteCallback) |
172 | delete callback; | 172 | delete callback; |
173 | 173 | ||
174 | return 0; | 174 | return 0; |
175 | } | 175 | } |
176 | } | 176 | } |
177 | 177 | ||
178 | 178 | ||
179 | } // end namespace io | 179 | } // end namespace io |
180 | } // end namespace irr | 180 | } // end namespace irr |