metaclassparser.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. Copyright 2017 Herik Lima de Castro and Marcelo Medeiros Eler
  3. Distributed under MIT license, or public domain if desired and
  4. recognized in your jurisdiction.
  5. See file LICENSE for detail.
  6. */
  7. #ifndef METACLASSPARSER_H
  8. #define METACLASSPARSER_H
  9. #include "cppwebframework_global.h"
  10. #include <QDebug>
  11. #include <QMap>
  12. #include <QMetaMethod>
  13. #include <QMetaProperty>
  14. #include <QMetaType>
  15. #include <QObject>
  16. #include <QString>
  17. #include <tuple>
  18. CWF_BEGIN_NAMESPACE
  19. /**
  20. * @brief This class extracts all information from a QObject.
  21. */
  22. class CPPWEBFRAMEWORKSHARED_EXPORT MetaClassParser
  23. {
  24. public:
  25. QMap<std::tuple<QString, QString>, QMetaMethod> methods;
  26. QMap<QString, QMetaProperty> properties;
  27. QMap<QPair<QString, QString>, QMetaProperty> props;
  28. /**
  29. * @brief Extracts all properties and methods names from a QObject.
  30. * @param QObject *object : Object.
  31. */
  32. explicit MetaClassParser(QObject *object, bool removeObjectName = false);
  33. /**
  34. * @brief Returns the method return type given a method name.
  35. * @param const QString &methodName : Method name.
  36. * @return QString : Return type.
  37. */
  38. QString getReturnType(const QString &methodName);
  39. /**
  40. * @brief Returns the method parameter type given a method name.
  41. * @param const QString &methodName : Method name.
  42. * @return QString : Parameter type.
  43. */
  44. QString getParameterType(const QString &methodName);
  45. /**
  46. * @brief Returns all properties names.
  47. */
  48. QStringList getAllPropertiesNames() const;
  49. /**
  50. * @brief Tries to find a property.
  51. */
  52. QMetaProperty findProperty(const QString &propertyName);
  53. /**
  54. * @brief Instantiate a class by name.
  55. * @param const QByteArray &name : Class name.
  56. * @return void * : Returns nullptr if fails.
  57. */
  58. static void *instantiateClassByName(const QByteArray &name);
  59. };
  60. CWF_END_NAMESPACE
  61. #endif // METACLASSPARSER_H