vrshoot

view libs/assimp/irrXML/irrXML.cpp @ 2:334d17aed7de

visual studio project files
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 02 Feb 2014 18:36:38 +0200
parents
children
line source
1 // Copyright (C) 2002-2005 Nikolaus Gebhardt
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
5 // Need to include Assimp, too. We're using Assimp's version of fast_atof
6 // so we need stdint.h. But no PCH.
8 #include "AssimpPCH.h"
10 #include "irrXML.h"
11 #include "irrString.h"
12 #include "irrArray.h"
13 #include "fast_atof.h"
14 #include "CXMLReaderImpl.h"
16 namespace irr
17 {
18 namespace io
19 {
21 //! Implementation of the file read callback for ordinary files
22 class CFileReadCallBack : public IFileReadCallBack
23 {
24 public:
26 //! construct from filename
27 CFileReadCallBack(const char* filename)
28 : File(0), Size(0), Close(true)
29 {
30 // open file
31 File = fopen(filename, "rb");
33 if (File)
34 getFileSize();
35 }
37 //! construct from FILE pointer
38 CFileReadCallBack(FILE* file)
39 : File(file), Size(0), Close(false)
40 {
41 if (File)
42 getFileSize();
43 }
45 //! destructor
46 virtual ~CFileReadCallBack()
47 {
48 if (Close && File)
49 fclose(File);
50 }
52 //! Reads an amount of bytes from the file.
53 virtual int read(void* buffer, int sizeToRead)
54 {
55 if (!File)
56 return 0;
58 return (int)fread(buffer, 1, sizeToRead, File);
59 }
61 //! Returns size of file in bytes
62 virtual int getSize()
63 {
64 return Size;
65 }
67 private:
69 //! retrieves the file size of the open file
70 void getFileSize()
71 {
72 fseek(File, 0, SEEK_END);
73 Size = ftell(File);
74 fseek(File, 0, SEEK_SET);
75 }
77 FILE* File;
78 int Size;
79 bool Close;
81 }; // end class CFileReadCallBack
85 // FACTORY FUNCTIONS:
88 //! Creates an instance of an UFT-8 or ASCII character xml parser.
89 IrrXMLReader* createIrrXMLReader(const char* filename)
90 {
91 return new CXMLReaderImpl<char, IXMLBase>(new CFileReadCallBack(filename));
92 }
95 //! Creates an instance of an UFT-8 or ASCII character xml parser.
96 IrrXMLReader* createIrrXMLReader(FILE* file)
97 {
98 return new CXMLReaderImpl<char, IXMLBase>(new CFileReadCallBack(file));
99 }
102 //! Creates an instance of an UFT-8 or ASCII character xml parser.
103 IrrXMLReader* createIrrXMLReader(IFileReadCallBack* callback)
104 {
105 return new CXMLReaderImpl<char, IXMLBase>(callback, false);
106 }
109 //! Creates an instance of an UTF-16 xml parser.
110 IrrXMLReaderUTF16* createIrrXMLReaderUTF16(const char* filename)
111 {
112 return new CXMLReaderImpl<char16, IXMLBase>(new CFileReadCallBack(filename));
113 }
116 //! Creates an instance of an UTF-16 xml parser.
117 IrrXMLReaderUTF16* createIrrXMLReaderUTF16(FILE* file)
118 {
119 return new CXMLReaderImpl<char16, IXMLBase>(new CFileReadCallBack(file));
120 }
123 //! Creates an instance of an UTF-16 xml parser.
124 IrrXMLReaderUTF16* createIrrXMLReaderUTF16(IFileReadCallBack* callback)
125 {
126 return new CXMLReaderImpl<char16, IXMLBase>(callback, false);
127 }
130 //! Creates an instance of an UTF-32 xml parser.
131 IrrXMLReaderUTF32* createIrrXMLReaderUTF32(const char* filename)
132 {
133 return new CXMLReaderImpl<char32, IXMLBase>(new CFileReadCallBack(filename));
134 }
137 //! Creates an instance of an UTF-32 xml parser.
138 IrrXMLReaderUTF32* createIrrXMLReaderUTF32(FILE* file)
139 {
140 return new CXMLReaderImpl<char32, IXMLBase>(new CFileReadCallBack(file));
141 }
144 //! Creates an instance of an UTF-32 xml parser.
145 IrrXMLReaderUTF32* createIrrXMLReaderUTF32(IFileReadCallBack* callback)
146 {
147 return new CXMLReaderImpl<char32, IXMLBase>(callback, false);
148 }
151 } // end namespace io
152 } // end namespace irr