00001 #include "tlbimportplugin.hh" 00002 00003 #include "typelib/importer.hh" 00004 #include "typelib/registry.hh" 00005 #include "typelib/pluginmanager.hh" 00006 00007 #include "utilmm/configfile/configset.hh" 00008 #include <iostream> 00009 00010 using namespace std; 00011 using namespace boost; 00012 using utilmm::config_set; 00013 using Typelib::Registry; 00014 using Typelib::PluginManager; 00015 using Typelib::Importer; 00016 00017 TlbImportPlugin::TlbImportPlugin() 00018 : Plugin("tlb", "import") {} 00019 00020 bool TlbImportPlugin::apply(const OptionList& remaining, const config_set& options, Registry& registry) 00021 { 00022 if (remaining.empty()) 00023 { 00024 cerr << "No file found on command line. Aborting" << endl; 00025 return false; 00026 } 00027 string const file(remaining.front()); 00028 00029 try 00030 { 00031 auto_ptr<Importer> importer(PluginManager::self()->importer("tlb")); 00032 if (! importer.get()) 00033 { 00034 cerr << "Cannot find an I/O plugin for tlb" << endl; 00035 return false; 00036 } 00037 00038 importer->load(file, options, registry); 00039 return true; 00040 } 00041 catch(Typelib::RegistryException& e) 00042 { cerr << "Error in type management: " << e.toString() << endl; } 00043 catch(Typelib::ImportError e) 00044 { cerr << e.toString() << endl; } 00045 catch(std::exception& e) 00046 { cerr << "Error parsing file " << file << ":\n\t" << typeid(e).name() << endl; } 00047 return false; 00048 } 00049