| 125 | |
| 126 | |
| 127 | JSON::Object::Ptr JSONConfiguration::findStart(const std::string& key, std::string& lastPart) |
| 128 | { |
| 129 | JSON::Object::Ptr currentObject = _object; |
| 130 | |
| 131 | StringTokenizer tokenizer(key, "."); |
| 132 | lastPart = tokenizer[tokenizer.count() - 1]; |
| 133 | |
| 134 | for(int i = 0; i < tokenizer.count() - 1; ++i) |
| 135 | { |
| 136 | std::vector<int> indexes; |
| 137 | std::string name = tokenizer[i]; |
| 138 | getIndexes(name, indexes); |
| 139 | |
| 140 | DynamicAny result = currentObject->get(name); |
| 141 | |
| 142 | if ( result.isEmpty() ) // Not found |
| 143 | { |
| 144 | if ( indexes.empty() ) // We want an object, create it |
| 145 | { |
| 146 | JSON::Object::Ptr newObject = new JSON::Object(); |
| 147 | currentObject->set(name, newObject); |
| 148 | currentObject = newObject; |
| 149 | } |
| 150 | else // We need an array |
| 151 | { |
| 152 | JSON::Array::Ptr newArray; |
| 153 | JSON::Array::Ptr parentArray; |
| 154 | JSON::Array::Ptr topArray; |
| 155 | for(std::vector<int>::iterator it = indexes.begin(); it != indexes.end(); ++it) |
| 156 | { |
| 157 | newArray = new JSON::Array(); |
| 158 | if ( topArray.isNull() ) |
| 159 | { |
| 160 | topArray = newArray; |
| 161 | } |
| 162 | |
| 163 | if ( ! parentArray.isNull() ) |
| 164 | { |
| 165 | parentArray->add(newArray); |
| 166 | } |
| 167 | |
| 168 | for(int i = 0; i <= *it - 1; ++i) |
| 169 | { |
| 170 | Poco::DynamicAny nullValue; |
| 171 | newArray->add(nullValue); |
| 172 | } |
| 173 | |
| 174 | parentArray = newArray; |
| 175 | } |
| 176 | |
| 177 | currentObject->set(name, topArray); |
| 178 | currentObject = new JSON::Object(); |
| 179 | newArray->add(currentObject); |
| 180 | } |
| 181 | } |
| 182 | else // We have a value |
| 183 | { |
| 184 | if ( indexes.empty() ) // We want an object |