#pragma once #include "generic/generic_basic_store.hpp" #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 = ztu::id_type_for; 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 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, 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{}; 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_type = 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 = ztu::id_type_for; inline id_type add(const shader_source_data& shader_source); [[nodiscard]] inline std::pair find(id_type id); [[nodiscard]] inline std::pair find(id_type id) const; inline void remove(const iterator_type& it); inline void clear(); [[nodiscard]] inline iterator_type begin(); [[nodiscard]] inline iterator_type 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; [[nodiscard]] inline view_type view(); [[nodiscard]] inline const_view_type view() const; private: std::vector m_ids; std::vector m_strings; std::vector m_lengths; id_type m_next_data_id{ 1 }; }; } #define INCLUDE_SHADER_SOURCE_STORE_IMPLEMENTATION #include "assets/data_stores/shader_source_store.ipp" #undef INCLUDE_SHADER_SOURCE_STORE_IMPLEMENTATION