From: curt Date: Sun, 18 Mar 2001 21:22:28 +0000 (+0000) Subject: Patch to property tree to allow repeating tag names. The property manager X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=7db44c113c2cbbd05938f2d444a5d63f005d0ce4;p=simgear.git Patch to property tree to allow repeating tag names. The property manager simply assigns ordinality as it finds multiple instances. --- diff --git a/simgear/magvar/magvar.cxx b/simgear/magvar/magvar.cxx index f078aae5..ff17ae5d 100644 --- a/simgear/magvar/magvar.cxx +++ b/simgear/magvar/magvar.cxx @@ -51,6 +51,9 @@ void SGMagVar::update( double lon, double lat, double alt_m, double jd ) { double sgGetMagVar( double lon, double lat, double alt_m, double jd ) { + // cout << "lat = " << lat << " lon = " << lon << " elev = " << alt_m + // << " JD = " << jd << endl; + double field[6]; return calc_magvar( lat, lon, alt_m / 1000.0, (long)jd, field ); } diff --git a/simgear/misc/props_io.cxx b/simgear/misc/props_io.cxx index b1294937..b9ecabfc 100644 --- a/simgear/misc/props_io.cxx +++ b/simgear/misc/props_io.cxx @@ -20,6 +20,7 @@ #endif #include STL_STRING #include +#include #if !defined(FG_HAVE_NATIVE_SGI_COMPILERS) FG_USING_STD(istream); @@ -29,6 +30,7 @@ FG_USING_STD(ofstream); #endif FG_USING_STD(string); FG_USING_STD(vector); +FG_USING_STD(map); @@ -61,6 +63,7 @@ private: : node(_node), type(_type) {} SGPropertyNode * node; string type; + map counters; }; State &state () { return _state_stack[_state_stack.size() - 1]; } @@ -104,6 +107,8 @@ PropsVisitor::endXML () void PropsVisitor::startElement (const char * name, const XMLAttributes &atts) { + State &st = state(); + if (_level == 0) { push_state(_root, ""); } @@ -111,9 +116,14 @@ PropsVisitor::startElement (const char * name, const XMLAttributes &atts) else { const char * att_n = atts.getValue("n"); int index = 0; - if (att_n != 0) + if (att_n != 0) { index = atoi(att_n); - push_state(state().node->getChild(name, index, true), + st.counters[name] = max(st.counters[name], index+1); + } else { + index = st.counters[name]; + st.counters[name]++; + } + push_state(st.node->getChild(name, index, true), atts.getValue("type")); } } @@ -232,6 +242,9 @@ getTypeName (SGValue::Type type) case SGValue::STRING: return "string"; } + + // keep the compiler from squawking + return "unknown"; } @@ -241,7 +254,7 @@ getTypeName (SGValue::Type type) static void writeData (ostream &output, const string &data) { - for (int i = 0; i < data.size(); i++) { + for (int i = 0; i < (int)data.size(); i++) { switch (data[i]) { case '&': output << "&";