tamlAssetReferencedVisitor.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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_VISITOR_H_
  25. #include "persistence/taml/tamlVisitor.h"
  26. #endif
  27. #ifndef _TAML_PARSER_H_
  28. #include "persistence/taml/tamlParser.h"
  29. #endif
  30. #ifndef _ASSET_FIELD_TYPES_H_
  31. #include "assets/assetFieldTypes.h"
  32. #endif
  33. // Debug Profiling.
  34. #include "platform/profiler.h"
  35. //-----------------------------------------------------------------------------
  36. class TamlAssetReferencedVisitor : public TamlVisitor
  37. {
  38. public:
  39. typedef StringTableEntry typeAssetId;
  40. typedef HashMap<typeAssetId, StringTableEntry> typeAssetReferencedHash;
  41. private:
  42. typeAssetReferencedHash mAssetReferenced;
  43. public:
  44. TamlAssetReferencedVisitor() {}
  45. virtual ~TamlAssetReferencedVisitor() {}
  46. const typeAssetReferencedHash& getAssetReferencedMap( void ) const { return mAssetReferenced; }
  47. void clear( void ) { mAssetReferenced.clear(); }
  48. virtual bool wantsPropertyChanges( void ) { return false; }
  49. virtual bool wantsRootOnly( void ) { return false; }
  50. virtual bool visit( const TamlParser& parser, TamlVisitor::PropertyState& propertyState )
  51. {
  52. // Debug Profiling.
  53. PROFILE_SCOPE(TamlAssetReferencedVisitor_Visit);
  54. // Fetch property value.
  55. const char* pPropertyValue = propertyState.getPropertyValue();
  56. // Fetch property word count.
  57. const U32 propertyWordCount = StringUnit::getUnitCount( pPropertyValue, ASSET_ASSIGNMENT_TOKEN );
  58. // Finish if there's not two words.
  59. if ( propertyWordCount != 2 )
  60. return true;
  61. // Finish if the first word is not an asset signature.
  62. if ( StringTable->insert( StringUnit::getUnit( pPropertyValue, 0, ASSET_ASSIGNMENT_TOKEN ) ) != assetLooseIdSignature )
  63. return true;
  64. // Get asset Id.
  65. typeAssetId assetId = StringTable->insert( StringUnit::getUnit( pPropertyValue, 1, ASSET_ASSIGNMENT_TOKEN ) );
  66. // Finish if we already have this asset Id.
  67. if ( mAssetReferenced.contains( assetId ) )
  68. return true;
  69. // Insert asset reference.
  70. mAssetReferenced.insert( assetId, StringTable->EmptyString() );
  71. return true;
  72. }
  73. };
  74. #endif // _TAML_ASSET_REFERENCED_VISITOR_H_