Go to the documentation of this file.00001 #include "genom.hh"
00002
00003 #include <iostream>
00004
00005 #include "genommodule.hh"
00006 #include "preprocess.hh"
00007
00008 #include "configset.hh"
00009
00010 #include <boost/tokenizer.hpp>
00011
00012 using namespace std;
00013 using namespace boost;
00014 using Typelib::Registry;
00015
00016 GenomPlugin::GenomPlugin()
00017 : Plugin("genom", "import") {}
00018
00019 list<string> GenomPlugin::getOptions() const
00020 {
00021 static const char* arguments[] =
00022 { ":include,I=string:include search path" };
00023 return list<string>(arguments, arguments + 1);
00024 }
00025
00026 bool GenomPlugin::apply(const OptionList& remaining, const ConfigSet& options, Registry* registry)
00027 {
00028 if (remaining.empty())
00029 {
00030 cerr << "No file found on command line. Aborting" << endl;
00031 return false;
00032 }
00033
00034 list<string> cppargs;
00035
00036 string includes = options.getString("include");
00037 if (! includes.empty())
00038 {
00039
00040
00041 typedef tokenizer< char_separator<char> > Splitter;
00042 Splitter splitter(includes, char_separator<char> (":"));
00043 for (Splitter::const_iterator it = splitter.begin(); it != splitter.end(); ++it)
00044 cppargs.push_back("-I" + *it);
00045 }
00046
00047 string file = remaining.front();
00048 string i_file = preprocess(file, cppargs);
00049 if (i_file.empty())
00050 {
00051 cerr << "Could not preprocess " << file << ", aborting" << endl;
00052 return false;
00053 }
00054
00055
00056 try
00057 {
00058 GenomModule reader(registry);
00059 int old_count = registry -> getCount();
00060
00061 reader.read(i_file);
00062 cout << "Found " << registry -> getCount() - old_count << " types in " << file << endl;
00063 return true;
00064 }
00065 catch(Typelib::RegistryException& e)
00066 {
00067 cerr << "Error in type management: " << e.toString() << endl;
00068 return false;
00069 }
00070 catch(std::exception& e)
00071 {
00072 cerr << "Error parsing file " << file << ":\n\t"
00073 << typeid(e).name() << endl;
00074 return false;
00075 }
00076 }
00077