CXMLReader.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright (C) 2002-2012 Nikolaus Gebhardt
  2. // This file is part of the "Irrlicht Engine".
  3. // For conditions of distribution and use, see copyright notice in irrlicht.h
  4. #include "CXMLReaderImpl.h"
  5. #include "CXMLReader.h"
  6. #include "IReadFile.h"
  7. namespace irr
  8. {
  9. namespace io
  10. {
  11. //! Irrlicht implementation of the file read callback for the xml parser
  12. class CIrrXMLFileReadCallBack : public IFileReadCallBack
  13. {
  14. public:
  15. //! construct from FILE pointer
  16. CIrrXMLFileReadCallBack(IReadFile* file)
  17. : ReadFile(file)
  18. {
  19. ReadFile->grab();
  20. }
  21. //! destructor
  22. virtual ~CIrrXMLFileReadCallBack()
  23. {
  24. ReadFile->drop();
  25. }
  26. //! Reads an amount of bytes from the file.
  27. virtual int read(void* buffer, int sizeToRead)
  28. {
  29. return ReadFile->read(buffer, sizeToRead);
  30. }
  31. //! Returns size of file in bytes
  32. virtual long getSize() const
  33. {
  34. return ReadFile->getSize();
  35. }
  36. private:
  37. IReadFile* ReadFile;
  38. }; // end class CMyXMLFileReadCallBack
  39. // now create an implementation for IXMLReader using irrXML.
  40. //! Creates an instance of a wide character xml parser.
  41. IXMLReader* createIXMLReader(IReadFile* file)
  42. {
  43. if (!file)
  44. return 0;
  45. return new CXMLReaderImpl<wchar_t, IReferenceCounted>(new CIrrXMLFileReadCallBack(file));
  46. }
  47. //! Creates an instance of an UFT-8 or ASCII character xml parser.
  48. IXMLReaderUTF8* createIXMLReaderUTF8(IReadFile* file)
  49. {
  50. if (!file)
  51. return 0;
  52. return new CXMLReaderImpl<char, IReferenceCounted>(new CIrrXMLFileReadCallBack(file));
  53. }
  54. } // end namespace
  55. } // end namespace