Commit ad19da01 authored by IOhannes m zmölnig's avatar IOhannes m zmölnig
Browse files

simplified the autoregistering logic (less code in headers)

Closes: https://github.com/umlaeute/Gem/issues/205
parent 826f6453
......@@ -221,4 +221,3 @@ void CPPExtern::beforeDeletion(void)
//post("CPPExtern to be deleted");
}
struct register_class_setup *gem_register_class_setup_list = 0;
......@@ -332,11 +332,8 @@ static void obj_setupCallback(t_class *classPtr);
// (registering the class with pd)
// a static copy of this class is created at runtime, to actually do the setup-call
///////////////////////////////////////////////////////////////////////////////
struct register_class_setup {
struct register_class_setup *next;
void (*setup)(void);
};
extern struct register_class_setup *gem_register_class_setup_list;
typedef void (*t_class_setup)(void);
extern "C" { GEM_EXTERN void gem_register_class_setup(const char*name, t_class_setup); }
#ifdef NO_AUTO_REGISTER_CLASS
// if NO_AUTO_REGISTER_CLASS is defined, we will not register the class
......@@ -344,16 +341,10 @@ extern struct register_class_setup *gem_register_class_setup_list;
static int NEW_CLASS ## _dummyinstance
#else
// for debugging we can show the which classes are auto-registering
# if 0
# define POST_AUTOREGISTER(NEW_CLASS) post("auto-registering: "#NEW_CLASS)
# else
# define POST_AUTOREGISTER(NEW_CLASS)
# endif
# define AUTO_REGISTER_CLASS(NEW_CLASS) \
static struct register_class_setup NEW_CLASS ## _register = { 0, NEW_CLASS ## _setup }; \
# define AUTO_REGISTER_CLASS(NEW_CLASS) \
class NEW_CLASS ## _cppclass { \
public: \
NEW_CLASS ## _cppclass(void) {POST_AUTOREGISTER(NEW_CLASS); NEW_CLASS ## _register.next = gem_register_class_setup_list; gem_register_class_setup_list = & NEW_CLASS ## _register; } \
NEW_CLASS ## _cppclass(void) {gem_register_class_setup(#NEW_CLASS, & NEW_CLASS ## _setup); } \
}; \
static NEW_CLASS ## _cppclass NEW_CLASS ## _instance
#endif
......
......@@ -78,6 +78,23 @@ extern "C" {
#endif /* HAVE_M_IMP_H */
typedef struct class_setup_list_ {
struct class_setup_list_ *next;
const char*name;
t_class_setup setup;;
} class_setup_list_t;
static class_setup_list_t *register_class_setup_list = 0;
void gem_register_class_setup(const char*name, t_class_setup setup) {
class_setup_list_t*x = new class_setup_list_t;
x->next = register_class_setup_list;
x->setup = setup;
x->name = name;
register_class_setup_list = x;
}
namespace
{
......@@ -241,11 +258,12 @@ void setup()
verbose(-1,
"GEM: \tmailing-list https://lists.puredata.info/listinfo/gem-dev/");
struct register_class_setup *l = gem_register_class_setup_list;
while (l)
{
for(class_setup_list_t *l = register_class_setup_list; l;) {
class_setup_list_t*next = l->next;
verbose(4, "registering Gem object: %s", l->name);
l->setup();
l = l->next;
delete l;
l = next;
}
gem::Settings::init();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment