-
Notifications
You must be signed in to change notification settings - Fork 8
/
tokendatabase.cpp
74 lines (62 loc) · 1.76 KB
/
tokendatabase.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* Database responsible for resolving tokens between translation units
*/
#include "tokendatabase.h"
#include <wx/filename.h>
#include <wx/string.h>
#include "treemap.h"
TokenDatabase::TokenDatabase() :
m_pTokens(new TreeMap<AbstractToken>()),
m_pFilenames(new TreeMap<wxString>())
{
}
TokenDatabase::~TokenDatabase()
{
delete m_pFilenames;
delete m_pTokens;
}
FileId TokenDatabase::GetFilenameId(const wxString& filename)
{
wxFileName fln(filename);
fln.Normalize(wxPATH_NORM_ALL & ~wxPATH_NORM_CASE);
const wxString& normFile = fln.GetFullPath(wxPATH_UNIX);
std::vector<int> id = m_pFilenames->GetIdSet(normFile);
if (id.empty())
return m_pFilenames->Insert(normFile, normFile);
return id.front();
}
wxString TokenDatabase::GetFilename(FileId fId) const
{
return m_pFilenames->GetValue(fId);
}
TokenId TokenDatabase::InsertToken(const wxString& identifier, const AbstractToken& token)
{
TokenId tId = GetTokenId(identifier, token.tokenHash);
if (tId == wxNOT_FOUND)
return m_pTokens->Insert(identifier, token);
return tId;
}
TokenId TokenDatabase::GetTokenId(const wxString& identifier, unsigned tokenHash) const
{
std::vector<int> ids = m_pTokens->GetIdSet(identifier);
for (std::vector<int>::const_iterator itr = ids.begin();
itr != ids.end(); ++itr)
{
if (m_pTokens->GetValue(*itr).tokenHash == tokenHash)
return *itr;
}
return wxNOT_FOUND;
}
AbstractToken& TokenDatabase::GetToken(TokenId tId) const
{
return m_pTokens->GetValue(tId);
}
std::vector<TokenId> TokenDatabase::GetTokenMatches(const wxString& identifier) const
{
return m_pTokens->GetIdSet(identifier);
}
void TokenDatabase::Shrink()
{
m_pFilenames->Shrink();
m_pTokens->Shrink();
}