tamlAssetReferencedVisitor.h 3.6 KB

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