cimportplugin.cc
Go to the documentation of this file.
00001 #include "cimportplugin.hh"
00002 #include "typelib/pluginmanager.hh"
00003 #include "typelib/importer.hh"
00004 
00005 #include <iostream>
00006 
00007 #include "utilmm/configfile/configset.hh"
00008 #include "typelib/registry.hh"
00009 
00010 using namespace std;
00011 using namespace boost;
00012 using utilmm::config_set;
00013 using Typelib::Registry;
00014 using Typelib::PluginManager;
00015 
00016 CImportPlugin::CImportPlugin()
00017     : Plugin("C", "import") {}
00018 
00019 list<string> CImportPlugin::getOptions() const
00020 {
00021     static const char* arguments[] = 
00022     { "*:include,I=string:include search path",
00023       "*:define,D=string:Define this symbol" };
00024     return list<string>(arguments, arguments + 2);
00025 }
00026 
00027 bool CImportPlugin::apply(const OptionList& remaining, const config_set& options, Registry& registry)
00028 {
00029     if (remaining.empty())
00030     {
00031         cerr << "No file found on command line. Aborting" << endl;
00032         return false;
00033     }
00034     string const file(remaining.front());
00035 
00036     try
00037     {
00038         auto_ptr<Typelib::Importer> importer(PluginManager::self()->importer("c"));
00039         if (! importer.get())
00040         {
00041             cerr << "Cannot find the import I/O plugin for C" << std::endl;
00042             return false;
00043         }
00044                 
00045         importer->load(file, options, registry);
00046         return true;
00047     }
00048     catch(Typelib::RegistryException& e)
00049     { cerr << "error: " << e.toString() << endl; }
00050     catch(Typelib::ImportError e)
00051     { cerr << e.toString() << endl; }
00052     catch(std::exception& e)
00053     { cerr << "Error parsing file " << file << ":\n\t" << typeid(e).name() << endl; }
00054     return false;
00055 }
00056 


typelib
Author(s): Sylvain Joyeux/sylvain.joyeux@m4x.org
autogenerated on Thu Jan 2 2014 11:38:41