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_USE_FILES | ||||
30 | | ||||
31 | // thin wrapper around QFile, implementing the default TopDUContext | ||||
32 | // storage mechanism but also used for migration purposes in the | ||||
33 | // database stores. | ||||
34 | class KDEVPLATFORMLANGUAGE_EXPORT TopDUContextFile : public QFile | ||||
35 | { | ||||
36 | public: | ||||
37 | TopDUContextFile(uint topContextIndex); | ||||
38 | void commit(); | ||||
39 | static bool exists(uint topContextIndex); | ||||
40 | static bool remove(uint topContextIndex); | ||||
41 | }; | ||||
42 | | ||||
43 | #if !defined(KDEV_TOPCONTEXTS_USE_FILES) | ||||
44 | class KDEVPLATFORMLANGUAGE_EXPORT TopDUContextDB | ||||
45 | { | ||||
46 | public: | ||||
47 | virtual ~TopDUContextDB() {}; | ||||
48 | virtual bool open(QIODevice::OpenMode mode) = 0; | ||||
49 | virtual void commit() = 0; | ||||
50 | virtual bool flush() = 0; | ||||
51 | bool resize(qint64); | ||||
52 | qint64 write(const char* data, qint64 len); | ||||
53 | qint64 read(char* data, qint64 maxSize); | ||||
54 | QByteArray read(qint64 maxSize); | ||||
55 | QByteArray readAll(); | ||||
56 | qint64 pos() const; | ||||
57 | bool seek(qint64 pos); | ||||
58 | qint64 size(); | ||||
59 | QString errorString() const; | ||||
60 | QString fileName() const; | ||||
61 | static bool exists(uint) { return false; }; | ||||
62 | static bool remove(uint) { return false; }; | ||||
63 | | ||||
64 | protected: | ||||
65 | bool open(QIODevice::OpenMode mode, const QString &backendName); | ||||
66 | virtual bool getCurrentKeyValue() = 0; | ||||
67 | virtual bool isValid() = 0; | ||||
68 | virtual bool currentKeyExists() = 0; | ||||
69 | static bool exists(const QByteArray&) { return false; }; | ||||
70 | static QByteArray indexKey(uint idx); | ||||
71 | static QByteArray indexKey(uint* idx); | ||||
72 | bool migrateFromFile(); | ||||
73 | QByteArray m_currentKey; | ||||
74 | uint m_currentIndex; | ||||
75 | QByteArray m_currentValue; | ||||
76 | qint64 m_currentLen, m_readCursor; | ||||
77 | int m_mode; | ||||
78 | QString m_errorString; | ||||
79 | }; | ||||
80 | | ||||
81 | class KDEVPLATFORMLANGUAGE_EXPORT TopDUContextLMDB : public TopDUContextDB | ||||
82 | { | ||||
83 | public: | ||||
84 | typedef union { char *bytes; qint32 *qint32Ptr; } LZ4Frame; | ||||
85 | TopDUContextLMDB(uint topContextIndex); | ||||
86 | virtual ~TopDUContextLMDB(); | ||||
87 | bool open(QIODevice::OpenMode mode) override; | ||||
88 | void commit() override; | ||||
89 | bool flush() override; | ||||
90 | QString fileName() const; | ||||
91 | static bool exists(uint topContextIndex); | ||||
92 | static bool remove(uint topContextIndex); | ||||
93 | | ||||
94 | protected: | ||||
95 | virtual bool getCurrentKeyValue() override; | ||||
96 | virtual bool isValid() override; | ||||
97 | virtual bool currentKeyExists() override; | ||||
98 | static bool exists(const QByteArray& key); | ||||
99 | static uint s_DbRefCount; | ||||
100 | }; | ||||
101 | #endif // !KDEV_TOPCONTEXTS_USE_FILES | ||||
102 | | ||||
103 | } | ||||
104 | #endif |