示例#1
0
// Finds the track named \a searchTrack in the music library \a library. Throws XmlTree::ChildNotFoundExc() if none is found.
const XmlTree& findTrackNamed( const XmlTree &library, const std::string &searchTrack )
{
	for( XmlTree::ConstIter trackIter = library.begin("album/track"); trackIter != library.end(); ++trackIter ) {
		if( trackIter->getValue() == searchTrack )
			return *trackIter;
	}
	
	// failed to find a track named 'searchTrack'
	throw XmlTree::ExcChildNotFound( library, searchTrack );
}
示例#2
0
void FlickrTestApp::setup()
{
	glEnable( GL_TEXTURE_2D );

	const XmlTree xml( loadUrl( Url( "http://api.flickr.com/services/feeds/groups_pool.gne?id=1423039@N24&lang=en-us&format=rss_200" ) ) );
	for( XmlTree::ConstIter item = xml.begin( "rss/channel/item" ); item != xml.end(); ++item ) {
		mUrls.push_back( item->getChild( "media:content" ).getAttributeValue<Url>( "url" ) );
	}

	createTextureFromURL();
	lastTime = getElapsedSeconds();
	activeTex = 0;
}
示例#3
0
WarpList Warp::readSettings( const DataSourceRef &source )
{
	XmlTree  doc;
	WarpList warps;

	// try to load the specified xml file
	try {
		doc = XmlTree( source );
	}
	catch( ... ) {
		return warps;
	}

	// check if this is a valid file
	bool isWarp = doc.hasChild( "warpconfig" );
	if( !isWarp ) return warps;

	//
	if( isWarp ) {
		// get first profile
		XmlTree profileXml = doc.getChild( "warpconfig/profile" );

		// iterate maps
		for( XmlTree::ConstIter child = profileXml.begin( "map" ); child != profileXml.end(); ++child ) {
			XmlTree warpXml = child->getChild( "warp" );

			// create warp of the correct type
			std::string method = warpXml.getAttributeValue<std::string>( "method", "unknown" );
			if( method == "bilinear" ) {
				WarpBilinearRef warp( new WarpBilinear() );
				warp->fromXml( warpXml );
				warps.push_back( warp );
			}
			else if( method == "perspective" ) {
				WarpPerspectiveRef warp( new WarpPerspective() );
				warp->fromXml( warpXml );
				warps.push_back( warp );
			}
			else if( method == "perspectivebilinear" ) {
				WarpPerspectiveBilinearRef warp( new WarpPerspectiveBilinear() );
				warp->fromXml( warpXml );
				warps.push_back( warp );
			}
		}
	}

	return warps;
}
void EarthquakeApp::parseEarthquakes( const string &url )
{
	const XmlTree xml( loadUrl( Url( url ) ) );
	for( XmlTree::ConstIter itemIter = xml.begin( "feed/entry" ); itemIter != xml.end(); ++itemIter ) {
		string titleLine( itemIter->getChild( "title" ).getValue() );
		size_t firstComma = titleLine.find( ',' );
		float magnitude = fromString<float>( titleLine.substr( titleLine.find( ' ' ) + 1, firstComma - 2 ) );
		string title = titleLine.substr( firstComma + 2 );

		istringstream locationString( itemIter->getChild( "georss:point" ).getValue() );
		Vec2f locationVector;
		locationString >> locationVector.x >> locationVector.y;
		
		mEarth.addQuake( locationVector.x, locationVector.y, magnitude, title );		
	}
	console() << xml << std::endl;
	
	//mEarth.addQuake( 37.7f, -122.0f, 8.6f, "San Francisco" );
}
示例#5
0
void ConfigDict::loadXML(DataSourceRef source)
{
	XmlTree doc;
	try {
		doc = XmlTree(source);	
	} catch(rapidxml::parse_error &e) {
		LOG_ERROR("ConfigDict::loadXML - couldnt parse XML data ("<< 
				  "error: "<< e.what() <<" "<<
				  "file: "<< source->getFilePathHint() <<
				  ")");
	}
	
	XmlTree root = *doc.begin();
	
	for(XmlTree::ConstIter setting = root.begin(); setting != root.end(); ++setting) 
	{
		string key = setting->getTag();
		string value = setting->getValue();
		settings.insert(std::pair<string,string>(key, value) );
	}
}
示例#6
0
void XMLTestApp::setup()
{
	XmlTree doc( loadFile( getAssetPath( "library.xml" ) ) );
	XmlTree musicLibrary( doc.getChild( "library" ) );
	for( XmlTree::ConstIter item = doc.begin("library/album"); item != doc.end(); ++item ) {
		console() << "Node: " << item->getTag() << " Value: " << item->getValue() << endl;
	}

	for( XmlTree::ConstIter track = doc.begin("library/album/track"); track != doc.end(); ++track )
		console() << track->getValue() << endl;

	assert( (musicLibrary / "album")["musician"] == "John Coltrane" );

	// test that /one/two is equivalent to one/two
	vector<string> noLeadingSeparator, leadingSeparator;
	for( XmlTree::ConstIter track = doc.begin("library/album/track"); track != doc.end(); ++track )
		noLeadingSeparator.push_back( track->getValue() );
	for( XmlTree::ConstIter track = doc.begin("/library/album/track"); track != doc.end(); ++track )
		leadingSeparator.push_back( track->getValue() );
	assert( noLeadingSeparator == leadingSeparator );

	XmlTree firstAlbum = doc.getChild( "library/album" );
	for( XmlTree::Iter child = firstAlbum.begin(); child != firstAlbum.end(); ++child ) {
		console() << "Tag: " << child->getTag() << "  Value: " << child->getValue() << endl;
	}
	console() << doc.getChild( "library/owner/city" );
	XmlTree ownerCity = doc.getChild( "///library/////owner/city" );
	console() << "Path: " << ownerCity.getPath() << "  Value: " << ownerCity.getValue() << std::endl;
	console() << doc;
	
	console() << findTrackNamed( doc.getChild( "library" ), "Wolf" );
	
	// Whoops - assignment by value doesn't modifying the original XmlTree
	XmlTree firstTrackCopy = doc.getChild( "/library/album/track" );
	firstTrackCopy.setValue( "Replacement name" );
	console() << doc.getChild( "/library/album/track" ) << std::endl;

	XmlTree &firstTrackRef = doc.getChild( "/library/album/track" );
	firstTrackRef.setValue( "Replacement name" );
	console() << doc.getChild( "/library/album/track" ) << std::endl;

	XmlTree albumCopy = copyFirstAlbum( doc / "library" );
	console() << ( albumCopy / "track" ).getPath() << std::endl; // should print 'newRoot/track'

	// This code only works in VC2010
/*	std::for_each( doc.begin( "library/album" ), doc.end(), []( const XmlTree &child ) {
		app::console() << child.getChild( "title" ).getValue() << std::endl;
	} );*/
}
示例#7
0
void CanvasComponent::initFromXml(const XmlTree& xml, bool createNodes)
{
    id = xml.getAttributeValue<int>("id");
    // when loading a patch, update globalID so future
    // nodes will be created with a unique id
    if (globalComponentID <= id) {
        // increment global id so each component will have a unique id
        globalComponentID = id+1;
    }
    
    setName(xml.getAttributeValue<std::string>("name"));
    Vec2f pos = Vec2f(xml.getAttributeValue<float>("position.x"), xml.getAttributeValue<float>("position.y"));
    Vec2f size = Vec2f(xml.getAttributeValue<float>("size.x"), xml.getAttributeValue<float>("size.y"));
    canvasRect = Rectf(pos, pos+size);
    
    setSize(size);
    
    showInputPlus = xml.getAttributeValue<bool>("showInputPlus");
    showOutputPlus = xml.getAttributeValue<bool>("showOutputPlus");
    
    if (createNodes)
    {
        // add inputs and outputs
        XmlTree inputNodesTree = xml.getChild("InputNodes");
        for(XmlTree::ConstIter iter = inputNodesTree.begin(); iter != inputNodesTree.end(); ++iter)
        {
            if (iter->getTag() == "Node") {
                addInputNodeFromXml(iter->getChild(""));
            }
        }
        XmlTree outputNodesTree = xml.getChild("OutputNodes");
        for(XmlTree::ConstIter iter = outputNodesTree.begin(); iter != outputNodesTree.end(); ++iter)
        {
            if (iter->getTag() == "Node") {
                addOutputNodeFromXml(iter->getChild(""));
            }
        }
    }
}