rev |
line source |
nuclear@0
|
1 // Copyright (C) 2002-2005 Nikolaus Gebhardt
|
nuclear@0
|
2 // This file is part of the "Irrlicht Engine" and the "irrXML" project.
|
nuclear@0
|
3 // For conditions of distribution and use, see copyright notice in irrlicht.h and/or irrXML.h
|
nuclear@0
|
4
|
nuclear@0
|
5 // Need to include Assimp, too. We're using Assimp's version of fast_atof
|
nuclear@0
|
6 // so we need stdint.h. But no PCH.
|
nuclear@0
|
7
|
nuclear@0
|
8 #include "AssimpPCH.h"
|
nuclear@0
|
9
|
nuclear@0
|
10 #include "irrXML.h"
|
nuclear@0
|
11 #include "irrString.h"
|
nuclear@0
|
12 #include "irrArray.h"
|
nuclear@0
|
13 #include "fast_atof.h"
|
nuclear@0
|
14 #include "CXMLReaderImpl.h"
|
nuclear@0
|
15
|
nuclear@0
|
16 namespace irr
|
nuclear@0
|
17 {
|
nuclear@0
|
18 namespace io
|
nuclear@0
|
19 {
|
nuclear@0
|
20
|
nuclear@0
|
21 //! Implementation of the file read callback for ordinary files
|
nuclear@0
|
22 class CFileReadCallBack : public IFileReadCallBack
|
nuclear@0
|
23 {
|
nuclear@0
|
24 public:
|
nuclear@0
|
25
|
nuclear@0
|
26 //! construct from filename
|
nuclear@0
|
27 CFileReadCallBack(const char* filename)
|
nuclear@0
|
28 : File(0), Size(0), Close(true)
|
nuclear@0
|
29 {
|
nuclear@0
|
30 // open file
|
nuclear@0
|
31 File = fopen(filename, "rb");
|
nuclear@0
|
32
|
nuclear@0
|
33 if (File)
|
nuclear@0
|
34 getFileSize();
|
nuclear@0
|
35 }
|
nuclear@0
|
36
|
nuclear@0
|
37 //! construct from FILE pointer
|
nuclear@0
|
38 CFileReadCallBack(FILE* file)
|
nuclear@0
|
39 : File(file), Size(0), Close(false)
|
nuclear@0
|
40 {
|
nuclear@0
|
41 if (File)
|
nuclear@0
|
42 getFileSize();
|
nuclear@0
|
43 }
|
nuclear@0
|
44
|
nuclear@0
|
45 //! destructor
|
nuclear@0
|
46 virtual ~CFileReadCallBack()
|
nuclear@0
|
47 {
|
nuclear@0
|
48 if (Close && File)
|
nuclear@0
|
49 fclose(File);
|
nuclear@0
|
50 }
|
nuclear@0
|
51
|
nuclear@0
|
52 //! Reads an amount of bytes from the file.
|
nuclear@0
|
53 virtual int read(void* buffer, int sizeToRead)
|
nuclear@0
|
54 {
|
nuclear@0
|
55 if (!File)
|
nuclear@0
|
56 return 0;
|
nuclear@0
|
57
|
nuclear@0
|
58 return (int)fread(buffer, 1, sizeToRead, File);
|
nuclear@0
|
59 }
|
nuclear@0
|
60
|
nuclear@0
|
61 //! Returns size of file in bytes
|
nuclear@0
|
62 virtual int getSize()
|
nuclear@0
|
63 {
|
nuclear@0
|
64 return Size;
|
nuclear@0
|
65 }
|
nuclear@0
|
66
|
nuclear@0
|
67 private:
|
nuclear@0
|
68
|
nuclear@0
|
69 //! retrieves the file size of the open file
|
nuclear@0
|
70 void getFileSize()
|
nuclear@0
|
71 {
|
nuclear@0
|
72 fseek(File, 0, SEEK_END);
|
nuclear@0
|
73 Size = ftell(File);
|
nuclear@0
|
74 fseek(File, 0, SEEK_SET);
|
nuclear@0
|
75 }
|
nuclear@0
|
76
|
nuclear@0
|
77 FILE* File;
|
nuclear@0
|
78 int Size;
|
nuclear@0
|
79 bool Close;
|
nuclear@0
|
80
|
nuclear@0
|
81 }; // end class CFileReadCallBack
|
nuclear@0
|
82
|
nuclear@0
|
83
|
nuclear@0
|
84
|
nuclear@0
|
85 // FACTORY FUNCTIONS:
|
nuclear@0
|
86
|
nuclear@0
|
87
|
nuclear@0
|
88 //! Creates an instance of an UFT-8 or ASCII character xml parser.
|
nuclear@0
|
89 IrrXMLReader* createIrrXMLReader(const char* filename)
|
nuclear@0
|
90 {
|
nuclear@0
|
91 return new CXMLReaderImpl<char, IXMLBase>(new CFileReadCallBack(filename));
|
nuclear@0
|
92 }
|
nuclear@0
|
93
|
nuclear@0
|
94
|
nuclear@0
|
95 //! Creates an instance of an UFT-8 or ASCII character xml parser.
|
nuclear@0
|
96 IrrXMLReader* createIrrXMLReader(FILE* file)
|
nuclear@0
|
97 {
|
nuclear@0
|
98 return new CXMLReaderImpl<char, IXMLBase>(new CFileReadCallBack(file));
|
nuclear@0
|
99 }
|
nuclear@0
|
100
|
nuclear@0
|
101
|
nuclear@0
|
102 //! Creates an instance of an UFT-8 or ASCII character xml parser.
|
nuclear@0
|
103 IrrXMLReader* createIrrXMLReader(IFileReadCallBack* callback)
|
nuclear@0
|
104 {
|
nuclear@0
|
105 return new CXMLReaderImpl<char, IXMLBase>(callback, false);
|
nuclear@0
|
106 }
|
nuclear@0
|
107
|
nuclear@0
|
108
|
nuclear@0
|
109 //! Creates an instance of an UTF-16 xml parser.
|
nuclear@0
|
110 IrrXMLReaderUTF16* createIrrXMLReaderUTF16(const char* filename)
|
nuclear@0
|
111 {
|
nuclear@0
|
112 return new CXMLReaderImpl<char16, IXMLBase>(new CFileReadCallBack(filename));
|
nuclear@0
|
113 }
|
nuclear@0
|
114
|
nuclear@0
|
115
|
nuclear@0
|
116 //! Creates an instance of an UTF-16 xml parser.
|
nuclear@0
|
117 IrrXMLReaderUTF16* createIrrXMLReaderUTF16(FILE* file)
|
nuclear@0
|
118 {
|
nuclear@0
|
119 return new CXMLReaderImpl<char16, IXMLBase>(new CFileReadCallBack(file));
|
nuclear@0
|
120 }
|
nuclear@0
|
121
|
nuclear@0
|
122
|
nuclear@0
|
123 //! Creates an instance of an UTF-16 xml parser.
|
nuclear@0
|
124 IrrXMLReaderUTF16* createIrrXMLReaderUTF16(IFileReadCallBack* callback)
|
nuclear@0
|
125 {
|
nuclear@0
|
126 return new CXMLReaderImpl<char16, IXMLBase>(callback, false);
|
nuclear@0
|
127 }
|
nuclear@0
|
128
|
nuclear@0
|
129
|
nuclear@0
|
130 //! Creates an instance of an UTF-32 xml parser.
|
nuclear@0
|
131 IrrXMLReaderUTF32* createIrrXMLReaderUTF32(const char* filename)
|
nuclear@0
|
132 {
|
nuclear@0
|
133 return new CXMLReaderImpl<char32, IXMLBase>(new CFileReadCallBack(filename));
|
nuclear@0
|
134 }
|
nuclear@0
|
135
|
nuclear@0
|
136
|
nuclear@0
|
137 //! Creates an instance of an UTF-32 xml parser.
|
nuclear@0
|
138 IrrXMLReaderUTF32* createIrrXMLReaderUTF32(FILE* file)
|
nuclear@0
|
139 {
|
nuclear@0
|
140 return new CXMLReaderImpl<char32, IXMLBase>(new CFileReadCallBack(file));
|
nuclear@0
|
141 }
|
nuclear@0
|
142
|
nuclear@0
|
143
|
nuclear@0
|
144 //! Creates an instance of an UTF-32 xml parser.
|
nuclear@0
|
145 IrrXMLReaderUTF32* createIrrXMLReaderUTF32(IFileReadCallBack* callback)
|
nuclear@0
|
146 {
|
nuclear@0
|
147 return new CXMLReaderImpl<char32, IXMLBase>(callback, false);
|
nuclear@0
|
148 }
|
nuclear@0
|
149
|
nuclear@0
|
150
|
nuclear@0
|
151 } // end namespace io
|
nuclear@0
|
152 } // end namespace irr
|