qprotobufserializerregistry_p.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * MIT License
  3. *
  4. * Copyright (c) 2019 Alexey Edelev <semlanik@gmail.com>, Viktor Kopp <vifactor@gmail.com>
  5. *
  6. * This file is part of QtProtobuf project https://git.semlanik.org/semlanik/qtprotobuf
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy of this
  9. * software and associated documentation files (the "Software"), to deal in the Software
  10. * without restriction, including without limitation the rights to use, copy, modify,
  11. * merge, publish, distribute, sublicense, and/or sell copies of the Software, and
  12. * to permit persons to whom the Software is furnished to do so, subject to the following
  13. * conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in all copies
  16. * or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  19. * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  20. * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  21. * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  22. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. */
  25. #pragma once
  26. #include <QObject>
  27. #include <QSharedPointer>
  28. #include <memory>
  29. #include <type_traits>
  30. #include <unordered_map>
  31. #include "qabstractprotobufserializer.h"
  32. #include "qtprotobufglobal.h"
  33. namespace QtProtobuf {
  34. class QProtobufSerializerRegistryPrivate;
  35. /*!
  36. * \ingroup QtProtobuf
  37. * \private
  38. * \brief The QProtobufSerializerRegistry class provides api to register serializers,
  39. * loads serializer plugins and constructs serializer based on identifier.
  40. *
  41. * \details Class reads list of plugins from folder defined by QT_INSTALL_PLUGINS variable.
  42. * User can choose specific plugin or list of plugins with serializer implementations.
  43. * Pay attention, QProtobufSerializerRegistry not load all plugins, but only required by user.
  44. */
  45. class Q_PROTOBUF_EXPORT QProtobufSerializerRegistry final
  46. {
  47. public:
  48. std::shared_ptr<QAbstractProtobufSerializer> getSerializer(const QString &id);
  49. std::shared_ptr<QAbstractProtobufSerializer> getSerializer(const QString &id, const QString &plugin);
  50. std::unique_ptr<QAbstractProtobufSerializer> acquireSerializer(const QString &id, const QString &plugin);
  51. float pluginVersion(const QString &plugin);
  52. QStringList pluginSerializers(const QString &plugin);
  53. float pluginProtobufVersion(const QString &plugin);
  54. int pluginRating(const QString &plugin);
  55. QString loadPlugin(const QString &name);
  56. static QProtobufSerializerRegistry &instance() {
  57. static QProtobufSerializerRegistry _instance;
  58. return _instance;
  59. }
  60. private:
  61. QProtobufSerializerRegistry();
  62. ~QProtobufSerializerRegistry();
  63. Q_DISABLE_COPY_MOVE(QProtobufSerializerRegistry)
  64. std::unique_ptr<QProtobufSerializerRegistryPrivate> dPtr;
  65. };
  66. }