Brunot
Loading...
Searching...
No Matches
Factory.h
Go to the documentation of this file.
1// File: Factory.h
2// Description: A class to create objects. pulls from archetypes that exist in the Libraryr class to do so
3// start with Factory::make()
4// Author(s): Aidan Hartman (aidan.hartman@digipen.edu) Base Implementation
5// Marcelo Escamilla(marcelo.escamilla@digipen.edu) Audio implementation
6// Bryley Elder (bryley.elder@digipen.edu) Added components to factory creation
7// 2025 / 11 / 02
8// (C) Digipen 2025
9// Factory.h
10// ____ __ __ __
11// /\__ _\/\ \ /\ \/\ \
12// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
13// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
14// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
15// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
16// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
17
18#pragma once
19#include <string>
20
21#include "Framework/Library.h"
23
24
25namespace th
26{
27
29{
30 friend Library;
31
32public:
33#pragma region static_functions
34
35
43 template <typename T>
44 static auto make(const std::string& name) -> std::unique_ptr<T>
45 {
46 hlg::Trace("Getting {} from library ##START", name);
47 T* archetype = Library::get<T>(name);
48 auto result = std::make_unique<T>(*archetype);
49 hlg::Trace("##END Getting {} from library", name);
50 return result;
51 }
52
53
60 template <>
61 auto make<GameObject>(const std::string& name) -> std::unique_ptr<GameObject>
62 {
63 hlg::Trace("Getting {} from library ##START", name);
64 auto archetype = Library::get<GameObject>(name);
65 auto result = archetype->clone();
66 hlg::Trace("##END Getting {} from library", name);
67 return result;
68 }
69
70
71#pragma endregion
72
73 Factory() = delete;
74 ~Factory() = delete;
75 Factory(const Factory& other) = delete;
76 Factory(Factory&& other) noexcept = delete;
77 auto operator=(const Factory& other) -> Factory& = delete;
78 auto operator=(Factory&& other) noexcept -> Factory& = delete;
79
80
81#pragma region overridden_functions
82#pragma endregion
83
84#pragma region Factory_Functions
85
86
87#pragma endregion
88
89private:
95 static auto create(const std::string& name) -> std::unique_ptr<AnySerializable>;
96
103 static auto makePath(const std::string& name) -> std::string;
104};
105} // namespace th
static FMOD_RESULT result
Definition AudioObject.cpp:27
Factory()=delete
auto operator=(Factory &&other) noexcept -> Factory &=delete
Factory(Factory &&other) noexcept=delete
~Factory()=delete
static auto make(const std::string &name) -> std::unique_ptr< T >
create an object and heap allocate it.
Definition Factory.h:44
static auto create(const std::string &name) -> std::unique_ptr< AnySerializable >
create an object and heap allocate it.
Definition Factory.cpp:401
static auto makePath(const std::string &name) -> std::string
prepends "Data/" and appends ".json" to a string maybe in the future we will allow this to handle sub...
Definition Factory.cpp:433
auto operator=(const Factory &other) -> Factory &=delete
Factory(const Factory &other)=delete
friend Library
Definition Factory.h:30
static auto get(const std::string &name) -> T *
get a pointer to an object in the library.
Definition Library.h:48
auto Trace(spdlog::format_string_t< Args... > message, Args &&... args) -> void
Definition Logging.h:46
Definition Factory.cpp:59