1 /*
2     Copyright (c) 2008-2009 NetAllied Systems GmbH
3 
4     This file is part of COLLADASaxFrameworkLoader.
5 
6     Licensed under the MIT Open Source License,
7     for details please see LICENSE file or the website
8     http://www.opensource.org/licenses/mit-license.php
9 */
10 
11 #ifndef __COLLADASAXFWL_VERSIONPARSER_H__
12 #define __COLLADASAXFWL_VERSIONPARSER_H__
13 
14 #include "COLLADASaxFWLPrerequisites.h"
15 #include "COLLADASaxFWLTypes.h"
16 #include "COLLADASaxFWLColladaParserAutoGen14FunctionMapFactory.h"
17 #include "COLLADASaxFWLColladaParserAutoGen15FunctionMapFactory.h"
18 
19 #include "GeneratedSaxParserParser.h"
20 
21 namespace COLLADASaxFWL14
22 {
23     class ColladaParserAutoGen14Private;
24 }
25 namespace COLLADASaxFWL15
26 {
27     class ColladaParserAutoGen15Private;
28 }
29 
30 namespace COLLADASaxFWL
31 {
32     class FileLoader;
33 
34     /**
35      * Starts parsing a file to find out which COLLADA version it uses.
36      * Creates appropriate parser and continues with that.
37      */
38     class VersionParser : public GeneratedSaxParser::Parser
39     {
40     private:
41         /** The function map we use to parse the COLLADA file. It contains only those elements that are required
42         to parse all the objects listed in given flags.*/
43         COLLADASaxFWL14::ColladaParserAutoGen14Private::ElementFunctionMap mFunctionMap14;
44         COLLADASaxFWL15::ColladaParserAutoGen15Private::ElementFunctionMap mFunctionMap15;
45 
46         /** Private Parser for COLLADA 1.4 */
47         COLLADASaxFWL14::ColladaParserAutoGen14Private* mPrivateParser14;
48         /** Private Parser for COLLADA 1.5 */
49         COLLADASaxFWL15::ColladaParserAutoGen15Private* mPrivateParser15;
50 
51         /** File loader to use. */
52         FileLoader* mFileLoader;
53         /** Indicates which parts of the file shall be parsed. */
54         int mFlags;
55         /** Indicates which parts of the file have already been parsed. */
56         int& mParsedFlags;
57 
58     public:
59         VersionParser(GeneratedSaxParser::IErrorHandler* errorHandler,
60             FileLoader* fileLoader,
61             int flags,
62             int& parsedFlags);
63         virtual ~VersionParser();
64 
65         virtual bool elementBegin(const ParserChar* elementName, const ParserAttributes& attributes );
66 
67         virtual bool elementEnd(const ParserChar* elementName );
68 
69         virtual bool textData(const ParserChar* text, size_t textLength);
70 
71 		/** Returns the element of the element in level @a level, where the previous element is level 0.
72 		If level is invalid, 0 is returned.*/
73 		StringHash getElementHash( size_t level = 0 )const;
74 
75         /**
76         * Creates generated parser objects and starts parsing the input file.
77         * Will determine COLLADA version of input file and use appropriate parser.
78         */
79         bool createAndLaunchParser();
80         bool createAndLaunchParser(const char* buffer, int length);
81 
82     protected:
83         void createFunctionMap14();
84         void createFunctionMap15();
85         bool parse14( const ParserChar* elementName, const ParserAttributes& attributes );
86         bool parse15( const ParserChar* elementName, const ParserAttributes& attributes );
87     };
88 }
89 
90 #endif // __COLLADASAXFWL_VERSIONPARSER_H__
91