Debian Codegraph @

CodeLite/istorage.h

raw
1 //////////////////////////////////////////////////////////////////////////////
2 //////////////////////////////////////////////////////////////////////////////
3 //
4 // copyright : (C) 2009 by Eran Ifrah
5 // file name : istorage.h
6 //
7 // -------------------------------------------------------------------------
8 // A
9 // _____ _ _ _ _
10 // / __ \ | | | | (_) |
11 // | / \/ ___ __| | ___| | _| |_ ___
12 // | | / _ \ / _ |/ _ \ | | | __/ _ )
13 // | \__/\ (_) | (_| | __/ |___| | || __/
14 // \____/\___/ \__,_|\___\_____/_|\__\___|
15 //
16 // F i l e
17 //
18 // This program is free software; you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation; either version 2 of the License, or
21 // (at your option) any later version.
22 //
23 //////////////////////////////////////////////////////////////////////////////
24 //////////////////////////////////////////////////////////////////////////////
25
26 #ifndef ISTORAGE_H
27 #define ISTORAGE_H
28
29 #include "comment.h"
30 #include "entry.h"
31 #include "fileentry.h"
32 #include "pptable.h"
33 #include "tag_tree.h"
34
35 #define MAX_SEARCH_LIMIT 250
36
37 /**
38 * @class ITagsStorage defined the tags storage API used by codelite
39 * @author eran
40 * @date 10/06/09
41 * @file istorage.h
42 * @brief
43 */
44 class ITagsStorage
45 {
46 protected:
47 wxFileName m_fileName;
48 int m_singleSearchLimit;
49 int m_maxWorkspaceTagToColour;
50 bool m_useCache;
51 bool m_enableCaseInsensitive;
52
53 public:
54 enum { OrderNone, OrderAsc, OrderDesc };
55
56 public:
57 ITagsStorage()
58 : m_singleSearchLimit(MAX_SEARCH_LIMIT)
59 , m_maxWorkspaceTagToColour(1000)
60 , m_useCache(false)
61 , m_enableCaseInsensitive(true)
62 {
63 }
64
65 virtual ~ITagsStorage(){};
66 virtual void SetEnableCaseInsensitive(bool b) { m_enableCaseInsensitive = b; }
67 virtual void SetUseCache(bool useCache) { this->m_useCache = useCache; }
68
69 virtual bool GetUseCache() const { return m_useCache; }
70
71 /**
72 * @brief clear the storage cache
73 */
74 virtual void ClearCache() = 0;
75
76 /**
77 * Return the currently opened database.
78 * @return Currently open database
79 */
80 const wxFileName& GetDatabaseFileName() const { return m_fileName; }
81
82 void SetSingleSearchLimit(int singleSearchLimit)
83 {
84 if(singleSearchLimit < 0) {
85 singleSearchLimit = MAX_SEARCH_LIMIT;
86 }
87 this->m_singleSearchLimit = singleSearchLimit;
88 }
89
90 int GetSingleSearchLimit() const { return m_singleSearchLimit; }
91
92 void SetMaxWorkspaceTagToColour(int maxWorkspaceTagToColour)
93 {
94 this->m_maxWorkspaceTagToColour = maxWorkspaceTagToColour;
95 }
96
97 int GetMaxWorkspaceTagToColour() const { return m_maxWorkspaceTagToColour; }
98
99 // -----------------------------------------------------------------
100 // -------------------- API pure virtual ---------------------------
101 // -----------------------------------------------------------------
102
103 /**
104 * @brief return list of tags based on scope and name
105 * @param scope the scope to search. If 'scope' is empty the scope is ommited from the search
106 * @param name
107 * @param partialNameAllowed
108 */
109 virtual void GetTagsByScopeAndName(const wxString& scope, const wxString& name, bool partialNameAllowed,
110 std::vector<TagEntryPtr>& tags) = 0;
111 virtual void GetTagsByScopeAndName(const wxArrayString& scope, const wxString& name, bool partialNameAllowed,
112 std::vector<TagEntryPtr>& tags) = 0;
113
114 /**
115 * @brief return list of tags by scope. If the cache is enabled, tags will be fetched from the
116 * cache instead of accessing the disk
117 * @param scope
118 * @param limit maximum items to fetch
119 * @param limitExceeded set to true if the
120 * @param tags
121 */
122 virtual void GetTagsByScope(const wxString& scope, std::vector<TagEntryPtr>& tags) = 0;
123
124 /**
125 * @brief return array of tags by kind.
126 * @param kinds array of kinds
127 * @param orderingColumn the column that the output should be ordered by (leave empty for no sorting)
128 * @param order OrderAsc, OrderDesc or use OrderNone for no ordering the results
129 * @param tags
130 */
131 virtual void GetTagsByKind(const wxArrayString& kinds, const wxString& orderingColumn, int order,
132 std::vector<TagEntryPtr>& tags) = 0;
133
134 /**
135 * @brief return array of tags by kind.
136 * @param kinds array of kinds
137 * @param orderingColumn the column that the output should be ordered by (leave empty for no sorting)
138 * @param order OrderAsc, OrderDesc or use OrderNone for no ordering the results
139 * @param tags
140 */
141 virtual void GetTagsByKindLimit(const wxArrayString& kinds, const wxString& orderingColumn, int order, int limit,
142 const wxString& partName, std::vector<TagEntryPtr>& tags) = 0;
143
144 /**
145 * @brief return array of items by path
146 * @param path
147 * @param tags
148 */
149 virtual void GetTagsByPath(const wxArrayString& path, std::vector<TagEntryPtr>& tags) = 0;
150 virtual void GetTagsByPath(const wxString& path, std::vector<TagEntryPtr>& tags, int limit = 1) = 0;
151 virtual void GetTagsByPathAndKind(const wxString& path, std::vector<TagEntryPtr>& tags,
152 const std::vector<wxString>& kinds, int limit = 1) = 0;
153
154 /**
155 * @brief return array of items by name and parent
156 * @param path
157 * @param tags
158 */
159 virtual void GetTagsByNameAndParent(const wxString& name, const wxString& parent,
160 std::vector<TagEntryPtr>& tags) = 0;
161
162 /**
163 * @brief reutnr array of tags by kind and path
164 * @param kinds array of kind
165 * @param path
166 * @param tags [output]
167 */
168 virtual void GetTagsByKindAndPath(const wxArrayString& kinds, const wxString& path,
169 std::vector<TagEntryPtr>& tags) = 0;
170
171 /**
172 * @brief return tags by file and line number
173 * @param file
174 * @param line
175 * @param tags [output]
176 */
177 virtual void GetTagsByFileAndLine(const wxString& file, int line, std::vector<TagEntryPtr>& tags) = 0;
178
179 /**
180 * @brief return tag entry above (or equal) line
181 */
182 virtual TagEntryPtr GetTagAboveFileAndLine(const wxString& file, int line) = 0;
183
184 /**
185 * @brief return list by kind and scope
186 * @param scope
187 * @param kinds
188 * @param tags [output]
189 */
190 virtual void GetTagsByScopeAndKind(const wxString& scope, const wxArrayString& kinds,
191 std::vector<TagEntryPtr>& tags, bool applyLimit = true) = 0;
192
193 /**
194 * @brief return list by kind and scope while using a filter
195 * @param scope
196 * @param kinds
197 * @param tags [output]
198 */
199 virtual void GetTagsByScopeAndKind(const wxString& scope, const wxArrayString& kinds, const wxString& filter,
200 std::vector<TagEntryPtr>& tags, bool applyLimit = true) = 0;
201
202 /**
203 * @brief get list of tags by kind and file
204 * @param kind
205 * @param orderingColumn the column that the output should be ordered by (leave empty for no sorting)
206 * @param order OrderAsc, OrderDesc or use OrderNone for no ordering the results
207 * @param tags
208 */
209 virtual void GetTagsByKindAndFile(const wxArrayString& kind, const wxString& fileName,
210 const wxString& orderingColumn, int order, std::vector<TagEntryPtr>& tags) = 0;
211
212 /**
213 * @brief return list of all global functions
214 * @param tags [output]
215 */
216 virtual void GetGlobalFunctions(std::vector<TagEntryPtr>& tags) = 0;
217
218 /**
219 * @brief
220 * @param scope
221 * @param tags
222 */
223 virtual void GetDereferenceOperator(const wxString& scope, std::vector<TagEntryPtr>& tags) = 0;
224
225 /**
226 * @brief
227 * @param scope
228 * @param tags
229 */
230 virtual void GetSubscriptOperator(const wxString& scope, std::vector<TagEntryPtr>& tags) = 0;
231
232 // -------------------------- Files Table -------------------------------------------
233
234 /**
235 * @brief delete an entry by file name
236 * @param filename
237 * @return
238 */
239 virtual int DeleteFileEntry(const wxString& filename) = 0;
240
241 /**
242 * @brief insert entry by file name
243 * @param filename
244 * @return
245 */
246 virtual int InsertFileEntry(const wxString& filename, int timestamp) = 0;
247
248 /**
249 * @brief update file entry using file name as key
250 * @param filename
251 * @param timestamp new timestamp
252 * @return
253 */
254 virtual int UpdateFileEntry(const wxString& filename, int timestamp) = 0;
255
256 // -------------------------- TagEntry -------------------------------------------
257 /**
258 * Return a result set of tags according to file name.
259 * @param file Source file name
260 * @param path Database file name
261 * @return result set
262 */
263 virtual void SelectTagsByFile(const wxString& file, std::vector<TagEntryPtr>& tags,
264 const wxFileName& path = wxFileName()) = 0;
265
266 /**
267 * @brief return true if type exist under a given scope.
268 * Incase it exist but under the <global> scope, 'scope' will be modified
269 * @param typeName type to search [intput/output]
270 * @param scope [intput/output]
271 * @return true on success
272 */
273 virtual bool IsTypeAndScopeContainer(wxString& typeName, wxString& scope) = 0;
274
275 /**
276 * @brief return true if type exist under a given scope.
277 * Incase it exist but under the <global> scope, 'scope' will be modified
278 * @param typeName type to search
279 * @param scope [intput/output]
280 * @return true on success
281 */
282 virtual bool IsTypeAndScopeExist(wxString& typeName, wxString& scope) = 0;
283
284 /**
285 * @brief return true if typeName & scope exists in the storage (it uses LIMIT 1, hence LimitOne)
286 * @param typeName
287 * @param scope
288 * @return
289 */
290 virtual bool IsTypeAndScopeExistLimitOne(const wxString& typeName, const wxString& scope) = 0;
291
292 /**
293 * @brief return list of given scopes of file in ascending order
294 * @param fileName
295 * @param scopes
296 */
297 virtual void GetScopesFromFileAsc(const wxFileName& fileName, std::vector<wxString>& scopes) = 0;
298
299 /**
300 * Return the current version of the database library .
301 * @return current version of the database library
302 */
303 virtual const wxString& GetVersion() const = 0;
304
305 /**
306 * Schema version as appears in TAGS_VERSION table
307 * @return schema's version
308 */
309 virtual wxString GetSchemaVersion() const = 0;
310
311 /**
312 * @brief determine the current scope based on file name and line number
313 */
314 virtual TagEntryPtr GetScope(const wxString& filename, int line_number) = 0;
315
316 /**
317 * @brief
318 * @param fileName
319 * @param scopeName
320 * @param tags
321 */
322 virtual void GetTagsByFileScopeAndKind(const wxFileName& fileName, const wxString& scopeName,
323 const wxArrayString& kind, std::vector<TagEntryPtr>& tags) = 0;
324
325 /**
326 * @brief return a unique list of names
327 * @param kind
328 * @param names
329 */
330 virtual void GetTagsNames(const wxArrayString& kind, wxArrayString& names) = 0;
331
332 /**
333 * Store tree of tags into db.
334 * @param tree Tags tree to store
335 * @param path Database file name
336 * @param autoCommit handle the Store operation inside a transaction or let the user hadle it
337 */
338 virtual void Store(const std::vector<TagEntryPtr>& tags, bool auto_commit = true) = 0;
339
340 /**
341 * A very dengerous API call, which drops all tables from the database
342 * and recreate the schema from fresh. It is used when upgrading database between different
343 * versions
344 */
345 virtual void RecreateDatabase() = 0;
346
347 /**
348 * return list of files from the database. The returned list is ordered
349 * by name (ascending)
350 * @param partialName part of the file name to act as a filter
351 * @param files [output] array of files
352 */
353 virtual void GetFiles(const wxString& partialName, std::vector<FileEntryPtr>& files) = 0;
354
355 /**
356 * @brief return list of files from the database
357 * @param files vector of database record
358 */
359 virtual void GetFiles(std::vector<FileEntryPtr>& files) = 0;
360
361 /**
362 * @brief this function is for supporting CC inside an include statement
363 * line
364 */
365 virtual void GetFilesForCC(const wxString& userTyped, wxArrayString& matches) = 0;
366
367 /**
368 * @brief for transactional storage, provide begin/commit/rollback methods
369 */
370 virtual void Begin() = 0;
371 virtual void Commit() = 0;
372 virtual void Rollback() = 0;
373
374 /**
375 * Delete all entries from database that are related to filename.
376 * @param path Database name
377 * @param fileName File name
378 * @param autoCommit handle the Delete operation inside a transaction or let the user hadle it
379 */
380 virtual void DeleteByFileName(const wxFileName& path, const wxString& fileName, bool autoCommit = true) = 0;
381
382 /**
383 * @brief delete all files from FILES table which starts with filePrefix
384 * @param dbpath database file name
385 * @param filePrefix prefix criterion
386 */
387 virtual void DeleteFromFilesByPrefix(const wxFileName& dbpath, const wxString& filePrefix) = 0;
388
389 /**
390 * @brief delete files from FILES table
391 * @param files
392 */
393 virtual void DeleteFromFiles(const wxArrayString& files) = 0;
394
395 /**
396 * @brief delete all tags from database which their file's path begins with a given prefix
397 * @param dbpath database file name
398 * @param filePrefix prefix criterion
399 */
400 virtual void DeleteByFilePrefix(const wxFileName& dbpath, const wxString& filePrefix) = 0;
401
402 /**
403 * Open sqlite database.
404 * @param fileName Database file name
405 */
406 virtual void OpenDatabase(const wxFileName& fileName) = 0;
407
408 /**
409 * Test whether the database is opened
410 * @return true if database is attached to a file
411 */
412 virtual const bool IsOpen() const = 0;
413
414 /**
415 * @brief return list of tags by scopes and kinds
416 * @param scopes array of possible scopes
417 * @param kinds array of possible kinds
418 * @param tags [output]
419 */
420 virtual void GetTagsByScopesAndKind(const wxArrayString& scopes, const wxArrayString& kinds,
421 std::vector<TagEntryPtr>& tags) = 0;
422 /**
423 * @brief return list of tags by scopes and kinds with no LIMIT applied
424 * @param scopes array of possible scopes
425 * @param kinds array of possible kinds
426 * @param tags [output]
427 */
428 virtual void GetTagsByScopesAndKindNoLimit(const wxArrayString& scopes, const wxArrayString& kinds,
429 std::vector<TagEntryPtr>& tags) = 0;
430
431 /**
432 * @brief return list of tags by typerefs and kinds
433 * @param typerefs array of possible typerefs
434 * @param kinds array of possible kinds
435 * @param tags [output]
436 */
437 virtual void GetTagsByTyperefAndKind(const wxArrayString& typerefs, const wxArrayString& kinds,
438 std::vector<TagEntryPtr>& tags) = 0;
439
440 /**
441 * @brief return tags by files / scope
442 * @param files
443 * @param scope
444 * @param tags
445 */
446 virtual void GetTagsByFilesAndScope(const wxArrayString& files, const wxString& scope,
447 std::vector<TagEntryPtr>& tags) = 0;
448 /**
449 * @brief return tags by files / kinds / scope (the relation between the three is AND)
450 * @param files
451 * @param kinds
452 * @param scope
453 * @param tags
454 */
455 virtual void GetTagsByFilesKindAndScope(const wxArrayString& files, const wxArrayString& kinds,
456 const wxString& scope, std::vector<TagEntryPtr>& tags) = 0;
457 /**
458 * @brief
459 * @param files
460 * @param kinds
461 * @param scope
462 * @param typeref
463 * @param tags
464 */
465 virtual void GetTagsByFilesScopeTyperefAndKind(const wxArrayString& files, const wxArrayString& kinds,
466 const wxString& scope, const wxString& typeref,
467 std::vector<TagEntryPtr>& tags) = 0;
468 /**
469 * @brief return tags by files
470 * @param files
471 * @param tags
472 */
473 virtual void GetTagsByFiles(const wxArrayString& files, std::vector<TagEntryPtr>& tags) = 0;
474
475 /**
476 * @brief return macro evaluation
477 * @param name macro to search
478 */
479 virtual PPToken GetMacro(const wxString& name) = 0;
480
481 /**
482 * @brief store macros table as they are produced from the PPTable
483 */
484 virtual void StoreMacros(const std::map<wxString, PPToken>& table) = 0;
485
486 /**
487 * @brief return the macros defined by some files.
488 * The macro return must match the given used macros.
489 *
490 * @param files The files which define the macros we are looking for
491 * @param usedMacros The macros wee are looking for
492 * @param defMacros [out] The real defined macros
493 */
494 virtual void GetMacrosDefined(const std::set<std::string>& files, const std::set<wxString>& usedMacros,
495 wxArrayString& defMacros) = 0;
496
497 /**
498 * @brief return list of tags for a given prefix
499 */
500 virtual void GetTagsByName(const wxString& prefix, std::vector<TagEntryPtr>& tags, bool exactMatch = false) = 0;
501
502 /**
503 * @brief return list of tags for a given partial name
504 */
505 virtual void GetTagsByPartName(const wxString& partname, std::vector<TagEntryPtr>& tags) = 0;
506
507 /**
508 * @brief same as above, but allow multiple name parts
509 */
510 virtual void GetTagsByPartName(const wxArrayString& parts, std::vector<TagEntryPtr>& tags) = 0;
511
512 /**
513 * @brief search for a single match in the database for an entry with a given name
514 */
515 virtual TagEntryPtr GetTagsByNameLimitOne(const wxString& name) = 0;
516
517 /**
518 * @brief this function takes as input argument array of symbols and removes from it all the
519 * symbols that are not part of the workspace
520 */
521 virtual void RemoveNonWorkspaceSymbols(const std::vector<wxString>& symbols,
522 std::vector<wxString>& workspaceSymbols,
523 std::vector<wxString>& nonWorkspaceSymbols) = 0;
524 /**
525 * @brief check the integrity of the database to avoid "malformed disk" errors
526 */
527 virtual bool CheckIntegrity() const = 0;
528 /**
529 * @brief return list of tags only visible to `filepath`
530 * this usually includes static members, or any entity
531 * in an anonymous namespace
532 */
533 virtual size_t GetFileScopedTags(const wxString& filepath, const wxString& name, const wxArrayString& kinds,
534 std::vector<TagEntryPtr>& tags) = 0;
535
536 /**
537 * @brief load function parameters
538 */
539 virtual size_t GetParameters(const wxString& function_path, std::vector<TagEntryPtr>& tags) = 0;
540
541 /**
542 * @brief load all lambda functions for a given function
543 */
544 virtual size_t GetLambdas(const wxString& parent_function, std::vector<TagEntryPtr>& tags) = 0;
545 };
546
547 enum { TagOk = 0, TagExist, TagError };
548
549 typedef SmartPtr<ITagsStorage> ITagsStoragePtr;
550
551 #endif // ISTORAGE_H