33 ListField(
const std::string& name) { setName(name); }
36 size_t size()
const {
return _values.size(); }
39 void clear() { _values.clear(); }
50 if (values != _values) {
56 std::vector<T>
getValues()
const {
return _values; }
61 if (index >= _values.size()) {
62 _values.resize(index+1);
64 _values[index] = value;
71 if ((index >= _values.size()) || (_values[index] != value)) {
72 setValueAt(index, value);
78 return _values[index];
85 if (_values.size() != 1) {
89 for (
const T& value : _values) {
95 result.append(ValuePersistence::valueToString(value));
97 if (_values.size() != 1) {
106 size_t endPos = std::min(value.find(
"]"), value.length());
108 if (endPos > 1 && value[0] ==
'[') {
110 if (!isWhitespace(value, pos, endPos)) {
111 while (pos < endPos) {
112 size_t commaPos = std::min(value.find(
",", pos), endPos);
114 ValuePersistence::stringToValue(value.substr(pos, commaPos-pos), comp);
115 _values.push_back(comp);
122 ValuePersistence::stringToValue(value, comp);
123 _values.push_back(comp);
129 static bool isWhitespace(
const std::string& s,
size_t start,
size_t end)
131 for (
size_t i = start; i < end; i++) {
132 if (!::isspace(
static_cast<int>(s[i]))) {
139 std::vector<T> _values;
Base class for all fields used in the ML.
std::vector< T > getValues() const
Returns the value of the field as a Boolean.
void setValueAt(size_t index, T value)
Sets the field value at index index to value.
void setStringValue(const std::string &value) override
Sets the value of the field to value.
std::string getStringValue() const override
Returns the value of the field as string value.
void clear()
Clear value of field.
size_t size() const
Return number of elements of this fields value.
void setValues(const std::vector< T > &values)
Sets the field value to values.
void updateValueAt(size_t index, T value)
Sets the field value at index index to value, but only touch field if the new value is different from...
ListField(const std::string &name)
Constructor, creates a list field with a name.
ListField()=default
Default constructor, do not use it.
T getValueAt(size_t index) const
Get component value at index index. index must be in range.
void updateValues(const std::vector< T > &values)
Sets the field value to values, but only touch field if the new values are different from the old val...