[gdome]Re: [Re: [gtkmm] libxml v. Xerces-C ]



In message <20010613204851 8762 qmail www0q netaddress usa net>you write:
>Paul Davis <pbd Op Net> wrote:
>> whats wrong with libxml++, which wraps libxml2 ?
>
>Can you show me some example code?

In the code below, I typically iterate over PropertyLists because we
discovered a hard-to-generate bug in which the associative form:

	   prop = node->property ("property-name");

sometimes seemed to fail. It works 99% of the time, and somebody
should discover whats wrong with it.

My only other complaint is that I would prefer

namespace XML {
	  ...
};

to "XMLFoo", but its a minor quibble. The library has been working
very well for me so far, and I like it almost 100%.

--p

XMLNode *
Session::get_state()
{
	XMLNode *node = new XMLNode("Session");
	XMLNode *child;
	DiskStream *ds;
	GList *dlist;
	char buf[32];

	/* store configuration settings */

	child = node->add_child ("Options");
	
	child->add_property ("recording-plugins", recording_plugins?"yes":"no");
	child->add_property ("send-midi-timecode", send_midi_timecode?"yes":"no");
	g_snprintf (buf, sizeof(buf)-1, "%d", max_level);
	child->add_property ("max-level", buf);
	g_snprintf (buf, sizeof(buf)-1, "%d", min_level);
	child->add_property ("min-level", buf);
	g_snprintf (buf, sizeof(buf)-1, "%f", meter_hold);
	child->add_property ("meter-hold", buf);
	g_snprintf (buf, sizeof(buf)-1, "%d", over_length_long);
	child->add_property ("long-over-length", buf);
	g_snprintf (buf, sizeof(buf)-1, "%d", over_length_short);
	child->add_property ("short-over-length", buf);
	g_snprintf (buf, sizeof(buf)-1, "%f", shuttle_speed_factor);
	child->add_property ("shuttle-speed-factor", buf);
	g_snprintf (buf, sizeof(buf)-1, "%f", shuttle_speed_threshold);
	child->add_property ("shuttle-speed-threshold", buf);
	g_snprintf (buf, sizeof(buf)-1, "%f", rf_speed);
	child->add_property ("rf-speed", buf);
	g_snprintf (buf, sizeof(buf)-1, "%f", smpte_frames_per_second);
	child->add_property ("smpte-frames-per-second", buf);

	if (click_sound.length()) {
		child->add_property ("click-sound", click_sound);
	}
	if (click_emphasis_sound.length()) {
		child->add_property ("click-emphasis-sound", click_emphasis_sound);
	}

	child = node->add_child ("DiskStreams");

	for (dlist = diskstreams; dlist; dlist = g_list_next (dlist)) {
		ds = (DiskStream *) dlist->data;
		child->add_child (ds->get_state());
	}

	node->add_child (_locations.get_state());

	for (RouteList::iterator i = routes.begin(); i != routes.end(); i++) {
		node->add_child((*i)->get_state());
	}
	
	return node;
}

int
Session::set_state(const XMLNode *node)
{
	XMLNodeList nlist;
	XMLNodeConstIterator niter;
	XMLNode *child;

	if (node->name() != "Session-State" && node->name() != "Session"){
		error << "Bad node sent to Session::set_state()" << endmsg;
		return -1;
	}
		
	nlist = node->children();

	for (niter = nlist.begin(); niter != nlist.end(); niter++) {

		child = *niter;
			
		if (child->name() == "Route-State" || child->name() == "Route") {
			Route *mx;

			try {
				mx = new Route (*this, child);
			}

			catch (failed_constructor& err) {
				error << "Session: could not create Route from state"
				      << endmsg;
				return -1;
			}

			add_route (mx);

		} else if (child->name() == "Locations") {
			_locations.set_state (child);
		} else if (child->name() == "DiskStreams") {
				/* handled elsewhere */
		} else if (child->name() == "Options") {
			
			XMLPropertyList plist;
			XMLPropertyConstIterator piter;
			XMLProperty *prop;
			
			plist = child->properties();
			for (piter = plist.begin(); piter != plist.end(); piter++) {

				prop = *piter;

				if (prop->name() == "recording-plugins") {
					recording_plugins = (prop->value() == "yes");
				} else if (prop->name() == "send-midi-timecode") {
					send_midi_timecode = (prop->value() == "yes");
				} else if (prop->name() == "max-level") {
					max_level = atoi (prop->value().c_str());
				} else if (prop->name() == "min-level") {
					min_level = atoi (prop->value().c_str());
				} else if (prop->name() == "meter-hold") {
					meter_hold = atof (prop->value().c_str());
				} else if (prop->name() == "long-over-length") {
					over_length_long = atoi (prop->value().c_str());
				} else if (prop->name() == "short-over-length") {
					over_length_short = atoi (prop->value().c_str());
				} else if (prop->name() == "shuttle-speed-factor") {
					shuttle_speed_factor = atof (prop->value().c_str());
				} else if (prop->name() == "shuttle-speed-threshold") {
					shuttle_speed_threshold = atof (prop->value().c_str());
				} else if (prop->name() == "rf-speed") {
					rf_speed = atof (prop->value().c_str());
				} else if (prop->name() == "smpte-frames-per-second") {
					smpte_frames_per_second = atof (prop->value().c_str());
				} else if (prop->name() == "click-sound") {
					click_sound = prop->value();
				} else if (prop->name() == "click-emphasis-sound") {
					click_emphasis_sound = prop->value();
				} else {
					warning << "new/old session option \""
						<< prop->name()
						<< "\" found in state; ignored"
						<< endmsg;
				}
			}

		} else {
			warning << "unknown XML node \""
				<< child->name()
				<< "\" in Session-State (ignored)"
				<< endmsg;
		}
	}

	return 0;
}




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]