#pragma once #include #include #include "assets/data/shader_source_data.hpp" #include "assets/data_views/shader_source_view.hpp" namespace assets { class shader_source_store; template class shader_source_store_iterator { public: using size_type = std::size_t; using length_type = ztu::u32; using id_type = shader_source_id; using metadata_type = shader_source_data::metadata; using value_type = std::pair; using id_iterator_type = id_type const*; using string_iterator_type = Char*; using length_iterator_type = const length_type*; using metadata_iterator_type = const metadata_type*; using offset_type = size_type; using difference_type = std::ptrdiff_t; using pointer = value_type*; using reference = value_type; using iterator_category = std::random_access_iterator_tag; private: friend shader_source_store; shader_source_store_iterator( id_iterator_type ids, string_iterator_type strings, length_iterator_type lengths, metadata_iterator_type metadata, std::size_t index, const offset_type& offset ); public: constexpr shader_source_store_iterator() noexcept = default; constexpr shader_source_store_iterator(const shader_source_store_iterator&) noexcept = default; constexpr shader_source_store_iterator(shader_source_store_iterator&&) noexcept = default; constexpr shader_source_store_iterator& operator=(const shader_source_store_iterator&) noexcept = default; constexpr shader_source_store_iterator& operator=(shader_source_store_iterator&&) noexcept = default; reference operator*() const; shader_source_store_iterator& operator++(); shader_source_store_iterator operator++(int); shader_source_store_iterator& operator--(); shader_source_store_iterator operator--(int); shader_source_store_iterator& operator+=(difference_type n); shader_source_store_iterator& operator-=(difference_type n); shader_source_store_iterator operator+(difference_type n) const; shader_source_store_iterator operator-(difference_type n) const; difference_type operator-(const shader_source_store_iterator& other) const; reference operator[](difference_type n) const; bool operator==(const shader_source_store_iterator& other) const; bool operator!=(const shader_source_store_iterator& other) const; bool operator<(const shader_source_store_iterator& other) const; bool operator<=(const shader_source_store_iterator& other) const; bool operator>(const shader_source_store_iterator& other) const; bool operator>=(const shader_source_store_iterator& other) const; protected: void calc_offset(difference_type n); reference dereference() const; private: id_iterator_type m_ids{}; string_iterator_type m_strings{}; length_iterator_type m_lengths{}; metadata_iterator_type m_metadata{}; size_type m_index{}; offset_type m_offset{}; }; class shader_source_store { public: using size_type = std::size_t; using count_type = ztu::u32; using iterator = shader_source_store_iterator; using const_iterator = shader_source_store_iterator; using view_type = std::ranges::subrange; using const_view_type = std::ranges::subrange; using id_type = shader_source_id; using data_type = shader_source_data; bool insert(id_type id, const data_type& data); bool insert(iterator it, id_type id, const data_type& data); [[nodiscard]] std::pair find(id_type id); [[nodiscard]] std::pair find(id_type id) const; inline void remove(const iterator& it); inline void clear(); [[nodiscard]] inline std::shared_lock acquire_read_lock() const; [[nodiscard]] inline std::unique_lock acquire_write_lock(); [[nodiscard]] inline iterator begin(); [[nodiscard]] inline iterator end(); [[nodiscard]] inline const_iterator begin() const; [[nodiscard]] inline const_iterator end() const; [[nodiscard]] inline const_iterator cbegin() const; [[nodiscard]] inline const_iterator cend() const; protected: bool unsafe_insert(iterator it, id_type id, const data_type& data); [[nodiscard]] std::pair unsafe_find(id_type id); [[nodiscard]] std::pair unsafe_find(id_type id) const; private: std::vector m_ids; std::vector m_strings; std::vector m_lengths; std::vector m_metadata; mutable std::shared_mutex m_mutex; }; } #define INCLUDE_SHADER_SOURCE_STORE_IMPLEMENTATION #include "assets/data_stores/shader_source_store.ipp" #undef INCLUDE_SHADER_SOURCE_STORE_IMPLEMENTATION