diff --git a/MetaObjectRegistry.cpp b/MetaObjectRegistry.cpp new file mode 100644 index 0000000..01f7b0e --- /dev/null +++ b/MetaObjectRegistry.cpp @@ -0,0 +1,32 @@ +/* + * MetaObjectRegistry.cpp + * + * (c) 2016 Sofian Audry -- info(@)sofianaudry(.)com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "MetaObjectRegistry.h" + +MetaObjectRegistry& MetaObjectRegistry::instance() +{ + static MetaObjectRegistry inst; + return inst; +} + +const QMetaObject* MetaObjectRegistry::getMetaObject(QString className) const +{ + QMap::const_iterator it = metaObjectLookup.find(className); + return (it == metaObjectLookup.constEnd() ? 0 : *it); +} diff --git a/MetaObjectRegistry.h b/MetaObjectRegistry.h new file mode 100644 index 0000000..47d6c8c --- /dev/null +++ b/MetaObjectRegistry.h @@ -0,0 +1,53 @@ +/* + * MetaObjectRegistry.h + * + * (c) 2016 Sofian Audry -- info(@)sofianaudry(.)com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef METAOBJECTREGISTRY_H_ +#define METAOBJECTREGISTRY_H_ + +#include +#include +#include + +class MetaObjectRegistry { +private: + QList metaObjectList; + QMap metaObjectLookup; + +public: + MetaObjectRegistry() {} + virtual ~MetaObjectRegistry() {} + + template void add() + { + // Q_UNUSED(obj); + const QMetaObject* metaObj = &T::staticMetaObject; + if (!metaObjectList.contains(metaObj)) + { + metaObjectList << metaObj; + metaObjectLookup[metaObj->className()] = metaObj; + } + } + + const QMetaObject* getMetaObject(QString className) const; + + static MetaObjectRegistry& instance(); + +}; + +#endif /* METAOBJECTREGISTRY_H_ */ diff --git a/mapmap.pro b/mapmap.pro index 244e8fe..b1adb72 100644 --- a/mapmap.pro +++ b/mapmap.pro @@ -19,6 +19,7 @@ HEADERS = \ MappingManager.h \ Maths.h \ MediaImpl.h \ + MetaObjectRegistry.h \ OscInterface.h \ OscReceiver.h \ OutputGLCanvas.h \ @@ -47,6 +48,7 @@ SOURCES = \ Mapping.cpp \ MappingManager.cpp \ MediaImpl.cpp \ + MetaObjectRegistry.cpp \ OscInterface.cpp \ OscReceiver.cpp \ OutputGLCanvas.cpp \