QtProtobuf  0.6
Protobuf plugin to generate Qt classes
qprotobufserializerregistry_p.h
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 
26 #pragma once
27 
28 #include <QObject>
29 #include <QSharedPointer>
30 
31 #include <memory>
32 #include <type_traits>
33 #include <unordered_map>
34 
35 #include "qabstractprotobufserializer.h"
36 
37 #include "qtprotobufglobal.h"
38 
39 namespace QtProtobuf {
40 
41 class QProtobufSerializerRegistryPrivate;
42 
53 class Q_PROTOBUF_EXPORT QProtobufSerializerRegistry final
54 {
55 public:
56  std::shared_ptr<QAbstractProtobufSerializer> getSerializer(const QString &id);
57  std::shared_ptr<QAbstractProtobufSerializer> getSerializer(const QString &id, const QString &plugin);
58  std::unique_ptr<QAbstractProtobufSerializer> acquireSerializer(const QString &id, const QString &plugin);
59  float pluginVersion(const QString &plugin);
60  QStringList pluginSerializers(const QString &plugin);
61  float pluginProtobufVersion(const QString &plugin);
62  int pluginRating(const QString &plugin);
63 
64  QString loadPlugin(const QString &name);
65 
66  static QProtobufSerializerRegistry &instance() {
67  static QProtobufSerializerRegistry _instance;
68  return _instance;
69  }
70 
71 private:
72  QProtobufSerializerRegistry();
73  ~QProtobufSerializerRegistry();
74 
75  Q_DISABLE_COPY_MOVE(QProtobufSerializerRegistry)
76 
77  std::unique_ptr<QProtobufSerializerRegistryPrivate> dPtr;
78 };
79 }