Commit ee35e812e22398451a2f5faac4c0cc6d4b60dab8
Merge pull request #232 from biometrics/interface_lookup
Add a function to explicitly look up a br::Object's interface via metaOb...
Showing
1 changed file
with
29 additions
and
28 deletions
openbr/openbr_plugin.cpp
| ... | ... | @@ -45,6 +45,16 @@ using namespace cv; |
| 45 | 45 | |
| 46 | 46 | Q_DECLARE_METATYPE(QLocalSocket::LocalSocketState) |
| 47 | 47 | |
| 48 | +static const QMetaObject *getInterface(const QObject *obj) | |
| 49 | +{ | |
| 50 | + const QMetaObject *baseClass = obj->metaObject(); | |
| 51 | + | |
| 52 | + while (strcmp(baseClass->superClass()->className(), "br::Object") != 0) | |
| 53 | + baseClass = baseClass->superClass(); | |
| 54 | + | |
| 55 | + return baseClass; | |
| 56 | +} | |
| 57 | + | |
| 48 | 58 | /* File - public methods */ |
| 49 | 59 | // Note that the convention for displaying metadata is as follows: |
| 50 | 60 | // [] for lists in which argument order does not matter (e.g. [FTO=false, Index=0]), |
| ... | ... | @@ -606,28 +616,24 @@ QStringList Object::prunedArguments(bool expanded) const |
| 606 | 616 | if (!className.startsWith(".")) |
| 607 | 617 | className = "." + className; |
| 608 | 618 | |
| 609 | - if (className.endsWith("Distance")) { | |
| 610 | - className.chop(QString("Distance").size()); | |
| 619 | + const QMetaObject *interface = getInterface(this); | |
| 620 | + QString interfaceName = QString(interface->className()).remove("br::"); | |
| 621 | + | |
| 622 | + if (className.endsWith(interfaceName)) | |
| 623 | + className.chop(interfaceName.size()); | |
| 624 | + | |
| 625 | + if (interfaceName == "Distance") | |
| 611 | 626 | shellObject.reset(Factory<Distance>::make(className)); |
| 612 | - } | |
| 613 | - else if (className.endsWith("Transform")) { | |
| 614 | - className.chop(QString("Transform").size()); | |
| 627 | + else if (interfaceName == "Transform") | |
| 615 | 628 | shellObject.reset(Factory<Transform>::make(className)); |
| 616 | - } | |
| 617 | - else if (className.endsWith("Format")) { | |
| 618 | - className.chop(QString("Format").size()); | |
| 629 | + else if (interfaceName == "Format") | |
| 619 | 630 | shellObject.reset(Factory<Format>::make(className)); |
| 620 | - } | |
| 621 | - else if (className.endsWith("Initializer")) { | |
| 622 | - className.chop(QString("Initializer").size()); | |
| 631 | + else if (interfaceName == "Initializer") | |
| 623 | 632 | shellObject.reset(Factory<Initializer>::make(className)); |
| 624 | - } | |
| 625 | - else if (className.endsWith("Output")) { | |
| 626 | - className.chop(QString("Output").size()); | |
| 633 | + else if (interfaceName == "Output") | |
| 627 | 634 | shellObject.reset(Factory<Output>::make(className)); |
| 628 | - } | |
| 629 | 635 | else |
| 630 | - qFatal("Object with className: %s is of unrecognized type", qPrintable(className)); | |
| 636 | + qFatal("Object with className: %s has unrecognized interface: %s", qPrintable(className), qPrintable(interfaceName)); | |
| 631 | 637 | |
| 632 | 638 | for (int i=firstAvailablePropertyIdx; i<metaObject()->propertyCount(); i++) { |
| 633 | 639 | const char *name = metaObject()->property(i).name(); |
| ... | ... | @@ -876,18 +882,13 @@ void Object::init(const File &file_) |
| 876 | 882 | { |
| 877 | 883 | file = file_; |
| 878 | 884 | |
| 879 | - // Determine interfaceName and firstAvailablePropertyIdx | |
| 880 | - QString interfaceName; | |
| 881 | - const QMetaObject *baseClass = metaObject(); | |
| 882 | - while (true) { | |
| 883 | - if (!strcmp(baseClass->superClass()->className(), "br::Object") /* Special case for classes that inherit directly from br::Object */ || | |
| 884 | - !strcmp(baseClass->superClass()->superClass()->className(), "br::Object") /* General case for plugins that inherit indirectly from br::Object */) { | |
| 885 | - firstAvailablePropertyIdx = baseClass->propertyOffset(); | |
| 886 | - interfaceName = QString(baseClass->superClass()->className()).remove("br::"); | |
| 887 | - break; | |
| 888 | - } | |
| 889 | - baseClass = baseClass->superClass(); | |
| 890 | - } | |
| 885 | + const QMetaObject *interface = getInterface(this); | |
| 886 | + if (strcmp(interface->className(), metaObject()->className()) != 0) | |
| 887 | + firstAvailablePropertyIdx = interface->propertyCount(); | |
| 888 | + else | |
| 889 | + firstAvailablePropertyIdx = interface->propertyOffset(); | |
| 890 | + | |
| 891 | + QString interfaceName = QString(interface->className()).remove("br::"); | |
| 891 | 892 | |
| 892 | 893 | // Strip interface name from object name (e.g. PipeTransform -> Pipe) |
| 893 | 894 | QString name = QString(metaObject()->className()).remove("br::"); | ... | ... |