33 #ifndef __xmm_lib__attribute__
34 #define __xmm_lib__attribute__
40 #include <boost/any.hpp>
45 #pragma mark === Functions checkLimits ===
55 void checkLimits(T
const& value,
59 throw std::runtime_error(
"Attribute limits are not implemented for the current type.");
63 void checkLimits<std::size_t>(std::size_t
const& value,
64 std::size_t
const& limit_min,
65 std::size_t
const& limit_max);
68 void checkLimits<unsigned char>(
unsigned char const& value,
69 unsigned char const& limit_min,
70 unsigned char const& limit_max);
73 void checkLimits<char>(
char const& value,
74 char const& limit_min,
75 char const& limit_max);
78 void checkLimits<unsigned int>(
unsigned int const& value,
79 unsigned int const& limit_min,
80 unsigned int const& limit_max);
83 void checkLimits<int>(
int const& value,
85 int const& limit_max);
88 void checkLimits<long>(
long const& value,
89 long const& limit_min,
90 long const& limit_max);
93 void checkLimits<float>(
float const& value,
94 float const& limit_min,
95 float const& limit_max);
98 void checkLimits<double>(
double const& value,
99 double const& limit_min,
100 double const& limit_max);
103 #pragma mark === Class AttributeBase ===
107 class AttributeBase {
112 AttributeBase() : changed(false)
122 #pragma mark === Class AttributeHandler ===
126 class AttributeHandler {
127 template <
typename T>
friend class Attribute;
133 virtual ~AttributeHandler() {}
139 virtual void onAttributeChange(AttributeBase* attr_pointer) = 0;
144 #pragma mark === Class Attribute ===
149 template <
typename T>
161 T
const& limit_min=default_limit_min(),
162 T
const& limit_max=default_limit_max()) :
163 limit_min_(limit_min),
164 limit_max_(limit_max),
178 limit_min_(src.limit_min_),
179 limit_max_(src.limit_max_),
196 limit_min_ = src.limit_min_;
197 limit_max_ = src.limit_max_;
198 parent_ = src.parent_;
217 void set(T
const& value,
bool silently =
false)
219 checkLimits(value, limit_min_, limit_max_);
222 if (!silently && parent_)
223 parent_->onAttributeChange(
this);
250 limit_min_ = limit_min;
259 limit_max_ = limit_max;
268 T
const& limit_max=default_limit_max())
298 static T default_limit_min() {
return std::numeric_limits<T>::lowest(); }
303 static T default_limit_max() {
return std::numeric_limits<T>::max(); }
323 AttributeHandler *parent_;
virtual ~Attribute()
Destructor.
Definition: attribute.hpp:207
AttributeHandler * get_parent() const
get the parent to receive change notifications
Definition: attribute.hpp:287
void set_parent(AttributeHandler *parent)
set the parent to receive change notifications
Definition: attribute.hpp:278
T getCopy() const
get a copy of the attribute's current value
Definition: attribute.hpp:239
Attribute & operator=(Attribute< U > const &src)
Assignment operator.
Definition: attribute.hpp:192
Definition: attribute.hpp:42
void set_limit_max(T const &limit_max=default_limit_max())
set the attribute's maximum value
Definition: attribute.hpp:257
Attribute(AttributeHandler *parent=nullptr, T const &value=T(), T const &limit_min=default_limit_min(), T const &limit_max=default_limit_max())
Default Constructor.
Definition: attribute.hpp:159
void set_limit_min(T const &limit_min=default_limit_min())
set the attribute's minimum value
Definition: attribute.hpp:248
Attribute(Attribute const &src)
Copy Constructor.
Definition: attribute.hpp:176
void set(T const &value, bool silently=false)
Set the attribute value.
Definition: attribute.hpp:217
Generic Attribute.
Definition: attribute.hpp:150
void set_limits(T const &limit_min=default_limit_min(), T const &limit_max=default_limit_max())
set the attribute's limit values
Definition: attribute.hpp:267