| 159 | } |
| 160 | |
| 161 | static SDObject *XML2Config(pugi::xml_node &obj) |
| 162 | { |
| 163 | SDObject *ret = |
| 164 | new SDObject(rdcstr(obj.name()), obj.attribute("type") ? "setting"_lit : "category"_lit); |
| 165 | |
| 166 | if(ret->type.name == "category"_lit) |
| 167 | { |
| 168 | uint32_t i = 0; |
| 169 | for(pugi::xml_node child = obj.first_child(); child; child = child.next_sibling()) |
| 170 | { |
| 171 | if(child.type() == pugi::node_comment) |
| 172 | continue; |
| 173 | |
| 174 | SDObject *childObj = XML2Config(child); |
| 175 | if(childObj) |
| 176 | { |
| 177 | ret->AddAndOwnChild(childObj); |
| 178 | } |
| 179 | else |
| 180 | { |
| 181 | RDCERR("Error converting child %u config option '%s'", i, ret->name.c_str()); |
| 182 | delete ret; |
| 183 | return NULL; |
| 184 | } |
| 185 | |
| 186 | i++; |
| 187 | } |
| 188 | } |
| 189 | else |
| 190 | { |
| 191 | pugi::xml_node value = obj.first_child(); |
| 192 | rdcstr description = obj.previous_sibling().value(); |
| 193 | description.trim(); |
| 194 | |
| 195 | ret->AddAndOwnChild(makeSDObject("description"_lit, description)); |
| 196 | |
| 197 | SDObject *valueObj = NULL; |
| 198 | |
| 199 | SDBasic type = getType(obj.attribute("type").as_string()); |
| 200 | |
| 201 | if(type == SDBasic::Array) |
| 202 | { |
| 203 | type = getType(obj.attribute("elemtype").as_string()); |
| 204 | valueObj = makeSDArray("value"_lit); |
| 205 | |
| 206 | uint32_t i = 0; |
| 207 | for(pugi::xml_node el = value; el; el = el.next_sibling()) |
| 208 | { |
| 209 | SDObject *childObj = makeSDObject("$el"_lit, type, el); |
| 210 | |
| 211 | if(childObj) |
| 212 | { |
| 213 | valueObj->AddAndOwnChild(childObj); |
| 214 | } |
| 215 | else |
| 216 | { |
| 217 | RDCERR("Error converting array value %u in config option '%s'", i, ret->name.c_str()); |
| 218 | delete valueObj; |
no test coverage detected