vrshoot

diff libs/assimp/irrXML/irrXML.cpp @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libs/assimp/irrXML/irrXML.cpp	Sat Feb 01 19:58:19 2014 +0200
     1.3 @@ -0,0 +1,152 @@
     1.4 +// Copyright (C) 2002-2005 Nikolaus Gebhardt
     1.5 +// This file is part of the "Irrlicht Engine" and the "irrXML" project.
     1.6 +// For conditions of distribution and use, see copyright notice in irrlicht.h and/or irrXML.h
     1.7 +
     1.8 +// Need to include Assimp, too. We're using Assimp's version of fast_atof
     1.9 +// so we need stdint.h. But no PCH.
    1.10 +
    1.11 +#include "AssimpPCH.h"
    1.12 +
    1.13 +#include "irrXML.h"
    1.14 +#include "irrString.h"
    1.15 +#include "irrArray.h"
    1.16 +#include "fast_atof.h"
    1.17 +#include "CXMLReaderImpl.h"
    1.18 +
    1.19 +namespace irr
    1.20 +{
    1.21 +namespace io
    1.22 +{
    1.23 +
    1.24 +//! Implementation of the file read callback for ordinary files
    1.25 +class CFileReadCallBack : public IFileReadCallBack
    1.26 +{
    1.27 +public:
    1.28 +
    1.29 +	//! construct from filename
    1.30 +	CFileReadCallBack(const char* filename)
    1.31 +		: File(0), Size(0), Close(true)
    1.32 +	{
    1.33 +		// open file
    1.34 +		File = fopen(filename, "rb");
    1.35 +
    1.36 +		if (File)
    1.37 +			getFileSize();
    1.38 +	}
    1.39 +
    1.40 +	//! construct from FILE pointer
    1.41 +	CFileReadCallBack(FILE* file)
    1.42 +		: File(file), Size(0), Close(false)
    1.43 +	{
    1.44 +		if (File)
    1.45 +			getFileSize();
    1.46 +	}
    1.47 +
    1.48 +	//! destructor
    1.49 +	virtual ~CFileReadCallBack()
    1.50 +	{
    1.51 +		if (Close && File)
    1.52 +			fclose(File);
    1.53 +	}
    1.54 +
    1.55 +	//! Reads an amount of bytes from the file.
    1.56 +	virtual int read(void* buffer, int sizeToRead)
    1.57 +	{
    1.58 +		if (!File)
    1.59 +			return 0;
    1.60 +
    1.61 +		return (int)fread(buffer, 1, sizeToRead, File);
    1.62 +	}
    1.63 +
    1.64 +	//! Returns size of file in bytes
    1.65 +	virtual int getSize()
    1.66 +	{
    1.67 +		return Size;
    1.68 +	}
    1.69 +
    1.70 +private:
    1.71 +
    1.72 +	//! retrieves the file size of the open file
    1.73 +	void getFileSize()
    1.74 +	{
    1.75 +		fseek(File, 0, SEEK_END);
    1.76 +		Size = ftell(File);
    1.77 +		fseek(File, 0, SEEK_SET);
    1.78 +	}
    1.79 +
    1.80 +	FILE* File;
    1.81 +	int Size;
    1.82 +	bool Close;
    1.83 +
    1.84 +}; // end class CFileReadCallBack
    1.85 +
    1.86 +
    1.87 +
    1.88 +// FACTORY FUNCTIONS:
    1.89 +
    1.90 +
    1.91 +//! Creates an instance of an UFT-8 or ASCII character xml parser. 
    1.92 +IrrXMLReader* createIrrXMLReader(const char* filename)
    1.93 +{
    1.94 +	return new CXMLReaderImpl<char, IXMLBase>(new CFileReadCallBack(filename)); 
    1.95 +}
    1.96 +
    1.97 +
    1.98 +//! Creates an instance of an UFT-8 or ASCII character xml parser. 
    1.99 +IrrXMLReader* createIrrXMLReader(FILE* file)
   1.100 +{
   1.101 +	return new CXMLReaderImpl<char, IXMLBase>(new CFileReadCallBack(file)); 
   1.102 +}
   1.103 +
   1.104 +
   1.105 +//! Creates an instance of an UFT-8 or ASCII character xml parser. 
   1.106 +IrrXMLReader* createIrrXMLReader(IFileReadCallBack* callback)
   1.107 +{
   1.108 +	return new CXMLReaderImpl<char, IXMLBase>(callback, false); 
   1.109 +}
   1.110 +
   1.111 +
   1.112 +//! Creates an instance of an UTF-16 xml parser. 
   1.113 +IrrXMLReaderUTF16* createIrrXMLReaderUTF16(const char* filename)
   1.114 +{
   1.115 +	return new CXMLReaderImpl<char16, IXMLBase>(new CFileReadCallBack(filename)); 
   1.116 +}
   1.117 +
   1.118 +
   1.119 +//! Creates an instance of an UTF-16 xml parser. 
   1.120 +IrrXMLReaderUTF16* createIrrXMLReaderUTF16(FILE* file)
   1.121 +{
   1.122 +	return new CXMLReaderImpl<char16, IXMLBase>(new CFileReadCallBack(file)); 
   1.123 +}
   1.124 +
   1.125 +
   1.126 +//! Creates an instance of an UTF-16 xml parser. 
   1.127 +IrrXMLReaderUTF16* createIrrXMLReaderUTF16(IFileReadCallBack* callback)
   1.128 +{
   1.129 +	return new CXMLReaderImpl<char16, IXMLBase>(callback, false); 
   1.130 +}
   1.131 +
   1.132 +
   1.133 +//! Creates an instance of an UTF-32 xml parser. 
   1.134 +IrrXMLReaderUTF32* createIrrXMLReaderUTF32(const char* filename)
   1.135 +{
   1.136 +	return new CXMLReaderImpl<char32, IXMLBase>(new CFileReadCallBack(filename)); 
   1.137 +}
   1.138 +
   1.139 +
   1.140 +//! Creates an instance of an UTF-32 xml parser. 
   1.141 +IrrXMLReaderUTF32* createIrrXMLReaderUTF32(FILE* file)
   1.142 +{
   1.143 +	return new CXMLReaderImpl<char32, IXMLBase>(new CFileReadCallBack(file)); 
   1.144 +}
   1.145 +
   1.146 +
   1.147 +//! Creates an instance of an UTF-32 xml parser. 
   1.148 +IrrXMLReaderUTF32* createIrrXMLReaderUTF32(IFileReadCallBack* callback)
   1.149 +{
   1.150 +	return new CXMLReaderImpl<char32, IXMLBase>(callback, false); 
   1.151 +}
   1.152 +
   1.153 +
   1.154 +} // end namespace io
   1.155 +} // end namespace irr