Line data Source code
1 : // 2 : // Copyright 2024 OpenModelViewer Authors 3 : // 4 : // Licensed under the Apache License, Version 2.0 (the "License"); 5 : // you may not use this file except in compliance with the License. 6 : // You may obtain a copy of the License at 7 : // 8 : // http://www.apache.org/licenses/LICENSE-2.0 9 : // 10 : // Unless required by applicable law or agreed to in writing, software 11 : // distributed under the License is distributed on an "AS IS" BASIS, 12 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 : // See the License for the specific language governing permissions and 14 : // limitations under the License. 15 : // 16 : 17 : #pragma once 18 : 19 : #include "openmodelviewer/core/resource/resource_handle.hpp" 20 : #include "openmodelviewer/core/id/atomic_id_generator.hpp" 21 : 22 : namespace openmodelviewer::core::resource 23 : { 24 : /** 25 : * @brief Generator for creating unique ResourceHandle objects. 26 : * 27 : * This class encapsulates the logic for assigning thread-safe unique IDs 28 : * to tasks. It relies on an AtomicIdGenerator internally to ensure 29 : * uniqueness across threads. 30 : */ 31 : class ResourceHandleGenerator 32 : { 33 : public: 34 : /** 35 : * @brief Constructs a new ResourceHandleGenerator. 36 : * 37 : * @note Initializes the internal counter to start at 1. 38 : */ 39 50 : ResourceHandleGenerator() = default; 40 : 41 : /** 42 : * @brief Generates a new ResourceHandle with a unique ResourceId. 43 : * 44 : * Each call produces a TaskHandle with a unique TaskId and the 45 : * specified TaskType. 46 : * 47 : * @param type The type of thread or queue for which the task is scheduled. 48 : * @return A TaskHandle with a unique identifier and the specified type. 49 : */ 50 : ResourceHandle generate() noexcept; 51 : private: 52 : id::AtomicIdGenerator m_generator; 53 : }; 54 : } // namespace openmodelviewer::core::resource