ArchiveTOC.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 <AzCore/base.h>
  10. #include <AzCore/IO/Path/Path.h>
  11. #include <AzCore/std/containers/vector.h>
  12. #include <AzCore/std/function/function_fwd.h>
  13. #include <Archive/Clients/ArchiveInterfaceStructs.h>
  14. namespace Archive
  15. {
  16. struct ArchiveTableOfContentsView;
  17. //! String type which stores the error message when enumerating archived files
  18. using EnumerateErrorString = AZStd::fixed_string<512>;
  19. //! Structure for which owns the Table of Contents data
  20. //! It contains data structure which makes it easier to dynamically add/remove/update
  21. //! files to the table of contents while in memory
  22. struct ArchiveTableOfContents
  23. {
  24. //! The Archive TOC is either uncompressed
  25. //! or compressed based on the compression algorithm index
  26. //! set within the Archive Header
  27. ArchiveTableOfContents();
  28. //! Initializes a Table of Contents in-memory structure from a Table of Contents view
  29. using CreateFromTocViewOutcome = AZStd::expected<ArchiveTableOfContents, EnumerateErrorString>;
  30. static CreateFromTocViewOutcome CreateFromTocView(const ArchiveTableOfContentsView& tocView);
  31. //! vector storing a copy of each file metadata entry in memory
  32. //! It's length matches the value of m_fileCount
  33. AZStd::vector<ArchiveTocFileMetadata> m_fileMetadataTable;
  34. //! Wrapper path structure to ensure the Table of Contents only contain paths that
  35. //! uses the Posix Path Separator '/'
  36. //! This is used to normalize how the paths within the Table of Contents
  37. //! are stored across platforms(Linux/MacOS vs Windows)
  38. struct Path
  39. {
  40. Path() = default;
  41. Path(const Path&) = default;
  42. Path(Path&&) = default;
  43. //! Implicit conversion constructor to store move an AZ::IO::Path
  44. Path(AZ::IO::Path filePath);
  45. Path(AZ::IO::PathView filePath);
  46. Path& operator=(const Path&) = default;
  47. Path& operator=(Path&&) = default;
  48. //! Add support for storing an AZ::IO::Path into the table of contents
  49. //! as a path with only Posix Path Separators of '/'
  50. Path& operator=(AZ::IO::Path filePath);
  51. Path& operator=(AZ::IO::PathView filePath);
  52. //! implicit AZ::IO::Path operator that returns a reference
  53. //! to the underlying filesystem path
  54. operator AZ::IO::Path& () &;
  55. operator const AZ::IO::Path& () const&;
  56. operator AZ::IO::Path&& ()&&;
  57. operator const AZ::IO::Path&& () const&&;
  58. [[nodiscard]] bool empty() const;
  59. void clear();
  60. const typename AZ::IO::Path::string_type& Native() const& noexcept;
  61. const typename AZ::IO::Path::string_type&& Native() const&& noexcept;
  62. typename AZ::IO::Path::string_type& Native() & noexcept;
  63. typename AZ::IO::Path::string_type&& Native() && noexcept;
  64. const typename AZ::IO::Path::value_type* c_str() const noexcept;
  65. private:
  66. AZ::IO::Path m_posixPath{ AZ::IO::PosixPathSeparator };
  67. };
  68. //! vector storing a copy of each file path in memory
  69. //! Its length matches the value of m_fileCount
  70. using ArchiveFilePathTable = AZStd::vector<Path>;
  71. ArchiveFilePathTable m_filePaths;
  72. //! vector storing the block offset table for each file
  73. AZStd::vector<ArchiveBlockLineUnion> m_blockOffsetTable{};
  74. };
  75. } // namespace Archive
  76. // Implementation for any struct functions
  77. #include "ArchiveTOC.inl"