the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 156 lines 5.7 kB view raw
1// 4J-PB - 2// The ATG Framework is a common set of C++ class libraries that is used by the samples in the XDK, and was developed by the Advanced Technology Group (ATG). 3// The ATG Framework offers a clean and consistent format for the samples. These classes define functions used by all the samples. 4// The ATG Framework together with the samples demonstrates best practices and innovative techniques for Xbox 360. There are many useful sections of code in the samples. 5// You are encouraged to incorporate this code into your titles. 6 7//------------------------------------------------------------------------------------- 8// AtgXmlParser.h 9// 10// XMLParser and SAX interface declaration 11// 12// Xbox Advanced Technology Group 13// Copyright (C) Microsoft Corporation. All rights reserved. 14//------------------------------------------------------------------------------------- 15 16#pragma once 17#ifndef ATGXMLPARSER_H 18#define ATGXMLPARSER_H 19 20namespace ATG 21{ 22 23//----------------------------------------------------------------------------- 24// error returns from XMLParse 25//----------------------------------------------------------------------------- 26#define _ATGFAC 0x61B 27#define E_COULD_NOT_OPEN_FILE MAKE_HRESULT(1, _ATGFAC, 0x0001 ) 28#define E_INVALID_XML_SYNTAX MAKE_HRESULT(1, _ATGFAC, 0x0002 ) 29 30 31CONST UINT XML_MAX_ATTRIBUTES_PER_ELEMENT = 32; 32CONST UINT XML_MAX_NAME_LENGTH = 128; 33CONST UINT XML_READ_BUFFER_SIZE = 2048; 34CONST UINT XML_WRITE_BUFFER_SIZE = 2048; 35 36// No tag can be longer than XML_WRITE_BUFFER_SIZE - an error will be returned if 37// it is 38 39//------------------------------------------------------------------------------------- 40struct XMLAttribute 41{ 42 WCHAR* strName; 43 UINT NameLen; 44 WCHAR* strValue; 45 UINT ValueLen; 46}; 47 48//------------------------------------------------------------------------------------- 49class ISAXCallback 50{ 51friend class XMLParser; 52public: 53 ISAXCallback() {}; 54 virtual ~ISAXCallback() {}; 55 56 virtual HRESULT StartDocument() = 0; 57 virtual HRESULT EndDocument() = 0; 58 59 virtual HRESULT ElementBegin( CONST WCHAR* strName, UINT NameLen, 60 CONST XMLAttribute *pAttributes, UINT NumAttributes ) = 0; 61 virtual HRESULT ElementContent( CONST WCHAR *strData, UINT DataLen, BOOL More ) = 0; 62 virtual HRESULT ElementEnd( CONST WCHAR *strName, UINT NameLen ) = 0; 63 64 virtual HRESULT CDATABegin( ) = 0; 65 virtual HRESULT CDATAData( CONST WCHAR *strCDATA, UINT CDATALen, BOOL bMore ) = 0; 66 virtual HRESULT CDATAEnd( ) = 0; 67 68 virtual VOID Error( HRESULT hError, CONST CHAR *strMessage ) = 0; 69 70 virtual VOID SetParseProgress( DWORD dwProgress ) { } 71 72 const CHAR* GetFilename() { return m_strFilename; } 73 UINT GetLineNumber() { return m_LineNum; } 74 UINT GetLinePosition() { return m_LinePos; } 75 76private: 77 CONST CHAR *m_strFilename; 78 UINT m_LineNum; 79 UINT m_LinePos; 80}; 81 82 83//------------------------------------------------------------------------------------- 84class XMLParser 85{ 86public: 87 XMLParser(); 88 ~XMLParser(); 89 90 // Register an interface inheiriting from ISAXCallback 91 VOID RegisterSAXCallbackInterface( ISAXCallback *pISAXCallback ); 92 93 // Get the registered interface 94 ISAXCallback* GetSAXCallbackInterface(); 95 96 // ParseXMLFile returns one of the following: 97 // E_COULD_NOT_OPEN_FILE - couldn't open the file 98 // E_INVALID_XML_SYNTAX - bad XML syntax according to this parser 99 // E_NOINTERFACE - RegisterSAXCallbackInterface not called 100 // E_ABORT - callback returned a fail code 101 // S_OK - file parsed and completed 102 103 HRESULT ParseXMLFile( CONST CHAR *strFilename ); 104 105 // Parses from a buffer- if you pass a WCHAR buffer (and cast it), it will 106 // correctly detect it and use unicode instead. Return codes are the 107 // same as for ParseXMLFile 108 109 HRESULT ParseXMLBuffer( CONST CHAR* strBuffer, UINT uBufferSize ); 110 111private: 112 HRESULT MainParseLoop(); 113 114 HRESULT AdvanceCharacter( BOOL bOkToFail = FALSE ); 115 VOID SkipNextAdvance(); 116 117 HRESULT ConsumeSpace(); 118 HRESULT ConvertEscape(); 119 HRESULT AdvanceElement(); 120 HRESULT AdvanceName(); 121 HRESULT AdvanceAttrVal(); 122 HRESULT AdvanceCDATA(); 123 HRESULT AdvanceComment(); 124 125 VOID FillBuffer(); 126 127#ifdef _Printf_format_string_ // VC++ 2008 and later support this annotation 128 VOID Error( HRESULT hRet, _In_z_ _Printf_format_string_ CONST CHAR* strFormat, ... ); 129#else 130 VOID Error( HRESULT hRet, CONST CHAR* strFormat, ... ); 131#endif 132 133 ISAXCallback* m_pISAXCallback; 134 135 HANDLE m_hFile; 136 CONST CHAR* m_pInXMLBuffer; 137 UINT m_uInXMLBufferCharsLeft; 138 DWORD m_dwCharsTotal; 139 DWORD m_dwCharsConsumed; 140 141 BYTE m_pReadBuf[ XML_READ_BUFFER_SIZE + 2 ]; // room for a trailing NULL 142 WCHAR m_pWriteBuf[ XML_WRITE_BUFFER_SIZE ]; 143 144 BYTE* m_pReadPtr; 145 WCHAR* m_pWritePtr; // write pointer within m_pBuf 146 147 BOOL m_bUnicode; // TRUE = 16-bits, FALSE = 8-bits 148 BOOL m_bReverseBytes; // TRUE = reverse bytes, FALSE = don't reverse 149 150 BOOL m_bSkipNextAdvance; 151 WCHAR m_Ch; // Current character being parsed 152}; 153 154} // namespace ATG 155 156#endif