| 32 | //----------------------------------------------------------------------------- |
| 33 | |
| 34 | bool TamlJSONParser::accept( const char* pFilename, TamlVisitor& visitor ) |
| 35 | { |
| 36 | // Debug Profiling. |
| 37 | PROFILE_SCOPE(TamlJSONParser_Accept); |
| 38 | |
| 39 | // Sanity! |
| 40 | AssertFatal( pFilename != NULL, "Cannot parse a NULL filename." ); |
| 41 | |
| 42 | // Expand the file-path. |
| 43 | char filenameBuffer[1024]; |
| 44 | Con::expandToolScriptFilename( filenameBuffer, sizeof(filenameBuffer), pFilename ); |
| 45 | |
| 46 | FileStream stream; |
| 47 | |
| 48 | // File open for read? |
| 49 | if ( !stream.open( filenameBuffer, Torque::FS::File::Write ) ) |
| 50 | { |
| 51 | // No, so warn. |
| 52 | Con::warnf("TamlJSONParser::parse() - Could not open filename '%s' for parse.", filenameBuffer ); |
| 53 | return false; |
| 54 | } |
| 55 | |
| 56 | // Read JSON file. |
| 57 | const U32 streamSize = stream.getStreamSize(); |
| 58 | FrameTemp<char> jsonText( streamSize + 1 ); |
| 59 | if ( !stream.read( streamSize, jsonText ) ) |
| 60 | { |
| 61 | // Warn! |
| 62 | Con::warnf("TamlJSONParser::parse() - Could not load Taml JSON file from stream."); |
| 63 | return false; |
| 64 | } |
| 65 | |
| 66 | // Create JSON document. |
| 67 | rapidjson::Document inputDocument; |
| 68 | inputDocument.Parse<0>( jsonText ); |
| 69 | |
| 70 | // Close the stream. |
| 71 | stream.close(); |
| 72 | |
| 73 | // Check the document is valid. |
| 74 | if ( inputDocument.GetType() != rapidjson::kObjectType ) |
| 75 | { |
| 76 | // Warn! |
| 77 | Con::warnf("TamlJSONParser::parse() - Load Taml JSON file from stream but was invalid."); |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | // Set parsing filename. |
| 82 | setParsingFilename( filenameBuffer ); |
| 83 | |
| 84 | // Flag document as not dirty. |
| 85 | mDocumentDirty = false; |
| 86 | |
| 87 | // Fetch the root. |
| 88 | rapidjson::Value::MemberIterator rootItr = inputDocument.MemberBegin(); |
| 89 | |
| 90 | // Parse root value. |
| 91 | parseType( rootItr, visitor, true ); |
nothing calls this directly
no test coverage detected