Debian Codegraph @

CodeLite/fc_fileopener.h

raw
1 //////////////////////////////////////////////////////////////////////////////
2 //////////////////////////////////////////////////////////////////////////////
3 //
4 // copyright : (C) 2014 Eran Ifrah
5 // file name : fc_fileopener.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 __fcfileopener__
27 #define __fcfileopener__
28
29 #include <vector>
30 #include <string>
31 #include <set>
32 #include <stack>
33 #include <stdio.h>
34 #include <list>
35 #include "codelite_exports.h"
36 #include <wx/string.h>
37 #include "wxStringHash.h"
38
39 typedef struct yy_buffer_state* BufferState;
40 struct fcState
41 {
42 BufferState buffer;
43 wxString filename;
44 };
45
46 class WXDLLIMPEXP_CL fcFileOpener
47 {
48 public:
49 typedef std::unordered_set<wxString> Set_t;
50 typedef std::vector<wxString> Vector_t;
51 typedef std::stack<fcState> Stack_t;
52
53 protected:
54 static fcFileOpener* ms_instance;
55
56 fcFileOpener::Vector_t _searchPath;
57 fcFileOpener::Vector_t _excludePaths;
58 fcFileOpener::Set_t _matchedfiles;
59 fcFileOpener::Set_t _scannedfiles;
60 int _depth;
61 int _maxDepth;
62 fcFileOpener::Set_t _namespaces;
63 fcFileOpener::Set_t _namespaceAliases;
64 fcFileOpener::Set_t _includeStatements;
65 fcFileOpener::Stack_t _states;
66 wxString _cwd;
67
68 public:
69 static fcFileOpener* Get();
70 static void Release();
71
72 FILE* try_open(const wxString& path, const wxString& name, wxString& filepath);
73
74 // Flex buffer states
75 BufferState PopBufferState();
76 void PushBufferState(BufferState buffer, const wxString& filename);
77 bool IsStateStackEmpty() const { return _states.empty(); }
78
79 void SetCwd(const wxString& _cwd) { this->_cwd = _cwd; }
80 void AddSearchPath(const wxString& path);
81 void AddExcludePath(const wxString& path);
82
83 /**
84 * @brief open a file based on the include paths and return a pointer to it.
85 * @param include_path the string as appears inside the #include statement
86 * @param filepath [output] the file that was opened
87 */
88 FILE* OpenFile(const wxString& include_path, wxString& filepath);
89
90 void ClearResults()
91 {
92 _matchedfiles.clear();
93 _scannedfiles.clear();
94 _namespaces.clear();
95 _namespaceAliases.clear();
96 _includeStatements.clear();
97 _depth = 0;
98 _cwd.Clear();
99 while(!_states.empty()) {
100 _states.pop();
101 }
102 }
103
104 void ClearSearchPath()
105 {
106 _searchPath.clear();
107 _excludePaths.clear();
108 }
109
110 void incDepth() { _depth++; }
111
112 void decDepth()
113 {
114 _depth--;
115 if(_depth < 0) {
116 _depth = 0;
117 }
118 }
119
120 int getDepth() { return _depth; }
121
122 void setMaxDepth(const int& _maxDepth) { this->_maxDepth = _maxDepth; }
123
124 const int& getMaxDepth() const { return _maxDepth; }
125
126 // getters
127 const fcFileOpener::Set_t& GetResults() const { return _matchedfiles; }
128
129 ////////////////////////////////////////////////////
130 // Using namespace support
131 const fcFileOpener::Set_t& GetNamespaces() const { return _namespaces; }
132
133 void ClearNamespace() { _namespaces.clear(); }
134 void AddNamespace(const char* ns);
135
136 ////////////////////////////////////////////////////
137 // Namespace aliasing
138 const fcFileOpener::Set_t& GetNamespaceAliases() const { return _namespaceAliases; }
139 void ClearNamespaceAliases() { _namespaceAliases.clear(); }
140 void AddNamespaceAlias(const char* alias) { _namespaceAliases.insert(alias); }
141 void AddIncludeStatement(const wxString& statement);
142 const fcFileOpener::Set_t& GetIncludeStatements() const { return _includeStatements; }
143 fcFileOpener::Set_t& GetIncludeStatements() { return _includeStatements; }
144
145 private:
146 fcFileOpener();
147 virtual ~fcFileOpener();
148 };
149 #endif // __fcfileopener__