plugin.h
Ir a la documentación de este archivo.
1 //plugin.h
2 //----------------------------------------------------------------------
3 /*
4  * Fco. Javier Bohórquez Ogalla
5  * 75766599-E
6  * Puerto Real (Cádiz)
7  * powersgame@gmail.com
8  */
9 //----------------------------------------------------------------------
10 /*
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24  * MA 02110-1301, USA.
25  */
26 //----------------------------------------------------------------------
27 #ifndef _PLUGIN_
28 #define _PLUGIN_
29 #include <vector>
30 #include "error.h"
31 //~ #include "run/runTree.h"
32 #include "run/tree/typeNode.h"
33 using namespace std;
34 //----------------------------------------------------------------------
51 //----------------------------------------------------------------------
52 class PluginsLoader;
53 //----------------------------------------------------------------------
61 class PluginLoader {
62  void* m_libHandler;
63 
64  public:
65  PluginLoader () : m_libHandler(NULL) {}
66 
67  bool load (const char* name, PluginsLoader* pls);
68  void unload ();
69 };
70 //----------------------------------------------------------------------
79  map<string, runNode*(*)(listNode*)> creates;
80  static PluginsLoader* singleton;
81  PluginsLoader ();
82  vector<PluginLoader*> libs;
83  public:
84  static PluginsLoader* getPluginsLoader () {
85  if (!singleton)
86  singleton = new PluginsLoader();
87  return singleton;
88  }
89  void add (string key,runNode*(*val)(listNode*)) {
90  creates[key] = val;
91  }
92  void addPlugin (PluginLoader* plugin) {
93  libs.push_back (plugin);
94  }
95  void print () {
96  map<string, runNode*(*)(listNode*)>::iterator ini = creates.begin();
97  for (; ini != creates.end(); ini++){
98  cerr << ini->first << endl;
99  }
100  }
101  runNode *get (string key, listNode *list) {
102  if (creates.find(key) != creates.end()) {
103  runNode*(*func)(listNode*) = creates [key];
104  return (*func)(list);
105  } else {
106  return NULL;
107  }
108  return NULL;
109  }
110 };
111 //----------------------------------------------------------------------
119 class pluginNode : public nexpNode {
120  public:
121  static runNode *create (listNode* list) {}
122 };
123 //----------------------------------------------------------------------
124 
125 //----------------------------------------------------------------------
131 class loadNode : public logicNode {
132  public:
133  loadNode (runNode* module);
134  void run();
135  private:
136  runNode *module_;
137 };
138 //----------------------------------------------------------------------
139 class extensionNode {
140  public:
141  extensionNode (listNode* list = NULL) : list_(list) {}
142  vector<runNode*> getParams (bool require = true) {
143  if (!list_ && require)
144  throw errorException("Wrong number parameters", "extensionNode: some param is require", ERROR_PARAMS);
145  list_->run();
146  return list_->listvalue ();
147  }
148  private:
149  listNode* list_;
150 };
151 //----------------------------------------------------------------------
152 extern PluginsLoader *libs;
153 #endif
Nodo lista de elementos.
Definition: typeNode.h:294
Nodos lógicos.
Definition: expNode.h:279
Nodo ejecutable.
Definition: runTree.h:123
Cargador de módulo dinámico.
Definition: plugin.h:61
Nodo dinámico.
Definition: plugin.h:119
Cargador de módulos dinámicos.
Definition: plugin.h:78
Nodo carga librería dinámica.
Definition: plugin.h:131
Nodos de tipos de datos básicos.
Nodo expresión de tipo no definido.
Definition: expNode.h:164