SPARK  0.1.0
A general purpose game engine written in C++.
Loading...
Searching...
No Matches
ApplicationBuilder.h
1#pragma once
2
3#include "spark/base/Exception.h"
4
5#include "spark/mpl/typelist.h"
6
7namespace spark::core
8{
9 template <typename... Tags>
11 {
13 throw spark::base::DuplicatedApplicationException("There is already an instance of Application");
14 }
15
16 template <typename... Tags>
18 : m_settings(std::move(settings)) {}
19
20 template <typename... Tags>
22 {
23 static_assert(!spark::mpl::typelist<Tags...>::template contains<details::application_tags::set_name_called>, "Cannot set application name twice.");
24
25 m_settings.name = std::move(name);
26 return ApplicationBuilder<details::application_tags::set_name_called, Tags...>(std::move(m_settings));
27 }
28
29 template <typename... Tags>
31 {
32 static_assert(!spark::mpl::typelist<Tags...>::template contains<details::application_tags::set_size_called>, "Cannot set window size twice.");
33
34 m_settings.size.x = width;
35 m_settings.size.y = height;
36 return ApplicationBuilder<details::application_tags::set_size_called, Tags...>(std::move(m_settings));
37 }
38
39 template <typename... Tags>
41 {
42 static_assert(!spark::mpl::typelist<Tags...>::template contains<details::application_tags::set_resize_policy>, "Cannot set resize policy twice.");
43 m_settings.resizable = resizable;
44 return ApplicationBuilder<details::application_tags::set_resize_policy, Tags...>(std::move(m_settings));
45 }
46
47 template <typename... Tags>
48 std::unique_ptr<Application> ApplicationBuilder<Tags...>::build()
49 {
50 static_assert(spark::mpl::typelist<Tags...>::template contains<details::application_tags::set_name_called>, "Cannot build application without setting the name.");
51 static_assert(spark::mpl::typelist<Tags...>::template contains<details::application_tags::set_size_called>, "Cannot build application without setting the window size.");
52
53 auto app = std::unique_ptr<Application>(new Application(m_settings));
54 app->s_instance = app.get();
55 return app;
56 }
57}
Exception thrown when trying to create multiple instances of an application, which is not allowed.
Definition Exception.h:91
Definition ApplicationBuilder.h:18
ApplicationBuilder< details::application_tags::set_resize_policy, Tags... > setResizable(bool resizable)
Sets whether the application window is resizable.
Definition ApplicationBuilder.h:40
ApplicationBuilder< details::application_tags::set_size_called, Tags... > setSize(unsigned int width, unsigned int height)
Sets the size of the application window.
Definition ApplicationBuilder.h:30
ApplicationBuilder< details::application_tags::set_name_called, Tags... > setName(std::string name)
Sets the name of the application.
Definition ApplicationBuilder.h:21
std::unique_ptr< Application > build()
Builds the application with the given settings.
Definition ApplicationBuilder.h:48
A class representing a SPARK application.
Definition Application.h:19
static Application * Instance()
Gets the instance of the application.
Definition Application.cpp:53
A struct containing the settings for the application.
Definition Application.h:30
Definition typelist.h:8