plugin.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00026 #include "common.hpp"
00027 #include "plugin.hpp"
00028
00029 using namespace std;
00030
00031 namespace swarm {
00032
00033 typedef map<string,plugin*> plugins_map_t;
00034
00035
00036 plugins_map_t& plugins_map() {
00037 static plugins_map_t pmap;
00038 return pmap;
00039 }
00040
00041 void plugin::add(plugin* p){
00042 plugins_map()[p->id()] = p;
00043 }
00044
00045 plugin* plugin::find(const std::string& name){
00046 plugin* p = plugins_map()[name];
00047 if(p==0)
00048 throw plugin_not_found(name);
00049 return p;
00050 }
00051 void* plugin::instance(const std::string& name,const config& cfg){
00052 return plugin::find(name)->create(cfg);
00053 }
00054
00055 vector<plugin*> plugin::all() {
00056 vector<plugin*> v;
00057 for(plugins_map_t::iterator i = plugins_map().begin(); i != plugins_map().end(); i++) {
00058 v.push_back(i->second);
00059 }
00060 return v;
00061 }
00062
00063
00064 plugin::help_t plugin::help;
00065
00066 ostream& operator << (ostream& out, const plugin::help_t&){
00067 vector<plugin*> ps = plugin::all();
00068 out << "Found " << ps.size() << " plugins " << endl;
00069 for(int i = 0; i < ps.size(); i++){
00070 out << ps[i]->id() << "\t" << ps[i]->description() << endl;
00071 }
00072 return out;
00073 }
00074
00075 }