Changeset View
Changeset View
Standalone View
Standalone View
kdevplatform/language/duchain/topducontextdynamicdata_p.h
- This file was added.
1 | /* This is part of KDevelop | ||||
---|---|---|---|---|---|
2 | Copyright 2018 R.J.V. Bertin <rjvbertin@gmail.com> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Library General Public | ||||
6 | License version 2 as published by the Free Software Foundation. | ||||
7 | | ||||
8 | This library is distributed in the hope that it will be useful, | ||||
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
11 | Library General Public License for more details. | ||||
12 | | ||||
13 | You should have received a copy of the GNU Library General Public License | ||||
14 | along with this library; see the file COPYING.LIB. If not, write to | ||||
15 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
16 | Boston, MA 02110-1301, USA. | ||||
17 | */ | ||||
18 | | ||||
19 | #ifndef KDEVPLATFORM_TOPDUCONTEXTDYNAMICDATA_P_H | ||||
20 | #define KDEVPLATFORM_TOPDUCONTEXTDYNAMICDATA_P_H | ||||
21 | | ||||
22 | #include <QByteArray> | ||||
23 | #include <QFile> | ||||
24 | | ||||
25 | #include <languageexport.h> | ||||
26 | | ||||
27 | namespace KDevelop { | ||||
28 | | ||||
29 | // #define KDEV_TOPCONTEXTS_DB_TESTING | ||||
30 | // #define KDEV_TOPCONTEXTS_USE_FILES | ||||
31 | #define KDEV_TOPCONTEXTS_USE_LMDB | ||||
32 | // #define KDEV_TOPCONTEXTS_USE_LEVELDB | ||||
33 | // #define KDEV_TOPCONTEXTS_USE_KYOTO | ||||
34 | | ||||
35 | // thin wrapper around QFile, implementing the default TopDUContext | ||||
36 | // storage mechanism but also used for migration purposes in the | ||||
37 | // database stores. | ||||
38 | class KDEVPLATFORMLANGUAGE_EXPORT TopDUContextFile : public QFile | ||||
39 | { | ||||
40 | public: | ||||
41 | TopDUContextFile(uint topContextIndex); | ||||
42 | void commit(); | ||||
43 | static bool exists(uint topContextIndex); | ||||
44 | static bool remove(uint topContextIndex); | ||||
45 | }; | ||||
46 | | ||||
47 | #if defined(KDEV_TOPCONTEXTS_USE_LMDB) || defined(KDEV_TOPCONTEXTS_USE_LEVELDB) || defined(KDEV_TOPCONTEXTS_USE_KYOTO) | ||||
48 | class KDEVPLATFORMLANGUAGE_EXPORT TopDUContextDB | ||||
49 | { | ||||
50 | public: | ||||
51 | virtual ~TopDUContextDB() {}; | ||||
52 | virtual bool open(QIODevice::OpenMode mode) = 0; | ||||
53 | virtual void commit() = 0; | ||||
54 | virtual bool flush() = 0; | ||||
55 | bool resize(qint64); | ||||
56 | qint64 write(const char* data, qint64 len); | ||||
57 | qint64 read(char* data, qint64 maxSize); | ||||
58 | QByteArray read(qint64 maxSize); | ||||
59 | QByteArray readAll(); | ||||
60 | qint64 pos() const; | ||||
61 | bool seek(qint64 pos); | ||||
62 | qint64 size(); | ||||
63 | QString errorString() const; | ||||
64 | QString fileName() const; | ||||
65 | static bool exists(uint) { return false; }; | ||||
66 | static bool remove(uint) { return false; }; | ||||
67 | | ||||
68 | protected: | ||||
69 | bool open(QIODevice::OpenMode mode, const QString &backendName); | ||||
70 | virtual bool getCurrentKeyValue() = 0; | ||||
71 | virtual bool isValid() = 0; | ||||
72 | virtual bool currentKeyExists() = 0; | ||||
73 | static bool exists(const QByteArray&) { return false; }; | ||||
74 | static QByteArray indexKey(uint idx); | ||||
75 | static QByteArray indexKey(uint* idx); | ||||
76 | bool migrateFromFile(); | ||||
77 | QByteArray m_currentKey; | ||||
78 | uint m_currentIndex; | ||||
79 | QByteArray m_currentValue; | ||||
80 | qint64 m_currentLen, m_readCursor; | ||||
81 | int m_mode; | ||||
82 | QString m_errorString; | ||||
83 | }; | ||||
84 | #endif | ||||
85 | | ||||
86 | #ifdef KDEV_TOPCONTEXTS_USE_LMDB | ||||
87 | class KDEVPLATFORMLANGUAGE_EXPORT TopDUContextLMDB : public TopDUContextDB | ||||
88 | { | ||||
89 | public: | ||||
90 | typedef union { char *bytes; qint32 *qint32Ptr; } LZ4Frame; | ||||
91 | TopDUContextLMDB(uint topContextIndex); | ||||
92 | virtual ~TopDUContextLMDB(); | ||||
93 | bool open(QIODevice::OpenMode mode) override; | ||||
94 | void commit() override; | ||||
95 | bool flush() override; | ||||
96 | QString fileName() const; | ||||
97 | static bool exists(uint topContextIndex); | ||||
98 | static bool remove(uint topContextIndex); | ||||
99 | | ||||
100 | protected: | ||||
101 | virtual bool getCurrentKeyValue() override; | ||||
102 | virtual bool isValid() override; | ||||
103 | virtual bool currentKeyExists() override; | ||||
104 | static bool exists(const QByteArray& key); | ||||
105 | static uint s_DbRefCount; | ||||
106 | }; | ||||
107 | #endif | ||||
108 | | ||||
109 | #ifdef KDEV_TOPCONTEXTS_USE_LEVELDB | ||||
110 | class KDEVPLATFORMLANGUAGE_EXPORT TopDUContextLevelDB : public TopDUContextDB | ||||
111 | { | ||||
112 | public: | ||||
113 | TopDUContextLevelDB(uint topContextIndex); | ||||
114 | virtual ~TopDUContextLevelDB(); | ||||
115 | bool open(QIODevice::OpenMode mode) override; | ||||
116 | void commit() override; | ||||
117 | bool flush() override; | ||||
118 | static bool exists(uint topContextIndex); | ||||
119 | static bool remove(uint topContextIndex); | ||||
120 | | ||||
121 | protected: | ||||
122 | virtual bool getCurrentKeyValue() override; | ||||
123 | virtual bool isValid() override; | ||||
124 | virtual bool currentKeyExists() override; | ||||
125 | static bool exists(const QByteArray& key); | ||||
126 | static uint s_DbRefCount; | ||||
127 | }; | ||||
128 | #endif | ||||
129 | | ||||
130 | #ifdef KDEV_TOPCONTEXTS_USE_KYOTO | ||||
131 | class KDEVPLATFORMLANGUAGE_EXPORT TopDUContextKyotoCabinet : public TopDUContextDB | ||||
132 | { | ||||
133 | public: | ||||
134 | TopDUContextKyotoCabinet(uint topContextIndex); | ||||
135 | virtual ~TopDUContextKyotoCabinet(); | ||||
136 | bool open(QIODevice::OpenMode mode) override; | ||||
137 | void commit() override; | ||||
138 | bool flush() override; | ||||
139 | QString fileName() const; | ||||
140 | static bool exists(uint topContextIndex); | ||||
141 | static bool remove(uint topContextIndex); | ||||
142 | | ||||
143 | protected: | ||||
144 | virtual bool getCurrentKeyValue() override; | ||||
145 | virtual bool isValid() override; | ||||
146 | virtual bool currentKeyExists() override; | ||||
147 | static bool exists(const QByteArray& key); | ||||
148 | static uint s_DbRefCount; | ||||
149 | }; | ||||
150 | #endif | ||||
151 | | ||||
152 | } | ||||
153 | #endif |