// Note, for brevity purposes the notification logic was stripped
template<class T, const String &Name>
class Property
{
private:
T mValue;
public:
Property () {}
Property (const T &value) { mValue = value; }
Property (const Property<T, Name> &value) { *this = value; }
virtual ~Property () {}
virtual T & operator = (const T &value) { mValue = value; return mValue; }
virtual Property<T, Name> & operator = (const Property<T, Name> &value) { mValue = value.mValue; return *this; }
operator T () const { return mValue; }
const String &GetName () const { return Name; }
};
// Example code using the above property class
extern const String MyPropertyName = "MyProperty";
int main (int argc, char **argv)
{
Property<int, MyPropertyName> MyProperty;
MyProperty = 100;
printf("%d\n", (int)MyProperty);
return 0;
}
As you can see, a simple class with a template type can sufficiently handle properties; however I also need to include the property name with the property object. As you can see I am using a non-type template parameter to pass in the property name. I thought about passing the name as a parameter in the constructor, but it would add an extra step. I'm trying to minimize the amount of boilerplate coding, but at the same time I don't want to sway towards "bad programming" practices. I never had a need to use non-type template parameters before and so I'm cautious about swaying in that direction. I'd like to hear your feedback on this and whether or not you think it could be done better / differently, but still try to minimize bloat. When you have to create hundreds of properties and deal with bindings, it can become a maintenance nightmare.












