Cogs.Core
Attributes.h
1#pragma once
2
3#include "../Reflection/Attributes.h"
4
5namespace Cogs
6{
7 namespace ComponentModel
8 {
14 template<typename T>
15 struct DefaultValueAttribute : public Reflection::GenericAttribute<DefaultValueAttribute, T>
16 {
23 {
24 Reflection::Attribute::get<T>(0) = value;
25 }
26
28 T getValue() const { return Reflection::Attribute::get<T>(0); }
29 };
30
36 template<typename T>
37 struct RangeAttribute : public Reflection::GenericAttribute<RangeAttribute, T>
38 {
45 RangeAttribute(T min, T max)
46 {
47 Reflection::Attribute::get<T>(0) = min;
48 Reflection::Attribute::get<T>(1) = max;
49 }
50
52 T getMin() const { return Reflection::Attribute::get<T>(0); }
53
55 T getMax() const { return Reflection::Attribute::get<T>(1); }
56 };
57
63 template<typename T>
64 struct StepSizeAttribute : public Reflection::GenericAttribute<StepSizeAttribute, T>
65 {
72 {
73 Reflection::Attribute::get<T>(0) = value;
74 }
75
77 T getStepValue() const { return Reflection::Attribute::get<T>(0); }
78
79 };
80
84 struct SerializableAttribute : public Reflection::RegularAttribute<SerializableAttribute>
85 {
86
87 };
88
92 struct DescriptionAttribute : public Reflection::RegularAttribute<DescriptionAttribute>
93 {
99#if !defined( EMSCRIPTEN )
101 : Reflection::RegularAttribute<DescriptionAttribute>(false)
102 {
103 Attribute::get<StringView>(0) = text;
104 }
105#else
106 // Skip generation of description on Cogs.js. Save space. CodeGen not run in Cogs.js.
107 DescriptionAttribute(const char*)
108 : Reflection::RegularAttribute<DescriptionAttribute>(false)
109 {
110 Attribute::get<StringView>(0) = StringView();
111 }
112#endif
113
115 const StringView & getValue() const { return Attribute::get<StringView>(0); }
116 };
117
121 struct ColorAttribute : public Reflection::RegularAttribute<ColorAttribute>
122 {
123
124 };
125 }
126}
127
128template<> inline Cogs::StringView getName<Cogs::ComponentModel::StepSizeAttribute<float>>() { return "StepSizeAttribute"; }
129template<> inline Cogs::StringView getName<Cogs::ComponentModel::RangeAttribute<float>>() { return "RangeAttribute"; }
130template<> inline Cogs::StringView getName<Cogs::ComponentModel::RangeAttribute<int>>() { return "RangeAttribute"; }
131template<> inline Cogs::StringView getName<Cogs::ComponentModel::RangeAttribute<uint32_t>>() { return "RangeAttribute"; }
132template<> inline Cogs::StringView getName<Cogs::ComponentModel::DefaultValueAttribute<float>>() { return "DefaultValueAttribute"; }
133template<> inline Cogs::StringView getName<Cogs::ComponentModel::DefaultValueAttribute<uint32_t>>() { return "DefaultValueAttribute"; }
134template<> inline Cogs::StringView getName<Cogs::ComponentModel::DefaultValueAttribute<int32_t>>() { return "DefaultValueAttribute"; }
135template<> inline Cogs::StringView getName<Cogs::ComponentModel::DefaultValueAttribute<double>>() { return "DefaultValueAttribute"; }
136template<> inline Cogs::StringView getName<Cogs::ComponentModel::DescriptionAttribute>() { return "DescriptionAttribute"; }
137template<> inline Cogs::StringView getName<Cogs::ComponentModel::ColorAttribute>() { return "ColorAttribute"; }
138template<> inline Cogs::StringView getName<Cogs::ComponentModel::SerializableAttribute>() { return "SerializableAttribute"; }
Provides a weakly referenced view over the contents of a string.
Definition: StringView.h:24
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
Tags an object as being able to represent a color.
Definition: Attributes.h:122
Adds default value information to an object.
Definition: Attributes.h:16
DefaultValueAttribute(T value)
Constructs a default value attribute from the given value.
Definition: Attributes.h:22
T getValue() const
Get the default value.
Definition: Attributes.h:28
Adds a description to an object.
Definition: Attributes.h:93
DescriptionAttribute(StringView text)
Constructs a description from the given text string.
Definition: Attributes.h:100
const StringView & getValue() const
Get the description text string.
Definition: Attributes.h:115
Adds range information to an object.
Definition: Attributes.h:38
RangeAttribute(T min, T max)
Constructs a range attribute with the given bounds.
Definition: Attributes.h:45
T getMax() const
Get the maximum value of the range.
Definition: Attributes.h:55
T getMin() const
Get the minimum value of the range.
Definition: Attributes.h:52
Tags an object as being possible to serialize.
Definition: Attributes.h:85
Adds step size information to an object.
Definition: Attributes.h:65
T getStepValue() const
Get the Step value.
Definition: Attributes.h:77
StepSizeAttribute(T value)
Constructs a step value attribute from the given value.
Definition: Attributes.h:71
Base attribute type for generic attributes.
Definition: Attributes.h:119
Base attribute type for regular attributes.
Definition: Attributes.h:104
RegularAttribute(bool runtime=true)
Construct a regular attribute. True if runtime attribute.