/* -*- C++ -*- * Copyright ©2005,2008 Hugo Mills * * This software is distributed under the terms of the GNU GPL v3 * For more information on the GPL, see the file COPYING or * visit http://www.gnu.org/ * * This software is distributed without warranty */ #include "contentgroup.h" #include "magellan/plugininfo_content.h" #include "magellan/parsertools.h" #include "magellan/options.h" std::list* ContentGroup::content_plugins; PluginInfo* ContentGroup::getmodules(int i) { if(i==0) { PluginInfo_Content* pi = new PluginInfo_Content(); pi->name = "ContentGroup"; pi->author = "Hugo Mills"; pi->copyright = "©2005,2008 Hugo Mills"; pi->version = 0x10101; pi->parser = ContentGroup::parse; return pi; } else return NULL; } Content* ContentGroup::parse( ConfigLexer* lex, const std::string& param_type, const std::string& param_subtype ) { if(param_type != "") return NULL; if(param_subtype != "") return NULL; ContentGroup* cg = new ContentGroup(); while(!lex->eos()) { std::string type, subtype; if(lex->type() != TOKEN) { // Bitch about it std::cerr << "Expected a token, but didn't get one." << std::endl; return NULL; } type = lex->value(); lex->next(); if(lex->type() != CHAR || lex->value() != "{") { // Bitch about it std::cerr << "Expected { but not found" << std::endl; return NULL; } lex->next(); if(!readkeyedvalue(lex, "type", &subtype)) subtype = ""; // Find a content plugin that wants to try { Content* res = readplugin(lex, type, subtype, content_plugins->begin(), content_plugins->end()); if(res) { if(opts->debug_parse() >= 4 || opts->debug_render() >= 2) std::cerr << " (" << type << ") created at " << res << std::endl; cg->add(res); } } catch(...) { std::cerr << "Caught error in content group" << std::endl << " at line " << lex->lineno() << " of config file" << std::endl; } } return cg; } ContentGroup::~ContentGroup() { for(std::list::iterator it = contents.begin(); it != contents.end(); it++) { (*it)->destroy(); } } void ContentGroup::plot( Output* bitmap, XfView* viewport, XfMap* projection, XfOrbit* orbit, XfSphere* sphere ) { for(std::list::iterator it = contents.begin(); it != contents.end(); ++it) { if(opts->debug_render() >= 2) { std::cerr << "Plotting from plugin " << (*it) << " = " << (*it)->name << std::endl; } (*it)->plot(bitmap, viewport, projection, orbit, sphere); } } void ContentGroup::add(Content* itm) { contents.push_back(itm); } bool ContentGroup::isbound() const { for(std::list::const_iterator it = contents.begin(); it != contents.end(); it++) { if( !(*it)->isbound() ) return false; } return true; } Plugin* ContentGroup::bind(Configuration* config) { for(std::list::iterator it = contents.begin(); it != contents.end(); it++) { if(!(*it)->isbound()) { Content* boundcontent = dynamic_cast( (*it)->bind(config) ); if( boundcontent != NULL ) *it = boundcontent; } } if(isbound()) return this; return NULL; }