MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / accept

Method accept

Engine/source/persistence/taml/json/tamlJSONParser.cpp:34–121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32//-----------------------------------------------------------------------------
33
34bool 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 );

Callers

nothing calls this directly

Calls 11

expandToolScriptFilenameFunction · 0.85
EmptyStringMethod · 0.80
AcceptMethod · 0.80
openMethod · 0.65
closeMethod · 0.65
warnfFunction · 0.50
getStreamSizeMethod · 0.45
readMethod · 0.45
GetTypeMethod · 0.45
MemberBeginMethod · 0.45
AddMemberMethod · 0.45

Tested by

no test coverage detected