FougTools  0.7.0dev-046fb6a
Handy tools for C++, Qt and OpenCascade
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
plugins_loader_instance_iface_filter.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** FougTools
3 ** Copyright Fougue (30 Mar. 2015)
4 ** contact@fougue.pro
5 **
6 ** This software is a computer program whose purpose is to provide utility
7 ** tools for the C++ language and the Qt toolkit.
8 **
9 ** This software is governed by the CeCILL-C license under French law and
10 ** abiding by the rules of distribution of free software. You can use,
11 ** modify and/ or redistribute the software under the terms of the CeCILL-C
12 ** license as circulated by CEA, CNRS and INRIA at the following URL
13 ** "http://www.cecill.info".
14 ****************************************************************************/
15 
16 #pragma once
17 
19 
20 #include <QtCore/QObject>
21 
22 namespace qtcore {
23 
24 namespace internal {
25 
29 class QTTOOLS_CORE_EXPORT PluginsLoader_InstanceIFaceFilter_Helper
30 {
31 protected:
32  static void setRootComponentNullError(
33  QString* error, const QPluginLoader* loader);
34  static void setRootComponentIncompatibleError(
35  QString* error, const char* iid);
36  static QObject* rootComponent(QPluginLoader* loader);
37 };
38 
39 } // namespace internal
40 
48 template<typename INTERFACE>
51  protected internal::PluginsLoader_InstanceIFaceFilter_Helper
52 {
53 public:
54  bool accepts(QPluginLoader *loader, QString* error = NULL) const
55  {
56  if (rootComponent(loader) != NULL) {
57  if (qobject_cast<INTERFACE*>(rootComponent(loader)) != NULL) {
58  return true;
59  }
60  else {
61  setRootComponentIncompatibleError(
62  error, qobject_interface_iid<INTERFACE>());
63  }
64  }
65  else {
66  setRootComponentNullError(error, loader);
67  }
68  return false;
69  }
70 };
71 
72 } // namespace qtcore
bool accepts(QPluginLoader *loader, QString *error=NULL) const
Keep or discard the root component of QPluginLoader loader.
Definition: plugins_loader_instance_iface_filter.h:54
#define QTTOOLS_CORE_EXPORT
Definition: core.h:27
Generic plugin filter that keeps only root components satisfying an interface.
Definition: plugins_loader_instance_iface_filter.h:49
Definition: grid_numbering.cpp:19
Provides plugin filter to be used with PluginsLoader.
Definition: plugins_loader_instance_filter.h:23