utility: added FilePath abstraction and rewrote data management to use it

The utility class FilePath wraps an instance of boost::filesystem::path. Using FilePath allows for easy comparision of
file paths on different platforms using absolute or relative paths. Whereever file paths are compared, this wrapper
should be used.
This commit is contained in:
Eberhard Graether
2015-03-09 01:51:32 +01:00
parent 7014c8ac4c
commit df888e4151
37 changed files with 387 additions and 126 deletions
@@ -38,7 +38,7 @@ size_t TokenLocationCollection::getTokenLocationCount() const
}
TokenLocation* TokenLocationCollection::addTokenLocation(
Id tokenId, const std::string& filePath,
Id tokenId, const FilePath& filePath,
unsigned int startLineNumber, unsigned int startColumnNumber,
unsigned int endLineNumber, unsigned int endColumnNumber)
{
@@ -87,13 +87,13 @@ TokenLocation* TokenLocationCollection::findTokenLocationById(Id id) const
return nullptr;
}
TokenLocationFile* TokenLocationCollection::findTokenLocationFileByPath(const std::string& filePath) const
TokenLocationFile* TokenLocationCollection::findTokenLocationFileByPath(const FilePath& filePath) const
{
std::map<std::string, std::shared_ptr<TokenLocationFile>>::const_iterator it =
std::map<FilePath, std::shared_ptr<TokenLocationFile>>::const_iterator it =
find_if(m_files.begin(), m_files.end(),
[&](const std::pair<std::string, std::shared_ptr<TokenLocationFile>>& p)
[&](const std::pair<FilePath, std::shared_ptr<TokenLocationFile>>& p)
{
return FileSystem::equivalent(p.first, filePath);
return p.first == filePath;
}
);
@@ -143,7 +143,7 @@ void TokenLocationCollection::removeTokenLocationFile(TokenLocationFile* file)
TokenLocation* TokenLocationCollection::addTokenLocationAsPlainCopy(const TokenLocation* location)
{
const std::string& filePath = location->getTokenLocationLine()->getTokenLocationFile()->getFilePath();
const FilePath& filePath = location->getTokenLocationLine()->getTokenLocationFile()->getFilePath();
TokenLocationFile* file = createTokenLocationFile(filePath);
TokenLocation* copy = file->addTokenLocationAsPlainCopy(location);
@@ -157,7 +157,7 @@ void TokenLocationCollection::clear()
m_files.clear();
}
TokenLocationFile* TokenLocationCollection::createTokenLocationFile(const std::string& filePath)
TokenLocationFile* TokenLocationCollection::createTokenLocationFile(const FilePath& filePath)
{
TokenLocationFile* file = findTokenLocationFileByPath(filePath);