4 #include "AttributeModifier.h"
17 template<
unsigned int N>
20 int current_value = 0;
21 std::array<kstl::string, N> value_list;
34 template<
int notificationLevel,
unsigned int nbElements>
35 class maEnumHeritage :
public CoreModifiableAttributeData<maEnumValue<nbElements>>
37 template<
int notiflevel>
46 maEnumHeritage(
CoreModifiable& owner,
bool isInitAttribute, KigsID ID, kstl::string val0, kstl::string val1, kstl::string val2 =
"", kstl::string val3 =
"", kstl::string val4 =
"", kstl::string val5 =
"", kstl::string val6 =
"", kstl::string val7 =
"", kstl::string val8 =
"", kstl::string val9 =
"")
47 : CoreModifiableAttributeData<maEnumValue<nbElements>>(owner, isInitAttribute, ID)
51 if (nbElements>0) mValue.value_list[0] = std::move(val0);
52 if (nbElements>1) mValue.value_list[1] = std::move(val1);
53 if (nbElements>2) mValue.value_list[2] = std::move(val2);
54 if (nbElements>3) mValue.value_list[3] = std::move(val3);
55 if (nbElements>4) mValue.value_list[4] = std::move(val4);
56 if (nbElements>5) mValue.value_list[5] = std::move(val5);
57 if (nbElements>6) mValue.value_list[6] = std::move(val6);
58 if (nbElements>7) mValue.value_list[7] = std::move(val7);
59 if (nbElements>8) mValue.value_list[8] = std::move(val8);
60 if (nbElements>9) mValue.value_list[9] = std::move(val9);
61 mValue.current_value = 0;
64 kstl::vector<kstl::string> getEnumElements()
const override {
return {mValue.value_list.data(), mValue.value_list.data() + nbElements }; }
68 if (CoreModifiableAttributeData<maEnumValue<nbElements>>::CopyAttribute(attribute))
return true;
70 if (attribute.getValue(val))
72 if (val >= 0 && val < nbElements)
74 mValue.current_value = val;
82 kstl::string& operator[](
unsigned int index) { KIGS_ASSERT(index < nbElements);
return mValue.value_list[index]; }
83 const kstl::string& operator[](
unsigned int index)
const { KIGS_ASSERT(index < nbElements);
return mValue.value_list[index]; }
87 operator int() {
int val = 0; getValue(val);
return val; }
88 operator const kstl::string&()
const
90 int val; getValue(val);
91 return mValue.value_list[val];
95 #define IMPLEMENT_SET_VALUE_ENUM(type)\
96 virtual bool setValue(type value) override { if (this->isReadOnly()) { return false; } unsigned int tmpValue = (unsigned int)value; CALL_SETMODIFIER(notificationLevel, tmpValue); if (tmpValue < nbElements) { mValue.current_value = tmpValue; DO_NOTIFICATION(notificationLevel); return true; } return false; }
98 EXPAND_MACRO_FOR_NUMERIC_TYPES(NOQUALIFIER, NOQUALIFIER, IMPLEMENT_SET_VALUE_ENUM);
100 #define IMPLEMENT_GET_VALUE_ENUM(type)\
101 virtual bool getValue(type value) const override { unsigned int tmpValue=mValue.current_value; CALL_GETMODIFIER(notificationLevel, tmpValue); if(tmpValue<nbElements){ value = (type)tmpValue; return true;} return false; }
103 EXPAND_MACRO_FOR_NUMERIC_TYPES(NOQUALIFIER, &, IMPLEMENT_GET_VALUE_ENUM);
106 #undef IMPLEMENT_SET_VALUE_ENUM
107 #undef IMPLEMENT_GET_VALUE_ENUM
109 virtual bool setValue(
const kstl::string& value)
override
113 for (i = 0; i<nbElements; i++)
115 if (mValue.value_list[i] == value)
117 CALL_SETMODIFIER(notificationLevel, i);
120 mValue.current_value = i;
121 DO_NOTIFICATION(notificationLevel);
130 virtual bool getValue(kstl::string& value)
const override
132 unsigned int tmpValue = mValue.current_value;
133 CALL_GETMODIFIER(notificationLevel, tmpValue);
134 if (tmpValue < nbElements)
136 value = mValue.value_list[tmpValue];
141 virtual bool setValue(
const char* value)
override
143 kstl::string localstr(value);
144 return setValue(localstr);
151 template<
unsigned int nbElements>