| 1 |
#ifndef __fcfileopener__ |
| 2 |
#define __fcfileopener__ |
| 3 |
|
| 4 |
#include <vector> |
| 5 |
#include <string> |
| 6 |
#include <set> |
| 7 |
#include <stdio.h> |
| 8 |
#include <list> |
| 9 |
#include "codelite_exports.h" |
| 10 |
|
| 11 |
typedef struct yy_buffer_state *BufferState; |
| 12 |
struct fcState { |
| 13 |
BufferState buffer; |
| 14 |
wxString filename; |
| 15 |
}; |
| 16 |
|
| 17 |
class WXDLLIMPEXP_CL fcFileOpener |
| 18 |
{ |
| 19 |
public: |
| 20 |
typedef std::list<wxString> List_t; |
| 21 |
typedef std::set<wxString> Set_t; |
| 22 |
typedef std::vector<wxString> Vector_t; |
| 23 |
typedef std::list<fcState> Stack_t; |
| 24 |
|
| 25 |
protected: |
| 26 |
static fcFileOpener* ms_instance ; |
| 27 |
|
| 28 |
fcFileOpener::Vector_t _searchPath ; |
| 29 |
fcFileOpener::Vector_t _excludePaths ; |
| 30 |
fcFileOpener::Set_t _matchedfiles ; |
| 31 |
fcFileOpener::Set_t _scannedfiles ; |
| 32 |
int _depth ; |
| 33 |
int _maxDepth ; |
| 34 |
fcFileOpener::Set_t _namespaces ; |
| 35 |
fcFileOpener::Set_t _namespaceAliases ; |
| 36 |
fcFileOpener::List_t _includeStatements; |
| 37 |
fcFileOpener::Stack_t _states; |
| 38 |
wxString _cwd; |
| 39 |
|
| 40 |
public: |
| 41 |
static fcFileOpener* Get(); |
| 42 |
static void Release(); |
| 43 |
|
| 44 |
FILE* try_open(const wxString &path, const wxString &name, wxString &filepath); |
| 45 |
|
| 46 |
|
| 47 |
BufferState PopBufferState(); |
| 48 |
void PushBufferState(BufferState buffer, const wxString &filename); |
| 49 |
bool IsStateStackEmpty() const { |
| 50 |
return _states.empty(); |
| 51 |
} |
| 52 |
|
| 53 |
void SetCwd(const wxString& _cwd) { |
| 54 |
this->_cwd = _cwd; |
| 55 |
} |
| 56 |
void AddSearchPath(const wxString &path); |
| 57 |
void AddExcludePath(const wxString &path); |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
FILE *OpenFile(const wxString &include_path, wxString &filepath); |
| 65 |
|
| 66 |
void ClearResults() { |
| 67 |
_matchedfiles.clear(); |
| 68 |
_scannedfiles.clear(); |
| 69 |
_namespaces.clear(); |
| 70 |
_namespaceAliases.clear(); |
| 71 |
_includeStatements.clear(); |
| 72 |
_depth = 0; |
| 73 |
_cwd.Clear(); |
| 74 |
_states.clear(); |
| 75 |
} |
| 76 |
|
| 77 |
void ClearSearchPath() { |
| 78 |
_searchPath.clear(); |
| 79 |
_excludePaths.clear(); |
| 80 |
} |
| 81 |
|
| 82 |
void incDepth() { |
| 83 |
_depth++; |
| 84 |
} |
| 85 |
|
| 86 |
void decDepth() { |
| 87 |
_depth--; |
| 88 |
if ( _depth < 0) { |
| 89 |
_depth = 0; |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
int getDepth() { |
| 94 |
return _depth; |
| 95 |
} |
| 96 |
|
| 97 |
void setMaxDepth(const int& _maxDepth) { |
| 98 |
this->_maxDepth = _maxDepth; |
| 99 |
} |
| 100 |
|
| 101 |
const int& getMaxDepth() const { |
| 102 |
return _maxDepth; |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
const fcFileOpener::Set_t& GetResults() const { |
| 107 |
return _matchedfiles; |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
const fcFileOpener::Set_t& GetNamespaces() const { |
| 113 |
return _namespaces; |
| 114 |
} |
| 115 |
|
| 116 |
void ClearNamespace() { |
| 117 |
_namespaces.clear(); |
| 118 |
} |
| 119 |
void AddNamespace(const char* ns); |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
const fcFileOpener::Set_t& GetNamespaceAliases() const { |
| 124 |
return _namespaceAliases; |
| 125 |
} |
| 126 |
void ClearNamespaceAliases() { |
| 127 |
_namespaceAliases.clear(); |
| 128 |
} |
| 129 |
void AddNamespaceAlias(const char* alias) { |
| 130 |
_namespaceAliases.insert(alias); |
| 131 |
} |
| 132 |
void AddIncludeStatement(const wxString& statement); |
| 133 |
const fcFileOpener::List_t& GetIncludeStatements() const { |
| 134 |
return _includeStatements; |
| 135 |
} |
| 136 |
private: |
| 137 |
fcFileOpener(); |
| 138 |
virtual ~fcFileOpener(); |
| 139 |
|
| 140 |
|
| 141 |
}; |
| 142 |
#endif |