SourceAssetReference.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <QString>
  10. #include <AzCore/Interface/Interface.h>
  11. #include <AzCore/IO/Path/Path.h>
  12. #include <utilities/IPathConversion.h>
  13. #include <native/AssetManager/assetScanFolderInfo.h>
  14. #include <AssetDatabase/AssetDatabaseConnection.h>
  15. namespace AssetProcessor
  16. {
  17. //! Represents a reference to a single source asset on disk
  18. class SourceAssetReference
  19. {
  20. public:
  21. SourceAssetReference() = default;
  22. explicit SourceAssetReference(const char* absolutePath)
  23. : SourceAssetReference(AZ::IO::PathView(absolutePath))
  24. {
  25. }
  26. explicit SourceAssetReference(QString absolutePath)
  27. : SourceAssetReference(absolutePath.toUtf8().constData())
  28. {
  29. }
  30. explicit SourceAssetReference(AZ::IO::PathView absolutePath);
  31. SourceAssetReference(AZ::s64 scanFolderId, AZ::IO::PathView pathRelativeToScanFolder);
  32. SourceAssetReference(const AzToolsFramework::AssetDatabase::SourceDatabaseEntry& sourceEntry)
  33. : SourceAssetReference(sourceEntry.m_scanFolderPK, sourceEntry.m_sourceName.c_str())
  34. {
  35. }
  36. SourceAssetReference(QString scanFolderPath, QString pathRelativeToScanFolder)
  37. : SourceAssetReference(
  38. AZ::IO::PathView(scanFolderPath.toUtf8().constData()), AZ::IO::PathView(pathRelativeToScanFolder.toUtf8().constData()))
  39. {
  40. }
  41. SourceAssetReference(const char* scanFolderPath, const char* pathRelativeToScanFolder)
  42. : SourceAssetReference(AZ::IO::PathView(scanFolderPath), AZ::IO::PathView(pathRelativeToScanFolder))
  43. {
  44. }
  45. SourceAssetReference(AZ::IO::PathView scanFolderPath, AZ::IO::PathView pathRelativeToScanFolder);
  46. SourceAssetReference(AZ::s64 scanFolderId, AZ::IO::PathView scanFolderPath, AZ::IO::PathView pathRelativeToScanFolder);
  47. AZ_DEFAULT_COPY_MOVE(SourceAssetReference);
  48. bool operator==(const SourceAssetReference& other) const;
  49. bool operator!=(const SourceAssetReference& other) const;
  50. bool operator<(const SourceAssetReference& other) const;
  51. bool operator>(const SourceAssetReference& other) const;
  52. explicit operator bool() const;
  53. bool IsValid() const;
  54. AZ::IO::FixedMaxPath AbsolutePath() const;
  55. AZ::IO::FixedMaxPath RelativePath() const;
  56. AZ::IO::FixedMaxPath ScanFolderPath() const;
  57. AZ::s64 ScanFolderId() const;
  58. private:
  59. void Normalize();
  60. AZ::IO::Path m_absolutePath;
  61. AZ::IO::Path m_relativePath;
  62. AZ::IO::Path m_scanFolderPath;
  63. AZ::s64 m_scanFolderId{};
  64. };
  65. }
  66. namespace AZStd
  67. {
  68. template<>
  69. struct hash<AssetProcessor::SourceAssetReference>
  70. {
  71. using argument_type = AssetProcessor::SourceAssetReference;
  72. using result_type = size_t;
  73. result_type operator()(const argument_type& obj) const;
  74. };
  75. }