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 : #pragma once 17 : 18 : #include "openmodelviewer/core/context.hpp" 19 : 20 : namespace openmodelviewer::core 21 : { 22 : class ContextBuilder 23 : { 24 : public: 25 : static ContextBuilder make() noexcept; 26 : 27 : /** 28 : * @brief Sets a custom logger instance. 29 : */ 30 : ContextBuilder& withLogger(std::shared_ptr<Logger> logger) noexcept; 31 : 32 : /** 33 : * @brief Instantiates a new logger with the given log level. 34 : */ 35 : ContextBuilder& withLogger(LogLevel level) noexcept; 36 : 37 : /** 38 : * @brief Sets a custom scheduler instance. 39 : */ 40 : ContextBuilder& withScheduler(std::shared_ptr<TaskScheduler> scheduler) noexcept; 41 : 42 : /** 43 : * @brief Instantiates a new scheduler with the given thread count. 44 : */ 45 : ContextBuilder& withScheduler(size_t threadCount) noexcept; 46 : 47 : /** 48 : * @brief Sets a custom resource manager instance. 49 : */ 50 : ContextBuilder& withResourceManager(std::shared_ptr<ResourceManager> resourceManager) noexcept; 51 : 52 : /** 53 : * @brief Automatically constructs ResourceManager from current scheduler if needed. 54 : */ 55 : std::shared_ptr<Context> build() noexcept; 56 : 57 : private: 58 : std::shared_ptr<Logger> m_logger; 59 : std::shared_ptr<TaskScheduler> m_scheduler; 60 : std::shared_ptr<ResourceManager> m_resource; 61 : 62 7 : ContextBuilder() = default; 63 : }; 64 : } // namespace openmodelviewer::core