fixed array element updating problem in JSONConfiguration

This commit is contained in:
Kontinuation 2014-05-23 02:20:55 +08:00
parent 0a46d7c7ac
commit 3880f76d82
2 changed files with 11 additions and 1 deletions

View File

@ -154,6 +154,9 @@ public:
void add(const Dynamic::Var& value); void add(const Dynamic::Var& value);
/// Add the given value to the array /// Add the given value to the array
void set(unsigned int index, const Dynamic::Var &value);
/// Update the element on the given index to specified value
void stringify(std::ostream& out, unsigned int indent = 0, int step = -1) const; void stringify(std::ostream& out, unsigned int indent = 0, int step = -1) const;
/// Prints the array to out. When indent has zero value, /// Prints the array to out. When indent has zero value,
/// the array will be printed without newline breaks and spaces between elements. /// the array will be printed without newline breaks and spaces between elements.
@ -221,6 +224,13 @@ inline void Array::add(const Dynamic::Var& value)
} }
inline void Array::set(unsigned int index, const Dynamic::Var &value)
{
if (index >= _values.size()) _values.resize(index + 1);
_values[index] = value;
}
inline void Array::remove(unsigned int index) inline void Array::remove(unsigned int index)
{ {
_values.erase(_values.begin() + index); _values.erase(_values.begin() + index);

View File

@ -295,7 +295,7 @@ void JSONConfiguration::setValue(const std::string& key, const Poco::DynamicAny&
} }
arr = nextArray; arr = nextArray;
} }
arr->add(value); arr->set(indexes.back(), value);
} }
if (eventsEnabled()) if (eventsEnabled())