Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
SdlEnum.h
Go to the documentation of this file.
1#pragma once
2
3#include <Common/primitive_type.h>
4
5#include <string>
6#include <string_view>
7#include <cstddef>
8#include <utility>
9#include <vector>
10
11namespace ph
12{
13
22{
23public:
24 template<typename ValueType>
25 struct TEntry
26 {
27 std::string_view name;
28 ValueType value;
29
30 inline TEntry() :
31 name(), value(static_cast<ValueType>(0))
32 {}
33
34 inline TEntry(std::string_view name, ValueType value) :
35 name(std::move(name)), value(std::move(value))
36 {}
37 };
38
40
41 explicit SdlEnum(std::string name);
42
43 virtual Entry getEntry(std::size_t entryIndex) const = 0;
44 virtual std::size_t numEntries() const = 0;
45
46 const std::string& getName() const;
47 const std::string& getDescription() const;
48 std::string getEntryDescription(std::size_t entryIndex) const;
49
50protected:
51 SdlEnum& setDescription(std::string description);
52 SdlEnum& setEntryDescription(std::size_t entryIndex, std::string description);
53
54private:
55 std::string m_name;
56 std::string m_description;
57 std::vector<std::string> m_entryDescriptions;
58};
59
60// In-header Implementations:
61
62inline SdlEnum::SdlEnum(std::string name) :
63 m_name(std::move(name))
64{
65 PH_ASSERT(!m_name.empty());
66}
67
68inline SdlEnum& SdlEnum::setDescription(std::string description)
69{
70 m_description = std::move(description);
71
72 return *this;
73}
74
75inline SdlEnum& SdlEnum::setEntryDescription(const std::size_t entryIndex, std::string description)
76{
77 // Allocate more storage for entry descriptions if required
78 if(entryIndex >= m_entryDescriptions.size())
79 {
80 m_entryDescriptions.resize(entryIndex + 1);
81 }
82
83 PH_ASSERT_LT(entryIndex, m_entryDescriptions.size());
84 m_entryDescriptions[entryIndex] = std::move(description);
85
86 return *this;
87}
88
89inline const std::string& SdlEnum::getName() const
90{
91 return m_name;
92}
93
94inline const std::string& SdlEnum::getDescription() const
95{
96 return m_description;
97}
98
99// Returns a copy of string as the method accepts out-of-bound entry index
100inline std::string SdlEnum::getEntryDescription(const std::size_t entryIndex) const
101{
102 return entryIndex < m_entryDescriptions.size() ?
103 m_entryDescriptions[entryIndex] : "";
104}
105
106}// end namespace ph
Describes enum in SDL.
Definition SdlEnum.h:22
const std::string & getName() const
Definition SdlEnum.h:89
SdlEnum & setDescription(std::string description)
Definition SdlEnum.h:68
std::string getEntryDescription(std::size_t entryIndex) const
Definition SdlEnum.h:100
SdlEnum(std::string name)
Definition SdlEnum.h:62
SdlEnum & setEntryDescription(std::size_t entryIndex, std::string description)
Definition SdlEnum.h:75
const std::string & getDescription() const
Definition SdlEnum.h:94
virtual Entry getEntry(std::size_t entryIndex) const =0
virtual std::size_t numEntries() const =0
The root for all renderer implementations.
Definition EEngineProject.h:6
Definition TAABB2D.h:96
Definition SdlEnum.h:26
ValueType value
Definition SdlEnum.h:28
TEntry(std::string_view name, ValueType value)
Definition SdlEnum.h:34
std::string_view name
Definition SdlEnum.h:27
TEntry()
Definition SdlEnum.h:30