Torque3D Documentation / _generateds / tamlAssetReferencedVisitor.h

tamlAssetReferencedVisitor.h

Engine/source/assets/tamlAssetReferencedVisitor.h

More...

Classes:

Detailed Description

 1
 2//-----------------------------------------------------------------------------
 3// Copyright (c) 2013 GarageGames, LLC
 4//
 5// Permission is hereby granted, free of charge, to any person obtaining a copy
 6// of this software and associated documentation files (the "Software"), to
 7// deal in the Software without restriction, including without limitation the
 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 9// sell copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21// IN THE SOFTWARE.
22//-----------------------------------------------------------------------------
23
24#ifndef _TAML_ASSET_REFERENCED_VISITOR_H_
25#define _TAML_ASSET_REFERENCED_VISITOR_H_
26
27#ifndef _TAML_VISITOR_H_
28#include "persistence/taml/tamlVisitor.h"
29#endif
30
31#ifndef _TAML_PARSER_H_
32#include "persistence/taml/tamlParser.h"
33#endif
34
35#ifndef _ASSET_FIELD_TYPES_H_
36#include "assets/assetFieldTypes.h"
37#endif
38
39// Debug Profiling.
40#include "platform/profiler.h"
41
42//-----------------------------------------------------------------------------
43
44class TamlAssetReferencedVisitor : public TamlVisitor
45{
46public:
47    typedef StringTableEntry typeAssetId;
48    typedef HashMap<typeAssetId, StringTableEntry> typeAssetReferencedHash;
49
50private:
51    typeAssetReferencedHash mAssetReferenced;
52
53public:
54    TamlAssetReferencedVisitor() {}
55    virtual ~TamlAssetReferencedVisitor() {}
56
57    const typeAssetReferencedHash& getAssetReferencedMap( void ) const { return mAssetReferenced; }
58
59    void clear( void ) { mAssetReferenced.clear(); }
60
61    virtual bool wantsPropertyChanges( void ) { return false; }
62    virtual bool wantsRootOnly( void ) { return false; }
63
64    virtual bool visit( const TamlParser& parser, TamlVisitor::PropertyState& propertyState )
65    {    
66        // Debug Profiling.
67        PROFILE_SCOPE(TamlAssetReferencedVisitor_Visit);
68
69        // Fetch property value.
70        const char* pPropertyValue = propertyState.getPropertyValue();
71
72        // Fetch property word count.
73        const U32 propertyWordCount = StringUnit::getUnitCount( pPropertyValue, ASSET_ASSIGNMENT_TOKEN );
74
75        // Finish if there's not two words.
76        if ( propertyWordCount != 2 )
77            return true;
78
79        // Finish if the first word is not an asset signature.
80        if ( StringTable->insert( StringUnit::getUnit( pPropertyValue, 0, ASSET_ASSIGNMENT_TOKEN ) ) != assetLooseIdSignature )
81            return true;
82
83        // Get asset Id.
84        typeAssetId assetId = StringTable->insert( StringUnit::getUnit( pPropertyValue, 1, ASSET_ASSIGNMENT_TOKEN ) );
85
86        // Finish if we already have this asset Id.
87        if ( mAssetReferenced.contains( assetId ) )
88            return true;
89
90        // Insert asset reference.
91        mAssetReferenced.insert( assetId, StringTable->EmptyString() );
92
93        return true;
94    }
95};
96
97#endif // _TAML_ASSET_REFERENCED_VISITOR_H_
98