4#include "interfaces/IArguments.hpp"
5#include "interfaces/IHittable.hpp"
6#include "interfaces/IMaterial.hpp"
7#include "interfaces/ITexture.hpp"
9#include <unordered_map>
11#ifndef __CFG_FACTORY_HPP__
12 #define __CFG_FACTORY_HPP__
14namespace Raytracer::Config
16 enum class ConfigTextures {
23 enum class ConfigEffects {
31 enum class ConfigMaterials {
34 MATERIAL_DIFFUSE_LIGHT,
39 enum class ConfigShapes {
48 template <
typename I,
typename E>
49 requires std::is_enum_v<E>
50 using FactoryFunction = std::function<std::shared_ptr<I>(
51 std::shared_ptr<Interfaces::IArguments>)>;
53 template <
typename I,
typename E>
54 using FactoryMap = std::unordered_map<std::string, FactoryFunction<I, E>>;
56 template <
typename T,
typename E>
57 concept isValidEnum = std::is_enum_v<T> && std::is_same_v<T, E>;
63 template <
typename I,
typename E>
64 static std::shared_ptr<I> _get(
const FactoryMap<I, E> &map,
65 const std::string &name,
66 std::shared_ptr<Interfaces::IArguments> args)
68 return map.at(name)(args);
72 static FactoryMap<Raytracer::Interfaces::ITexture, ConfigTextures>
74 static FactoryMap<Raytracer::Interfaces::IHittable, ConfigEffects>
76 static FactoryMap<Raytracer::Interfaces::IMaterial, ConfigMaterials>
78 static FactoryMap<Raytracer::Interfaces::IHittable, ConfigShapes>
81 template <
typename I,
typename E>
83 static std::shared_ptr<I> get(
const std::string &name,
84 std::shared_ptr<Interfaces::IArguments> args)
86 return _get<I, E>(
textures, name, args);
89 template <
typename I,
typename E>
91 static std::shared_ptr<I> get(
const std::string &name,
92 std::shared_ptr<Interfaces::IArguments> args)
94 return _get<I, E>(
effects, name, args);
97 template <
typename I,
typename E>
99 static std::shared_ptr<I> get(
const std::string &name,
100 std::shared_ptr<Interfaces::IArguments> args)
102 return _get<I, E>(
materials, name, args);
105 template <
typename I,
typename E>
107 static std::shared_ptr<I> get(
const std::string &name,
108 std::shared_ptr<Interfaces::IArguments> args)
110 return _get<I, E>(
shapes, name, args);
Definition Factory.hpp:59
static FactoryMap< Raytracer::Interfaces::IMaterial, ConfigMaterials > materials
Factory map for materials.
Definition Factory.hpp:182
static FactoryMap< Raytracer::Interfaces::ITexture, ConfigTextures > textures
Factory map for textures.
Definition Factory.hpp:37
static FactoryMap< Raytracer::Interfaces::IHittable, ConfigEffects > effects
Factory map for effects.
Definition Factory.hpp:104
static FactoryMap< Raytracer::Interfaces::IHittable, ConfigShapes > shapes
Factory map for shapes.
Definition Factory.hpp:289
Definition Factory.hpp:57