src: implemented move constructor/assignment for filepath
* improves indexing performance by roughly 5% * switched to use uniqu_ptr for boost path to get rid of including boost in header * added different methods to change the current FilePath or to make a copy and change that one * used these methods appropriately throughout the code base * removed exists() method from FileSystem because it is already contained in FilePath * added const in some places
This commit is contained in:
@@ -83,7 +83,7 @@ LicenseChecker::LicenseState LicenseChecker::checkCurrentLicense() const
|
||||
return LICENSE_EMPTY;
|
||||
}
|
||||
|
||||
if (!License::checkLocation(FilePath(appPath).absolute().str(), licenseCheck))
|
||||
if (!License::checkLocation(FilePath(appPath).makeAbsolute().str(), licenseCheck))
|
||||
{
|
||||
return LICENSE_MOVED;
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ void IDECommunicationController::handleSetActiveTokenMessage(
|
||||
{
|
||||
const unsigned int cursorColumn = message.column;
|
||||
|
||||
const FilePath filePath = FilePath(message.fileLocation).canonical();
|
||||
const FilePath filePath = FilePath(message.fileLocation).makeCanonical();
|
||||
|
||||
if (FileSystem::getFileInfoForPath(filePath).lastWriteTime
|
||||
== m_storageAccess->getFileInfoForFilePath(filePath).lastWriteTime)
|
||||
|
||||
@@ -486,7 +486,7 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleOfBundleNode(bool isFocused)
|
||||
return getStyleForNodeType(
|
||||
NodeType::STYLE_BIG_NODE,
|
||||
"bundle",
|
||||
ResourcePaths::getGuiPath().concat(FilePath("graph_view/images/bundle.png")),
|
||||
ResourcePaths::getGuiPath().concatenate(FilePath("graph_view/images/bundle.png")),
|
||||
true,
|
||||
false,
|
||||
isFocused,
|
||||
|
||||
@@ -228,19 +228,19 @@ FilePath NodeType::getIconPath() const
|
||||
if (isPackage())
|
||||
{
|
||||
// this icon cannot be changed
|
||||
return ResourcePaths::getGuiPath().concat(FilePath("graph_view/images/namespace.png"));
|
||||
return ResourcePaths::getGuiPath().concatenate(FilePath("graph_view/images/namespace.png"));
|
||||
}
|
||||
|
||||
switch (m_type)
|
||||
{
|
||||
case NodeType::NODE_ENUM:
|
||||
return ResourcePaths::getGuiPath().concat(FilePath("graph_view/images/enum.png"));
|
||||
return ResourcePaths::getGuiPath().concatenate(FilePath("graph_view/images/enum.png"));
|
||||
case NodeType::NODE_TYPEDEF:
|
||||
return ResourcePaths::getGuiPath().concat(FilePath("graph_view/images/typedef.png"));
|
||||
return ResourcePaths::getGuiPath().concatenate(FilePath("graph_view/images/typedef.png"));
|
||||
case NodeType::NODE_MACRO:
|
||||
return ResourcePaths::getGuiPath().concat(FilePath("graph_view/images/macro.png"));
|
||||
return ResourcePaths::getGuiPath().concatenate(FilePath("graph_view/images/macro.png"));
|
||||
case NodeType::NODE_FILE:
|
||||
return ResourcePaths::getGuiPath().concat(FilePath("graph_view/images/file.png"));
|
||||
return ResourcePaths::getGuiPath().concatenate(FilePath("graph_view/images/file.png"));
|
||||
default:
|
||||
return FilePath();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef NODE_TYPE_H
|
||||
#define NODE_TYPE_H
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
|
||||
@@ -14,16 +14,12 @@ ParseLocation::ParseLocation(
|
||||
uint lineNumber,
|
||||
uint columnNumber
|
||||
)
|
||||
: filePath(filePath)
|
||||
: filePath(filePath.getCanonical())
|
||||
, startLineNumber(lineNumber)
|
||||
, startColumnNumber(columnNumber)
|
||||
, endLineNumber(lineNumber)
|
||||
, endColumnNumber(columnNumber)
|
||||
{
|
||||
if (this->filePath.exists())
|
||||
{
|
||||
this->filePath = this->filePath.canonical();
|
||||
}
|
||||
}
|
||||
|
||||
ParseLocation::ParseLocation(
|
||||
@@ -31,16 +27,12 @@ ParseLocation::ParseLocation(
|
||||
uint startLineNumber, uint startColumnNumber,
|
||||
uint endLineNumber, uint endColumnNumber
|
||||
)
|
||||
: filePath(filePath)
|
||||
: filePath(filePath.getCanonical())
|
||||
, startLineNumber(startLineNumber)
|
||||
, startColumnNumber(startColumnNumber)
|
||||
, endLineNumber(endLineNumber)
|
||||
, endColumnNumber(endColumnNumber)
|
||||
{
|
||||
if (this->filePath.exists())
|
||||
{
|
||||
this->filePath = this->filePath.canonical();
|
||||
}
|
||||
}
|
||||
|
||||
bool ParseLocation::isValid() const
|
||||
|
||||
@@ -75,7 +75,7 @@ void PersistentStorage::addSymbol(const StorageSymbol& data)
|
||||
|
||||
void PersistentStorage::addFile(const StorageFile& data)
|
||||
{
|
||||
StorageFile storedFile = m_sqliteIndexStorage.getFirstById<StorageFile>(data.id);
|
||||
const StorageFile storedFile = m_sqliteIndexStorage.getFirstById<StorageFile>(data.id);
|
||||
|
||||
if (storedFile.id == 0)
|
||||
{
|
||||
@@ -90,7 +90,7 @@ void PersistentStorage::addFile(const StorageFile& data)
|
||||
|
||||
Id PersistentStorage::addEdge(const StorageEdgeData& data)
|
||||
{
|
||||
StorageEdge storedEdge = m_sqliteIndexStorage.getEdgeBySourceTargetType(data.sourceNodeId, data.targetNodeId, data.type);
|
||||
const StorageEdge storedEdge = m_sqliteIndexStorage.getEdgeBySourceTargetType(data.sourceNodeId, data.targetNodeId, data.type);
|
||||
if (storedEdge.id == 0)
|
||||
{
|
||||
return m_sqliteIndexStorage.addEdge(data).id;
|
||||
@@ -100,7 +100,7 @@ Id PersistentStorage::addEdge(const StorageEdgeData& data)
|
||||
|
||||
Id PersistentStorage::addLocalSymbol(const StorageLocalSymbolData& data)
|
||||
{
|
||||
StorageLocalSymbol storedLocalSymbol = m_sqliteIndexStorage.getLocalSymbolByName(data.name);
|
||||
const StorageLocalSymbol storedLocalSymbol = m_sqliteIndexStorage.getLocalSymbolByName(data.name);
|
||||
if (storedLocalSymbol.id == 0)
|
||||
{
|
||||
return m_sqliteIndexStorage.addLocalSymbol(data).id;
|
||||
@@ -451,8 +451,8 @@ Id PersistentStorage::getIdForEdge(
|
||||
Edge::EdgeType type, const NameHierarchy& fromNameHierarchy, const NameHierarchy& toNameHierarchy
|
||||
) const
|
||||
{
|
||||
Id sourceId = getNodeIdForNameHierarchy(fromNameHierarchy);
|
||||
Id targetId = getNodeIdForNameHierarchy(toNameHierarchy);
|
||||
const Id sourceId = getNodeIdForNameHierarchy(fromNameHierarchy);
|
||||
const Id targetId = getNodeIdForNameHierarchy(toNameHierarchy);
|
||||
return m_sqliteIndexStorage.getEdgeBySourceTargetType(sourceId, targetId, type).id;
|
||||
}
|
||||
|
||||
@@ -484,12 +484,11 @@ std::shared_ptr<SourceLocationCollection> PersistentStorage::getFullTextSearchLo
|
||||
false, true
|
||||
).dispatch();
|
||||
|
||||
std::vector<FullTextSearchResult> allHits = m_fullTextSearchIndex.searchForTerm(searchTerm);
|
||||
int termLength = searchTerm.length();
|
||||
const int termLength = searchTerm.length();
|
||||
|
||||
for (FullTextSearchResult fileHits : allHits)
|
||||
for (const FullTextSearchResult& fileHits : m_fullTextSearchIndex.searchForTerm(searchTerm))
|
||||
{
|
||||
FilePath filePath = getFileNodePath(fileHits.fileId);
|
||||
const FilePath filePath = getFileNodePath(fileHits.fileId);
|
||||
std::shared_ptr<TextAccess> fileContent = getFileContent(filePath);
|
||||
|
||||
int charsTotal = 0;
|
||||
@@ -525,7 +524,7 @@ std::shared_ptr<SourceLocationCollection> PersistentStorage::getFullTextSearchLo
|
||||
location.endColumnNumber = pos + termLength - charsTotal;
|
||||
|
||||
// Set first bit to 1 to avoid collisions
|
||||
Id locationId = ~(~Id(0) >> 1) + collection->getSourceLocationCount() + 1;
|
||||
const Id locationId = ~(~Id(0) >> 1) + collection->getSourceLocationCount() + 1;
|
||||
|
||||
collection->addSourceLocation(
|
||||
LOCATION_FULLTEXT_SEARCH,
|
||||
@@ -557,8 +556,8 @@ std::vector<SearchMatch> PersistentStorage::getAutocompletionMatches(const std::
|
||||
TRACE();
|
||||
|
||||
// search in indices
|
||||
size_t maxResultsCount = 100;
|
||||
size_t maxBestScoredResultsLength = 100;
|
||||
const size_t maxResultsCount = 100;
|
||||
const size_t maxBestScoredResultsLength = 100;
|
||||
|
||||
// create SearchMatches
|
||||
std::vector<SearchMatch> matches;
|
||||
@@ -603,7 +602,7 @@ std::vector<SearchMatch> PersistentStorage::getAutocompletionSymbolMatches(
|
||||
const std::string& query, const NodeTypeSet& acceptedNodeTypes, size_t maxResultsCount, size_t maxBestScoredResultsLength) const
|
||||
{
|
||||
// search in indices
|
||||
std::vector<SearchResult> results =
|
||||
const std::vector<SearchResult> results =
|
||||
m_symbolIndex.search(query, acceptedNodeTypes, maxResultsCount, maxBestScoredResultsLength);
|
||||
|
||||
// fetch StorageNodes for node ids
|
||||
@@ -685,7 +684,7 @@ std::vector<SearchMatch> PersistentStorage::getAutocompletionSymbolMatches(
|
||||
|
||||
std::vector<SearchMatch> PersistentStorage::getAutocompletionFileMatches(const std::string& query, size_t maxResultsCount) const
|
||||
{
|
||||
std::vector<SearchResult> results = m_fileIndex.search(
|
||||
const std::vector<SearchResult> results = m_fileIndex.search(
|
||||
query,
|
||||
NodeTypeSet::all().getWithMatchingKept([](const NodeType& type) { return type.isFile(); }),
|
||||
maxResultsCount,
|
||||
@@ -701,7 +700,7 @@ std::vector<SearchMatch> PersistentStorage::getAutocompletionFileMatches(const s
|
||||
match.name = result.text;
|
||||
match.tokenIds = utility::toVector(result.elementIds);
|
||||
|
||||
FilePath path(match.name);
|
||||
const FilePath path(match.name);
|
||||
match.text = path.fileName();
|
||||
match.subtext = path.str();
|
||||
|
||||
@@ -725,7 +724,7 @@ std::vector<SearchMatch> PersistentStorage::getAutocompletionCommandMatches(
|
||||
const std::string& query, NodeTypeSet acceptedNodeTypes) const
|
||||
{
|
||||
// search in indices
|
||||
std::vector<SearchResult> results = m_commandIndex.search(query, NodeTypeSet::all(), 0);
|
||||
const std::vector<SearchResult> results = m_commandIndex.search(query, NodeTypeSet::all(), 0);
|
||||
|
||||
// create SearchMatches
|
||||
std::vector<SearchMatch> matches;
|
||||
@@ -785,7 +784,7 @@ std::vector<SearchMatch> PersistentStorage::getSearchMatchesForTokenIds(const st
|
||||
StorageNode node = storageNodeMap[elementId];
|
||||
|
||||
SearchMatch match;
|
||||
NameHierarchy nameHierarchy = NameHierarchy::deserialize(node.serializedName);
|
||||
const NameHierarchy nameHierarchy = NameHierarchy::deserialize(node.serializedName);
|
||||
match.name = nameHierarchy.getQualifiedName();
|
||||
match.text = nameHierarchy.getRawName();
|
||||
|
||||
@@ -885,11 +884,11 @@ std::shared_ptr<Graph> PersistentStorage::getGraphForActiveTokenIds(
|
||||
if (tokenIds.size() == 1)
|
||||
{
|
||||
const Id elementId = tokenIds[0];
|
||||
StorageNode node = m_sqliteIndexStorage.getFirstById<StorageNode>(elementId);
|
||||
const StorageNode node = m_sqliteIndexStorage.getFirstById<StorageNode>(elementId);
|
||||
|
||||
if (node.id > 0)
|
||||
{
|
||||
NodeType nodeType = utility::intToType(node.type);
|
||||
const NodeType nodeType = utility::intToType(node.type);
|
||||
if (nodeType.isPackage())
|
||||
{
|
||||
ids.clear();
|
||||
@@ -911,8 +910,7 @@ std::shared_ptr<Graph> PersistentStorage::getGraphForActiveTokenIds(
|
||||
nodeIds.push_back(elementId);
|
||||
edgeIds.clear();
|
||||
|
||||
std::vector<StorageEdge> edges = m_sqliteIndexStorage.getEdgesBySourceOrTargetId(elementId);
|
||||
for (const StorageEdge& edge : edges)
|
||||
for (const StorageEdge& edge : m_sqliteIndexStorage.getEdgesBySourceOrTargetId(elementId))
|
||||
{
|
||||
Edge::EdgeType edgeType = Edge::intToType(edge.type);
|
||||
if (edgeType == Edge::EDGE_MEMBER)
|
||||
@@ -965,8 +963,7 @@ std::shared_ptr<Graph> PersistentStorage::getGraphForActiveTokenIds(
|
||||
{
|
||||
if (nodeIds.size() != ids.size())
|
||||
{
|
||||
std::vector<StorageEdge> edges = m_sqliteIndexStorage.getAllByIds<StorageEdge>(ids);
|
||||
for (const StorageEdge& edge : edges)
|
||||
for (const StorageEdge& edge : m_sqliteIndexStorage.getAllByIds<StorageEdge>(ids))
|
||||
{
|
||||
if (edge.id > 0)
|
||||
{
|
||||
@@ -1082,8 +1079,8 @@ std::shared_ptr<Graph> PersistentStorage::getGraphForTrail(
|
||||
{
|
||||
bool isForward = forward == !(Edge::intToType(edge.type) & (Edge::EDGE_OVERRIDE | Edge::EDGE_INHERITANCE));
|
||||
|
||||
Id nodeId = isForward ? edge.targetNodeId : edge.sourceNodeId;
|
||||
Id otherNodeId = isForward ? edge.sourceNodeId : edge.targetNodeId;
|
||||
const Id nodeId = isForward ? edge.targetNodeId : edge.sourceNodeId;
|
||||
const Id otherNodeId = isForward ? edge.sourceNodeId : edge.targetNodeId;
|
||||
|
||||
if (nodeIds.find(nodeId) == nodeIds.end())
|
||||
{
|
||||
@@ -1127,7 +1124,7 @@ std::vector<Id> PersistentStorage::getActiveTokenIdsForId(Id tokenId, Id* declar
|
||||
{
|
||||
*declarationId = tokenId;
|
||||
|
||||
std::vector<StorageEdge> incomingEdges = m_sqliteIndexStorage.getEdgesByTargetId(tokenId);
|
||||
const std::vector<StorageEdge> incomingEdges = m_sqliteIndexStorage.getEdgesByTargetId(tokenId);
|
||||
for (size_t i = 0; i < incomingEdges.size(); i++)
|
||||
{
|
||||
activeTokenIds.push_back(incomingEdges[i].id);
|
||||
@@ -1150,7 +1147,7 @@ std::vector<Id> PersistentStorage::getNodeIdsForLocationIds(const std::vector<Id
|
||||
{
|
||||
const Id elementId = occurrence.elementId;
|
||||
|
||||
StorageEdge edge = m_sqliteIndexStorage.getFirstById<StorageEdge>(elementId);
|
||||
const StorageEdge edge = m_sqliteIndexStorage.getFirstById<StorageEdge>(elementId);
|
||||
if (edge.id != 0)
|
||||
{
|
||||
auto it = m_symbolDefinitionKinds.find(edge.targetNodeId);
|
||||
@@ -1210,7 +1207,7 @@ std::shared_ptr<SourceLocationCollection> PersistentStorage::getSourceLocationsF
|
||||
// check for non-indexed file
|
||||
if (path.empty() && m_symbolDefinitionKinds.find(tokenId) == m_symbolDefinitionKinds.end())
|
||||
{
|
||||
StorageNode fileNode = m_sqliteIndexStorage.getNodeById(tokenId);
|
||||
const StorageNode fileNode = m_sqliteIndexStorage.getNodeById(tokenId);
|
||||
if (NodeType(utility::intToType(fileNode.type)).isFile())
|
||||
{
|
||||
path = FilePath(NameHierarchy::deserialize(fileNode.serializedName).getQualifiedName());
|
||||
@@ -1248,7 +1245,7 @@ std::shared_ptr<SourceLocationCollection> PersistentStorage::getSourceLocationsF
|
||||
auto it = locationIdToElementIdMap.find(sourceLocation.id);
|
||||
if (it != locationIdToElementIdMap.end())
|
||||
{
|
||||
LocationType type = intToLocationType(sourceLocation.type);
|
||||
const LocationType type = intToLocationType(sourceLocation.type);
|
||||
if (type == LOCATION_QUALIFIER)
|
||||
{
|
||||
continue;
|
||||
@@ -1257,10 +1254,10 @@ std::shared_ptr<SourceLocationCollection> PersistentStorage::getSourceLocationsF
|
||||
FilePath path = getFileNodePath(sourceLocation.fileNodeId);
|
||||
if (path.empty())
|
||||
{
|
||||
StorageNode fileNode = m_sqliteIndexStorage.getNodeById(sourceLocation.fileNodeId);
|
||||
const StorageNode fileNode = m_sqliteIndexStorage.getNodeById(sourceLocation.fileNodeId);
|
||||
if (fileNode.id)
|
||||
{
|
||||
FilePath path2 = FilePath(NameHierarchy::deserialize(fileNode.serializedName).getQualifiedName());
|
||||
const FilePath path2 = FilePath(NameHierarchy::deserialize(fileNode.serializedName).getQualifiedName());
|
||||
if (path2.exists())
|
||||
{
|
||||
path = path2;
|
||||
@@ -1343,9 +1340,9 @@ std::shared_ptr<SourceLocationFile> PersistentStorage::getCommentLocationsInFile
|
||||
{
|
||||
TRACE();
|
||||
|
||||
std::shared_ptr<SourceLocationFile> file = std::make_shared<SourceLocationFile>(filePath, false, false);
|
||||
const std::shared_ptr<SourceLocationFile> file = std::make_shared<SourceLocationFile>(filePath, false, false);
|
||||
|
||||
std::vector<StorageCommentLocation> storageLocations = m_sqliteIndexStorage.getCommentLocationsInFile(filePath);
|
||||
const std::vector<StorageCommentLocation> storageLocations = m_sqliteIndexStorage.getCommentLocationsInFile(filePath);
|
||||
for (size_t i = 0; i < storageLocations.size(); i++)
|
||||
{
|
||||
file->addSourceLocation(
|
||||
@@ -1378,8 +1375,7 @@ std::vector<FileInfo> PersistentStorage::getFileInfosForFilePaths(const std::vec
|
||||
{
|
||||
std::vector<FileInfo> fileInfos;
|
||||
|
||||
std::vector<StorageFile> storageFiles = m_sqliteIndexStorage.getFilesByPaths(filePaths);
|
||||
for (const StorageFile& file : storageFiles)
|
||||
for (const StorageFile& file : m_sqliteIndexStorage.getFilesByPaths(filePaths))
|
||||
{
|
||||
fileInfos.push_back(FileInfo(FilePath(file.filePath), file.modificationTime));
|
||||
}
|
||||
@@ -1692,7 +1688,7 @@ TooltipInfo PersistentStorage::getTooltipInfoForTokenIds(const std::vector<Id>&
|
||||
StorageNode node = m_sqliteIndexStorage.getFirstById<StorageNode>(tokenIds[0]);
|
||||
if (node.id == 0 && origin == TOOLTIP_ORIGIN_CODE)
|
||||
{
|
||||
StorageEdge edge = m_sqliteIndexStorage.getFirstById<StorageEdge>(tokenIds[0]);
|
||||
const StorageEdge edge = m_sqliteIndexStorage.getFirstById<StorageEdge>(tokenIds[0]);
|
||||
|
||||
if (edge.id > 0)
|
||||
{
|
||||
@@ -1705,11 +1701,11 @@ TooltipInfo PersistentStorage::getTooltipInfoForTokenIds(const std::vector<Id>&
|
||||
return info;
|
||||
}
|
||||
|
||||
NodeType type = utility::intToType(node.type);
|
||||
const NodeType type = utility::intToType(node.type);
|
||||
info.title = type.getReadableTypeString();
|
||||
|
||||
DefinitionKind defKind = DEFINITION_NONE;
|
||||
StorageSymbol symbol = m_sqliteIndexStorage.getFirstById<StorageSymbol>(node.id);
|
||||
const StorageSymbol symbol = m_sqliteIndexStorage.getFirstById<StorageSymbol>(node.id);
|
||||
if (symbol.id > 0)
|
||||
{
|
||||
defKind = intToDefinitionKind(symbol.definitionKind);
|
||||
@@ -1717,7 +1713,7 @@ TooltipInfo PersistentStorage::getTooltipInfoForTokenIds(const std::vector<Id>&
|
||||
|
||||
if (type.isPotentialMember())
|
||||
{
|
||||
StorageComponentAccess access = m_sqliteIndexStorage.getComponentAccessByNodeId(node.id);
|
||||
const StorageComponentAccess access = m_sqliteIndexStorage.getComponentAccessByNodeId(node.id);
|
||||
if (access.nodeId != 0)
|
||||
{
|
||||
info.title = accessKindToString(intToAccessKind(access.type)) + " " + info.title;
|
||||
@@ -1768,8 +1764,8 @@ TooltipSnippet PersistentStorage::getTooltipSnippetForNode(const StorageNode& no
|
||||
{
|
||||
TRACE();
|
||||
|
||||
const NameHierarchy nameHierarchy = NameHierarchy::deserialize(node.serializedName);
|
||||
TooltipSnippet snippet;
|
||||
NameHierarchy nameHierarchy = NameHierarchy::deserialize(node.serializedName);
|
||||
snippet.code = nameHierarchy.getQualifiedNameWithSignature();
|
||||
snippet.locationFile = std::make_shared<SourceLocationFile>(
|
||||
FilePath(nameHierarchy.getDelimiter() == NAME_DELIMITER_JAVA ? "main.java" : "main.cpp"), true, true);
|
||||
@@ -2093,7 +2089,7 @@ std::set<Id> PersistentStorage::getReferencing(
|
||||
|
||||
std::set<FilePath> PersistentStorage::getReferencedByIncludes(const std::set<FilePath>& filePaths)
|
||||
{
|
||||
std::set<Id> ids = getReferenced(getFileNodeIds(filePaths), getFileIdToIncludingFileIdMap());
|
||||
const std::set<Id> ids = getReferenced(getFileNodeIds(filePaths), getFileIdToIncludingFileIdMap());
|
||||
|
||||
std::set<FilePath> paths;
|
||||
for (Id id: ids)
|
||||
@@ -2106,7 +2102,7 @@ std::set<FilePath> PersistentStorage::getReferencedByIncludes(const std::set<Fil
|
||||
|
||||
std::set<FilePath> PersistentStorage::getReferencedByImports(const std::set<FilePath>& filePaths)
|
||||
{
|
||||
std::set<Id> ids = getReferenced(getFileNodeIds(filePaths), getFileIdToImportingFileIdMap());
|
||||
const std::set<Id> ids = getReferenced(getFileNodeIds(filePaths), getFileIdToImportingFileIdMap());
|
||||
|
||||
std::set<FilePath> paths;
|
||||
for (Id id: ids)
|
||||
@@ -2119,7 +2115,7 @@ std::set<FilePath> PersistentStorage::getReferencedByImports(const std::set<File
|
||||
|
||||
std::set<FilePath> PersistentStorage::getReferencingByIncludes(const std::set<FilePath>& filePaths)
|
||||
{
|
||||
std::set<Id> ids = getReferencing(getFileNodeIds(filePaths), getFileIdToIncludingFileIdMap());
|
||||
const std::set<Id> ids = getReferencing(getFileNodeIds(filePaths), getFileIdToIncludingFileIdMap());
|
||||
|
||||
std::set<FilePath> paths;
|
||||
for (Id id: ids)
|
||||
@@ -2132,7 +2128,7 @@ std::set<FilePath> PersistentStorage::getReferencingByIncludes(const std::set<Fi
|
||||
|
||||
std::set<FilePath> PersistentStorage::getReferencingByImports(const std::set<FilePath>& filePaths)
|
||||
{
|
||||
std::set<Id> ids = getReferencing(getFileNodeIds(filePaths), getFileIdToImportingFileIdMap());
|
||||
const std::set<Id> ids = getReferencing(getFileNodeIds(filePaths), getFileIdToImportingFileIdMap());
|
||||
|
||||
std::set<FilePath> paths;
|
||||
for (Id id: ids)
|
||||
@@ -2316,7 +2312,7 @@ void PersistentStorage::addAggregationEdgesToGraph(
|
||||
// get all children of the active node
|
||||
std::set<Id> childNodeIdsSet, edgeIdsSet;
|
||||
m_hierarchyCache.addAllChildIdsForNodeId(nodeId, &childNodeIdsSet, &edgeIdsSet);
|
||||
std::vector<Id> childNodeIds = utility::toVector(childNodeIdsSet);
|
||||
const std::vector<Id> childNodeIds = utility::toVector(childNodeIdsSet);
|
||||
if (childNodeIds.size() == 0 && edgesToAggregate.size() == 0)
|
||||
{
|
||||
return;
|
||||
@@ -2333,7 +2329,7 @@ void PersistentStorage::addAggregationEdgesToGraph(
|
||||
connectedNodeIds[isSource ? edge.targetNodeId : edge.sourceNodeId].push_back(edgeInfo);
|
||||
}
|
||||
|
||||
std::vector<StorageEdge> outgoingEdges = m_sqliteIndexStorage.getEdgesBySourceIds(childNodeIds);
|
||||
const std::vector<StorageEdge> outgoingEdges = m_sqliteIndexStorage.getEdgesBySourceIds(childNodeIds);
|
||||
for (const StorageEdge& outEdge : outgoingEdges)
|
||||
{
|
||||
EdgeInfo edgeInfo;
|
||||
@@ -2342,7 +2338,7 @@ void PersistentStorage::addAggregationEdgesToGraph(
|
||||
connectedNodeIds[outEdge.targetNodeId].push_back(edgeInfo);
|
||||
}
|
||||
|
||||
std::vector<StorageEdge> incomingEdges = m_sqliteIndexStorage.getEdgesByTargetIds(childNodeIds);
|
||||
const std::vector<StorageEdge> incomingEdges = m_sqliteIndexStorage.getEdgesByTargetIds(childNodeIds);
|
||||
for (const StorageEdge& inEdge : incomingEdges)
|
||||
{
|
||||
EdgeInfo edgeInfo;
|
||||
@@ -2352,12 +2348,12 @@ void PersistentStorage::addAggregationEdgesToGraph(
|
||||
}
|
||||
|
||||
// get all parent nodes of all connected nodes (up to last level except namespace/undefined)
|
||||
Id nodeParentNodeId = m_hierarchyCache.getLastVisibleParentNodeId(nodeId);
|
||||
const Id nodeParentNodeId = m_hierarchyCache.getLastVisibleParentNodeId(nodeId);
|
||||
|
||||
std::map<Id, std::vector<EdgeInfo>> connectedParentNodeIds;
|
||||
for (const std::pair<Id, std::vector<EdgeInfo>>& p : connectedNodeIds)
|
||||
{
|
||||
Id parentNodeId = m_hierarchyCache.getLastVisibleParentNodeId(p.first);
|
||||
const Id parentNodeId = m_hierarchyCache.getLastVisibleParentNodeId(p.first);
|
||||
|
||||
if (parentNodeId != nodeParentNodeId)
|
||||
{
|
||||
@@ -2396,7 +2392,7 @@ void PersistentStorage::addAggregationEdgesToGraph(
|
||||
}
|
||||
|
||||
// Set first bit to 1 to avoid collisions
|
||||
Id aggregationId = ~(~Id(0) >> 1) + *componentAggregation->getAggregationIds().begin();
|
||||
const Id aggregationId = ~(~Id(0) >> 1) + *componentAggregation->getAggregationIds().begin();
|
||||
|
||||
Edge* edge = graph->createEdge(aggregationId, Edge::EDGE_AGGREGATION, sourceNode, targetNode);
|
||||
edge->addComponentAggregation(componentAggregation);
|
||||
@@ -2483,9 +2479,9 @@ void PersistentStorage::addInheritanceChainsToGraph(const std::vector<Id>& activ
|
||||
for (const std::tuple<Id, Id, std::vector<Id>>& edge :
|
||||
m_hierarchyCache.getInheritanceEdgesForNodeId(nodeId, *nodeIdSets[(i + 1) % 2]))
|
||||
{
|
||||
Id sourceId = std::get<0>(edge);
|
||||
Id targetId = std::get<1>(edge);
|
||||
std::vector<Id> edgeIds = std::get<2>(edge);
|
||||
const Id sourceId = std::get<0>(edge);
|
||||
const Id targetId = std::get<1>(edge);
|
||||
const std::vector<Id> edgeIds = std::get<2>(edge);
|
||||
|
||||
if (!edgeIds.size() || (edgeIds.size() == 1 && graph->getEdgeById(edgeIds[0])))
|
||||
{
|
||||
@@ -2493,7 +2489,7 @@ void PersistentStorage::addInheritanceChainsToGraph(const std::vector<Id>& activ
|
||||
}
|
||||
|
||||
// Set first 2 bits to 1 to avoid collisions
|
||||
Id inheritanceEdgeId = ~(~Id(0) >> 2) + inheritanceEdgeCount++;
|
||||
const Id inheritanceEdgeId = ~(~Id(0) >> 2) + inheritanceEdgeCount++;
|
||||
|
||||
Edge* inheritanceEdge = graph->createEdge(
|
||||
inheritanceEdgeId, Edge::EDGE_INHERITANCE, graph->getNodeById(sourceId), graph->getNodeById(targetId));
|
||||
@@ -2510,7 +2506,7 @@ void PersistentStorage::buildFilePathMaps()
|
||||
|
||||
for (StorageFile& file: m_sqliteIndexStorage.getAll<StorageFile>())
|
||||
{
|
||||
FilePath path = FilePath(file.filePath);
|
||||
const FilePath path(file.filePath);
|
||||
|
||||
m_fileNodeIds.emplace(path, file.id);
|
||||
m_fileNodePaths.emplace(file.id, path);
|
||||
@@ -2532,7 +2528,7 @@ void PersistentStorage::buildSearchIndex()
|
||||
{
|
||||
TRACE();
|
||||
|
||||
FilePath dbPath = getDbFilePath();
|
||||
const FilePath dbPath = getDbFilePath();
|
||||
|
||||
for (StorageNode& node : m_sqliteIndexStorage.getAll<StorageNode>())
|
||||
{
|
||||
@@ -2546,7 +2542,7 @@ void PersistentStorage::buildSearchIndex()
|
||||
|
||||
if (filePath.exists())
|
||||
{
|
||||
filePath = filePath.relativeTo(dbPath);
|
||||
filePath.makeRelativeTo(dbPath);
|
||||
}
|
||||
|
||||
m_fileIndex.addNode(node.id, filePath.str(), type);
|
||||
@@ -2555,10 +2551,10 @@ void PersistentStorage::buildSearchIndex()
|
||||
else
|
||||
{
|
||||
auto it = m_symbolDefinitionKinds.find(node.id);
|
||||
DefinitionKind defKind = (it != m_symbolDefinitionKinds.end() ? it->second : DEFINITION_NONE);
|
||||
const DefinitionKind defKind = (it != m_symbolDefinitionKinds.end() ? it->second : DEFINITION_NONE);
|
||||
if (defKind != DEFINITION_IMPLICIT)
|
||||
{
|
||||
NameHierarchy nameHierarchy = NameHierarchy::deserialize(node.serializedName);
|
||||
const NameHierarchy nameHierarchy = NameHierarchy::deserialize(node.serializedName);
|
||||
|
||||
// we don't use the signature here, so elements with the same signature share the same node.
|
||||
std::string name = nameHierarchy.getQualifiedName();
|
||||
@@ -2618,13 +2614,13 @@ void PersistentStorage::buildMemberEdgeIdOrderMap()
|
||||
SourceLocationCollection collection;
|
||||
for (const StorageSourceLocation& location: m_sqliteIndexStorage.getAllByIds<StorageSourceLocation>(locationIds))
|
||||
{
|
||||
LocationType locType = intToLocationType(location.type);
|
||||
const LocationType locType = intToLocationType(location.type);
|
||||
if (locType != LOCATION_TOKEN)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
FilePath path(m_fileNodePaths[location.fileNodeId]);
|
||||
const FilePath path(m_fileNodePaths[location.fileNodeId]);
|
||||
if (path.extension() == ".java")
|
||||
{
|
||||
collection.addSourceLocation(
|
||||
@@ -2666,7 +2662,7 @@ void PersistentStorage::buildHierarchyCache()
|
||||
{
|
||||
TRACE();
|
||||
|
||||
std::vector<StorageEdge> memberEdges = m_sqliteIndexStorage.getEdgesByType(Edge::typeToInt(Edge::EDGE_MEMBER));
|
||||
const std::vector<StorageEdge> memberEdges = m_sqliteIndexStorage.getEdgesByType(Edge::typeToInt(Edge::EDGE_MEMBER));
|
||||
|
||||
std::vector<Id> sourceNodeIds;
|
||||
for (const StorageEdge& edge : memberEdges)
|
||||
@@ -2674,10 +2670,8 @@ void PersistentStorage::buildHierarchyCache()
|
||||
sourceNodeIds.push_back(edge.sourceNodeId);
|
||||
}
|
||||
|
||||
std::vector<StorageNode> sourceNodes = m_sqliteIndexStorage.getAllByIds<StorageNode>(sourceNodeIds);
|
||||
|
||||
std::map<Id, NodeType> sourceNodeTypeMap;
|
||||
for (const StorageNode& node : sourceNodes)
|
||||
for (const StorageNode& node : m_sqliteIndexStorage.getAllByIds<StorageNode>(sourceNodeIds))
|
||||
{
|
||||
sourceNodeTypeMap.emplace(node.id, utility::intToType(node.type));
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
const size_t SqliteIndexStorage::s_storageVersion = 15;
|
||||
|
||||
SqliteIndexStorage::SqliteIndexStorage(const FilePath& dbFilePath)
|
||||
: SqliteStorage(dbFilePath.canonical())
|
||||
: SqliteStorage(dbFilePath.getCanonical())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "utility/TimeStamp.h"
|
||||
|
||||
SqliteStorage::SqliteStorage(const FilePath& dbFilePath)
|
||||
: m_dbFilePath(dbFilePath.canonical())
|
||||
: m_dbFilePath(dbFilePath.getCanonical())
|
||||
{
|
||||
m_database.open(m_dbFilePath.str().c_str());
|
||||
|
||||
|
||||
@@ -149,7 +149,7 @@ void ApplicationSettings::setShowBuiltinTypesInGraph(bool showBuiltinTypes)
|
||||
|
||||
FilePath ApplicationSettings::getColorSchemePath() const
|
||||
{
|
||||
FilePath defaultPath(ResourcePaths::getColorSchemesPath().concat(FilePath("bright.xml")));
|
||||
FilePath defaultPath(ResourcePaths::getColorSchemesPath().concatenate(FilePath("bright.xml")));
|
||||
FilePath path(getValue<std::string>("application/color_scheme", defaultPath.str()));
|
||||
|
||||
if (path != defaultPath && !path.exists())
|
||||
@@ -423,7 +423,7 @@ std::vector<FilePath> ApplicationSettings::getRecentProjects() const
|
||||
}
|
||||
else
|
||||
{
|
||||
recentProjects.push_back(UserPaths::getUserDataPath().concat(project));
|
||||
recentProjects.push_back(UserPaths::getUserDataPath().concatenate(project));
|
||||
}
|
||||
}
|
||||
return recentProjects;
|
||||
|
||||
@@ -126,7 +126,7 @@ std::string ProjectSettings::getProjectName() const
|
||||
|
||||
FilePath ProjectSettings::getProjectDirectoryPath() const
|
||||
{
|
||||
return getFilePath().parentDirectory();
|
||||
return getFilePath().getParentDirectory();
|
||||
}
|
||||
|
||||
std::string ProjectSettings::getDescription() const
|
||||
@@ -204,7 +204,7 @@ std::vector<FilePath> ProjectSettings::makePathsExpandedAndAbsolute(const std::v
|
||||
std::vector<FilePath> p = expandPaths(paths);
|
||||
|
||||
std::vector<FilePath> absPaths;
|
||||
FilePath basePath = getProjectDirectoryPath();
|
||||
const FilePath basePath = getProjectDirectoryPath();
|
||||
for (const FilePath& path : p)
|
||||
{
|
||||
if (path.isAbsolute())
|
||||
@@ -213,7 +213,7 @@ std::vector<FilePath> ProjectSettings::makePathsExpandedAndAbsolute(const std::v
|
||||
}
|
||||
else
|
||||
{
|
||||
absPaths.push_back(basePath.concat(path).canonical());
|
||||
absPaths.push_back(basePath.getConcatenated(path).makeCanonical());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,7 +229,7 @@ FilePath ProjectSettings::makePathExpandedAndAbsolute(const FilePath& path) cons
|
||||
return p;
|
||||
}
|
||||
|
||||
return getProjectDirectoryPath().concat(p).canonical();
|
||||
return getProjectDirectoryPath().concatenate(p).makeCanonical();
|
||||
}
|
||||
|
||||
SettingsMigrator ProjectSettings::getMigrations() const
|
||||
|
||||
@@ -14,15 +14,15 @@ void UserPaths::setUserDataPath(const FilePath& path)
|
||||
|
||||
FilePath UserPaths::getAppSettingsPath()
|
||||
{
|
||||
return getUserDataPath().concat(FilePath("ApplicationSettings.xml"));
|
||||
return getUserDataPath().concatenate(FilePath("ApplicationSettings.xml"));
|
||||
}
|
||||
|
||||
FilePath UserPaths::getWindowSettingsPath()
|
||||
{
|
||||
return getUserDataPath().concat(FilePath("window_settings.ini"));
|
||||
return getUserDataPath().concatenate(FilePath("window_settings.ini"));
|
||||
}
|
||||
|
||||
FilePath UserPaths::getLogPath()
|
||||
{
|
||||
return getUserDataPath().concat(FilePath("log/"));
|
||||
return getUserDataPath().concatenate(FilePath("log/"));
|
||||
}
|
||||
|
||||
@@ -218,7 +218,8 @@ bool CommandLineParser::startedWithLicense()
|
||||
|
||||
void CommandLineParser::processProjectfile()
|
||||
{
|
||||
m_projectFile = m_projectFile.absolute();
|
||||
m_projectFile.makeAbsolute();
|
||||
|
||||
const std::string errorstring =
|
||||
"Provided Projectfile is not valid:\n* Provided Projectfile('" + m_projectFile.fileName() + "') ";
|
||||
if (!m_projectFile.exists())
|
||||
|
||||
@@ -63,7 +63,7 @@ std::set<FilePath> FileManager::getAllSourceFilePathsRelative(const FilePath& ba
|
||||
{
|
||||
if (baseDirectory.exists())
|
||||
{
|
||||
absolutePaths.insert(path.relativeTo(baseDirectory));
|
||||
absolutePaths.insert(path.getRelativeTo(baseDirectory));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -78,7 +78,7 @@ std::vector<FilePath> FileManager::makeCanonical(const std::vector<FilePath>& fi
|
||||
std::vector<FilePath> ret;
|
||||
for (const FilePath& filePath: filePaths)
|
||||
{
|
||||
ret.push_back(filePath.canonical());
|
||||
ret.push_back(filePath.getCanonical());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -2,13 +2,14 @@
|
||||
|
||||
#include <regex>
|
||||
|
||||
#include "boost/filesystem/path.hpp"
|
||||
#include "boost/filesystem.hpp"
|
||||
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/utilityString.h"
|
||||
|
||||
FilePath::FilePath()
|
||||
: m_path("")
|
||||
: m_path(std::make_unique<boost::filesystem::path>(""))
|
||||
, m_exists(false)
|
||||
, m_checkedExists(false)
|
||||
, m_isDirectory(false)
|
||||
@@ -18,7 +19,7 @@ FilePath::FilePath()
|
||||
}
|
||||
|
||||
FilePath::FilePath(const char* filePath)
|
||||
: m_path(filePath)
|
||||
: m_path(std::make_unique<boost::filesystem::path>(filePath))
|
||||
, m_exists(false)
|
||||
, m_checkedExists(false)
|
||||
, m_isDirectory(false)
|
||||
@@ -28,7 +29,7 @@ FilePath::FilePath(const char* filePath)
|
||||
}
|
||||
|
||||
FilePath::FilePath(const std::string& filePath)
|
||||
: m_path(filePath)
|
||||
: m_path(std::make_unique<boost::filesystem::path>(filePath))
|
||||
, m_exists(false)
|
||||
, m_checkedExists(false)
|
||||
, m_isDirectory(false)
|
||||
@@ -38,7 +39,7 @@ FilePath::FilePath(const std::string& filePath)
|
||||
}
|
||||
|
||||
FilePath::FilePath(const boost::filesystem::path& filePath)
|
||||
: m_path(filePath)
|
||||
: m_path(std::make_unique<boost::filesystem::path>(filePath))
|
||||
, m_exists(false)
|
||||
, m_checkedExists(false)
|
||||
, m_isDirectory(false)
|
||||
@@ -47,8 +48,28 @@ FilePath::FilePath(const boost::filesystem::path& filePath)
|
||||
{
|
||||
}
|
||||
|
||||
FilePath::FilePath(const FilePath& other)
|
||||
: m_path(std::make_unique<boost::filesystem::path>(other.getPath()))
|
||||
, m_exists(other.m_exists)
|
||||
, m_checkedExists(other.m_checkedExists)
|
||||
, m_isDirectory(other.m_isDirectory)
|
||||
, m_checkedIsDirectory(other.m_checkedIsDirectory)
|
||||
, m_canonicalized(other.m_canonicalized)
|
||||
{
|
||||
}
|
||||
|
||||
FilePath::FilePath(FilePath&& other)
|
||||
: m_path(std::move(other.m_path))
|
||||
, m_exists(other.m_exists)
|
||||
, m_checkedExists(other.m_checkedExists)
|
||||
, m_isDirectory(other.m_isDirectory)
|
||||
, m_checkedIsDirectory(other.m_checkedIsDirectory)
|
||||
, m_canonicalized(other.m_canonicalized)
|
||||
{
|
||||
}
|
||||
|
||||
FilePath::FilePath(const std::string& filePath, const std::string& base)
|
||||
: m_path(boost::filesystem::absolute(filePath, base))
|
||||
: m_path(std::make_unique<boost::filesystem::path>(boost::filesystem::absolute(filePath, base)))
|
||||
, m_exists(false)
|
||||
, m_checkedExists(false)
|
||||
, m_isDirectory(false)
|
||||
@@ -57,21 +78,25 @@ FilePath::FilePath(const std::string& filePath, const std::string& base)
|
||||
{
|
||||
}
|
||||
|
||||
boost::filesystem::path FilePath::path() const
|
||||
FilePath::~FilePath()
|
||||
{
|
||||
return m_path;
|
||||
}
|
||||
|
||||
boost::filesystem::path FilePath::getPath() const
|
||||
{
|
||||
return boost::filesystem::path(*(m_path.get()));
|
||||
}
|
||||
|
||||
bool FilePath::empty() const
|
||||
{
|
||||
return m_path.empty();
|
||||
return m_path->empty();
|
||||
}
|
||||
|
||||
bool FilePath::exists() const
|
||||
{
|
||||
if (!m_checkedExists)
|
||||
{
|
||||
m_exists = boost::filesystem::exists(m_path);
|
||||
m_exists = boost::filesystem::exists(getPath());
|
||||
m_checkedExists = true;
|
||||
}
|
||||
|
||||
@@ -88,7 +113,7 @@ bool FilePath::isDirectory() const
|
||||
{
|
||||
if (!m_checkedIsDirectory)
|
||||
{
|
||||
m_isDirectory = boost::filesystem::is_directory(m_path);
|
||||
m_isDirectory = boost::filesystem::is_directory(getPath());
|
||||
m_checkedIsDirectory = true;
|
||||
}
|
||||
|
||||
@@ -97,12 +122,12 @@ bool FilePath::isDirectory() const
|
||||
|
||||
bool FilePath::isAbsolute() const
|
||||
{
|
||||
return m_path.is_absolute();
|
||||
return m_path->is_absolute();
|
||||
}
|
||||
|
||||
FilePath FilePath::parentDirectory() const
|
||||
FilePath FilePath::getParentDirectory() const
|
||||
{
|
||||
FilePath parentDirectory(m_path.parent_path());
|
||||
FilePath parentDirectory(m_path->parent_path());
|
||||
parentDirectory.m_checkedIsDirectory = true;
|
||||
parentDirectory.m_isDirectory = true;
|
||||
|
||||
@@ -111,25 +136,34 @@ FilePath FilePath::parentDirectory() const
|
||||
parentDirectory.m_checkedExists = true;
|
||||
parentDirectory.m_exists = true;
|
||||
}
|
||||
|
||||
return parentDirectory;
|
||||
}
|
||||
|
||||
FilePath FilePath::absolute() const
|
||||
FilePath& FilePath::makeAbsolute()
|
||||
{
|
||||
return FilePath(boost::filesystem::absolute(m_path));
|
||||
m_path = std::make_unique<boost::filesystem::path>(boost::filesystem::absolute(getPath()));
|
||||
return *this;
|
||||
}
|
||||
|
||||
FilePath FilePath::canonical() const
|
||||
FilePath FilePath::getAbsolute() const
|
||||
{
|
||||
FilePath path(*this);
|
||||
path.makeAbsolute();
|
||||
return path;
|
||||
}
|
||||
|
||||
FilePath& FilePath::makeCanonical()
|
||||
{
|
||||
if (m_canonicalized || !exists())
|
||||
{
|
||||
return FilePath(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
boost::filesystem::path canonicalPath;
|
||||
|
||||
#if defined(_WIN32)
|
||||
boost::filesystem::path abs_p = boost::filesystem::absolute(m_path);
|
||||
boost::filesystem::path abs_p = boost::filesystem::absolute(getPath());
|
||||
for (boost::filesystem::path::iterator it = abs_p.begin(); it != abs_p.end(); ++it)
|
||||
{
|
||||
if (*it == "..")
|
||||
@@ -158,12 +192,18 @@ FilePath FilePath::canonical() const
|
||||
}
|
||||
}
|
||||
#else
|
||||
canonicalPath = boost::filesystem::canonical(m_path);
|
||||
canonicalPath = boost::filesystem::canonical(getPath());
|
||||
#endif
|
||||
m_path = std::make_unique<boost::filesystem::path>(canonicalPath);
|
||||
m_canonicalized = true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
FilePath ret(canonicalPath);
|
||||
ret.m_canonicalized = true;
|
||||
return ret;
|
||||
FilePath FilePath::getCanonical() const
|
||||
{
|
||||
FilePath path(*this);
|
||||
path.makeCanonical();
|
||||
return path;
|
||||
}
|
||||
|
||||
std::vector<FilePath> FilePath::expandEnvironmentVariables() const
|
||||
@@ -201,10 +241,10 @@ std::vector<FilePath> FilePath::expandEnvironmentVariables() const
|
||||
return paths;
|
||||
}
|
||||
|
||||
FilePath FilePath::relativeTo(const FilePath& other) const
|
||||
FilePath& FilePath::makeRelativeTo(const FilePath& other)
|
||||
{
|
||||
boost::filesystem::path a = this->canonical().m_path;
|
||||
boost::filesystem::path b = other.canonical().m_path;
|
||||
const boost::filesystem::path a = this->getCanonical().getPath();
|
||||
const boost::filesystem::path b = other.getCanonical().getPath();
|
||||
|
||||
if (a.root_path() != b.root_path())
|
||||
{
|
||||
@@ -245,12 +285,35 @@ FilePath FilePath::relativeTo(const FilePath& other) const
|
||||
r = "./";
|
||||
}
|
||||
|
||||
return FilePath(r);
|
||||
m_path = std::make_unique<boost::filesystem::path>(r);
|
||||
return *this;
|
||||
}
|
||||
|
||||
FilePath FilePath::concat(const FilePath& other) const
|
||||
|
||||
FilePath FilePath::getRelativeTo(const FilePath& other) const
|
||||
{
|
||||
return FilePath(boost::filesystem::path(m_path) / other.m_path);
|
||||
FilePath path(*this);
|
||||
path.makeRelativeTo(other);
|
||||
return path;
|
||||
}
|
||||
|
||||
FilePath& FilePath::concatenate(const FilePath& other)
|
||||
{
|
||||
m_path->operator/=(other.getPath());
|
||||
m_exists = false;
|
||||
m_checkedExists = false;
|
||||
m_isDirectory = false;
|
||||
m_checkedIsDirectory = false;
|
||||
m_canonicalized = false;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
FilePath FilePath::getConcatenated(const FilePath& other) const
|
||||
{
|
||||
FilePath path(*this);
|
||||
path.concatenate(other);
|
||||
return path;
|
||||
}
|
||||
|
||||
bool FilePath::contains(const FilePath& other) const
|
||||
@@ -260,8 +323,8 @@ bool FilePath::contains(const FilePath& other) const
|
||||
return false;
|
||||
}
|
||||
|
||||
boost::filesystem::path dir = m_path;
|
||||
const boost::filesystem::path& dir2 = other.m_path;
|
||||
boost::filesystem::path dir = getPath();
|
||||
const std::unique_ptr<boost::filesystem::path>& dir2 = other.m_path;
|
||||
|
||||
if (dir.filename() == ".")
|
||||
{
|
||||
@@ -269,11 +332,11 @@ bool FilePath::contains(const FilePath& other) const
|
||||
}
|
||||
|
||||
auto it = dir.begin();
|
||||
auto it2 = dir2.begin();
|
||||
auto it2 = dir2->begin();
|
||||
|
||||
while (it != dir.end())
|
||||
{
|
||||
if (it2 == dir2.end())
|
||||
if (it2 == dir2->end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -292,7 +355,7 @@ bool FilePath::contains(const FilePath& other) const
|
||||
|
||||
std::string FilePath::str() const
|
||||
{
|
||||
return m_path.generic_string();
|
||||
return m_path->generic_string();
|
||||
}
|
||||
|
||||
std::string FilePath::getBackslashedString() const
|
||||
@@ -302,22 +365,22 @@ std::string FilePath::getBackslashedString() const
|
||||
|
||||
std::string FilePath::fileName() const
|
||||
{
|
||||
return m_path.filename().generic_string();
|
||||
return m_path->filename().generic_string();
|
||||
}
|
||||
|
||||
std::string FilePath::extension() const
|
||||
{
|
||||
return m_path.extension().generic_string();
|
||||
return m_path->extension().generic_string();
|
||||
}
|
||||
|
||||
FilePath FilePath::withoutExtension() const
|
||||
{
|
||||
return FilePath(boost::filesystem::path(m_path).replace_extension());
|
||||
return FilePath(getPath().replace_extension());
|
||||
}
|
||||
|
||||
FilePath FilePath::replaceExtension(const std::string& extension) const
|
||||
{
|
||||
return FilePath(boost::filesystem::path(m_path).replace_extension(extension));
|
||||
return FilePath(getPath().replace_extension(extension));
|
||||
}
|
||||
|
||||
bool FilePath::hasExtension(const std::vector<std::string>& extensions) const
|
||||
@@ -333,14 +396,36 @@ bool FilePath::hasExtension(const std::vector<std::string>& extensions) const
|
||||
return false;
|
||||
}
|
||||
|
||||
FilePath& FilePath::operator=(const FilePath& other)
|
||||
{
|
||||
m_path = std::make_unique<boost::filesystem::path>(other.getPath());
|
||||
m_exists = other.m_exists;
|
||||
m_checkedExists = other.m_checkedExists;
|
||||
m_isDirectory = other.m_isDirectory;
|
||||
m_checkedIsDirectory = other.m_checkedIsDirectory;
|
||||
m_canonicalized = other.m_canonicalized;
|
||||
return *this;
|
||||
}
|
||||
|
||||
FilePath& FilePath::operator=(FilePath&& other)
|
||||
{
|
||||
m_path = std::move(other.m_path);
|
||||
m_exists = other.m_exists;
|
||||
m_checkedExists = other.m_checkedExists;
|
||||
m_isDirectory = other.m_isDirectory;
|
||||
m_checkedIsDirectory = other.m_checkedIsDirectory;
|
||||
m_canonicalized = other.m_canonicalized;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool FilePath::operator==(const FilePath& other) const
|
||||
{
|
||||
if (exists() && other.exists())
|
||||
{
|
||||
return boost::filesystem::equivalent(m_path, other.m_path);
|
||||
return boost::filesystem::equivalent(getPath(), other.getPath());
|
||||
}
|
||||
|
||||
return m_path.compare(other.m_path) == 0;
|
||||
return m_path->compare(other.getPath()) == 0;
|
||||
}
|
||||
|
||||
bool FilePath::operator!=(const FilePath& other) const
|
||||
@@ -350,5 +435,5 @@ bool FilePath::operator!=(const FilePath& other) const
|
||||
|
||||
bool FilePath::operator<(const FilePath& other) const
|
||||
{
|
||||
return m_path.compare(other.m_path) < 0;
|
||||
return m_path->compare(other.getPath()) < 0;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,15 @@
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#include "boost/filesystem/path.hpp"
|
||||
namespace boost
|
||||
{
|
||||
namespace filesystem
|
||||
{
|
||||
class path;
|
||||
}
|
||||
}
|
||||
|
||||
class FilePath
|
||||
{
|
||||
@@ -13,9 +20,12 @@ public:
|
||||
explicit FilePath(const char* filePath);
|
||||
explicit FilePath(const std::string& filePath);
|
||||
explicit FilePath(const boost::filesystem::path& filePath);
|
||||
FilePath(const FilePath& filePath);
|
||||
FilePath(FilePath&& other);
|
||||
FilePath(const std::string& filePath, const std::string& base);
|
||||
~FilePath();
|
||||
|
||||
boost::filesystem::path path() const;
|
||||
boost::filesystem::path getPath() const;
|
||||
|
||||
bool empty() const;
|
||||
bool exists() const;
|
||||
@@ -23,12 +33,16 @@ public:
|
||||
bool isDirectory() const;
|
||||
bool isAbsolute() const;
|
||||
|
||||
FilePath parentDirectory() const;
|
||||
FilePath getParentDirectory() const;
|
||||
|
||||
FilePath absolute() const;
|
||||
FilePath canonical() const;
|
||||
FilePath relativeTo(const FilePath& other) const;
|
||||
FilePath concat(const FilePath& other) const;
|
||||
FilePath& makeAbsolute();
|
||||
FilePath getAbsolute() const;
|
||||
FilePath& makeCanonical();
|
||||
FilePath getCanonical() const;
|
||||
FilePath& makeRelativeTo(const FilePath& other);
|
||||
FilePath getRelativeTo(const FilePath& other) const;
|
||||
FilePath& concatenate(const FilePath& other);
|
||||
FilePath getConcatenated(const FilePath& other) const;
|
||||
std::vector<FilePath> expandEnvironmentVariables() const;
|
||||
|
||||
bool contains(const FilePath& other) const;
|
||||
@@ -42,12 +56,14 @@ public:
|
||||
FilePath replaceExtension(const std::string& extension) const;
|
||||
bool hasExtension(const std::vector<std::string>& extensions) const;
|
||||
|
||||
FilePath& operator=(const FilePath& other);
|
||||
FilePath& operator=(FilePath&& other);
|
||||
bool operator==(const FilePath& other) const;
|
||||
bool operator!=(const FilePath& other) const;
|
||||
bool operator<(const FilePath& other) const;
|
||||
|
||||
private:
|
||||
boost::filesystem::path m_path;
|
||||
std::unique_ptr<boost::filesystem::path> m_path;
|
||||
|
||||
mutable bool m_exists;
|
||||
mutable bool m_checkedExists;
|
||||
|
||||
@@ -13,9 +13,9 @@ std::vector<FilePath> FileSystem::getFilePathsFromDirectory(
|
||||
std::set<std::string> ext(extensions.begin(), extensions.end());
|
||||
std::vector<FilePath> files;
|
||||
|
||||
if (boost::filesystem::is_directory(path.path()))
|
||||
if (path.isDirectory())
|
||||
{
|
||||
boost::filesystem::recursive_directory_iterator it(path.path());
|
||||
boost::filesystem::recursive_directory_iterator it(path.getPath());
|
||||
boost::filesystem::recursive_directory_iterator endit;
|
||||
while (it != endit)
|
||||
{
|
||||
@@ -44,9 +44,7 @@ FileInfo FileSystem::getFileInfoForPath(const FilePath& filePath)
|
||||
{
|
||||
if (filePath.exists())
|
||||
{
|
||||
std::time_t t = boost::filesystem::last_write_time(filePath.path());
|
||||
boost::posix_time::ptime lastWriteTime = boost::posix_time::from_time_t(t);
|
||||
return FileInfo(filePath, lastWriteTime);
|
||||
return FileInfo(filePath, getLastWriteTime(filePath));
|
||||
}
|
||||
return FileInfo();
|
||||
}
|
||||
@@ -69,7 +67,7 @@ std::vector<FileInfo> FileSystem::getFileInfosFromPaths(
|
||||
{
|
||||
if (path.isDirectory())
|
||||
{
|
||||
boost::filesystem::recursive_directory_iterator it(path.path(), boost::filesystem::symlink_option::recurse);
|
||||
boost::filesystem::recursive_directory_iterator it(path.getPath(), boost::filesystem::symlink_option::recurse);
|
||||
boost::filesystem::recursive_directory_iterator endit;
|
||||
boost::system::error_code ec;
|
||||
for ( ; it != endit ; it.increment(ec) )
|
||||
@@ -113,25 +111,20 @@ std::vector<FileInfo> FileSystem::getFileInfosFromPaths(
|
||||
continue;
|
||||
}
|
||||
filePaths.insert(p);
|
||||
|
||||
std::time_t t = boost::filesystem::last_write_time(*it);
|
||||
boost::posix_time::ptime lastWriteTime = boost::posix_time::from_time_t(t);
|
||||
files.push_back(FileInfo(FilePath(it->path()), lastWriteTime));
|
||||
files.push_back(getFileInfoForPath(FilePath(it->path())));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (path.exists() && (!ext.size() || ext.find(utility::toLowerCase(path.extension())) != ext.end()))
|
||||
{
|
||||
boost::filesystem::path p = boost::filesystem::canonical(path.path());
|
||||
const FilePath canonicalPath = path.getCanonical();
|
||||
boost::filesystem::path p = canonicalPath.getPath();
|
||||
if (filePaths.find(p) != filePaths.end())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
filePaths.insert(p);
|
||||
|
||||
std::time_t t = boost::filesystem::last_write_time(path.path());
|
||||
boost::posix_time::ptime lastWriteTime = boost::posix_time::from_time_t(t);
|
||||
files.push_back(FileInfo(path, lastWriteTime));
|
||||
files.push_back(getFileInfoForPath(canonicalPath));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,7 +140,7 @@ std::set<FilePath> FileSystem::getSymLinkedDirectories(const std::vector<FilePat
|
||||
{
|
||||
if (path.isDirectory())
|
||||
{
|
||||
boost::filesystem::recursive_directory_iterator it(path.path(), boost::filesystem::symlink_option::recurse);
|
||||
boost::filesystem::recursive_directory_iterator it(path.getPath(), boost::filesystem::symlink_option::recurse);
|
||||
boost::filesystem::recursive_directory_iterator endit;
|
||||
boost::system::error_code ec;
|
||||
for ( ; it != endit ; it.increment(ec) )
|
||||
@@ -189,7 +182,7 @@ std::set<FilePath> FileSystem::getSymLinkedDirectories(const std::vector<FilePat
|
||||
|
||||
unsigned long long FileSystem::getFileByteSize(const FilePath& filePath)
|
||||
{
|
||||
return boost::filesystem::file_size(filePath.path());
|
||||
return boost::filesystem::file_size(filePath.getPath());
|
||||
}
|
||||
|
||||
TimeStamp FileSystem::getLastWriteTime(const FilePath& filePath)
|
||||
@@ -197,7 +190,7 @@ TimeStamp FileSystem::getLastWriteTime(const FilePath& filePath)
|
||||
boost::posix_time::ptime lastWriteTime;
|
||||
if (filePath.exists())
|
||||
{
|
||||
std::time_t t = boost::filesystem::last_write_time(filePath.path());
|
||||
std::time_t t = boost::filesystem::last_write_time(filePath.getPath());
|
||||
lastWriteTime = boost::posix_time::from_time_t(t);
|
||||
}
|
||||
return TimeStamp(lastWriteTime);
|
||||
@@ -208,14 +201,9 @@ std::string FileSystem::getTimeStringNow() // TODO: move to utility
|
||||
return boost::posix_time::to_iso_string(boost::posix_time::second_clock::universal_time());
|
||||
}
|
||||
|
||||
bool FileSystem::exists(const FilePath& path)
|
||||
{
|
||||
return boost::filesystem::exists(path.path());
|
||||
}
|
||||
|
||||
bool FileSystem::remove(const FilePath& path)
|
||||
{
|
||||
return boost::filesystem::remove(path.path());
|
||||
return boost::filesystem::remove(path.getPath());
|
||||
}
|
||||
|
||||
bool FileSystem::rename(const FilePath& from, const FilePath& to)
|
||||
@@ -225,7 +213,7 @@ bool FileSystem::rename(const FilePath& from, const FilePath& to)
|
||||
return false;
|
||||
}
|
||||
|
||||
boost::filesystem::rename(from.path(), to.path());
|
||||
boost::filesystem::rename(from.getPath(), to.getPath());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -236,7 +224,7 @@ bool FileSystem::copyFile(const FilePath& from, const FilePath& to)
|
||||
return false;
|
||||
}
|
||||
|
||||
boost::filesystem::copy_file(boost::filesystem::path(from.path()), boost::filesystem::path(to.path()));
|
||||
boost::filesystem::copy_file(from.getPath(), to.getPath());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -247,7 +235,7 @@ bool FileSystem::copy_directory(const FilePath& from, const FilePath& to)
|
||||
return false;
|
||||
}
|
||||
|
||||
boost::filesystem::copy_directory(boost::filesystem::path(from.path()),boost::filesystem::path(to.path()));
|
||||
boost::filesystem::copy_directory(from.getPath(), to.getPath());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -274,7 +262,6 @@ std::vector<FilePath> FileSystem::getDirectSubDirectories(const FilePath& path)
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
std::vector<FilePath> FileSystem::getRecursiveSubDirectories(const FilePath &path)
|
||||
{
|
||||
std::vector<FilePath> v;
|
||||
|
||||
@@ -26,7 +26,6 @@ public:
|
||||
static TimeStamp getLastWriteTime(const FilePath& filePath);
|
||||
static std::string getTimeStringNow();
|
||||
|
||||
static bool exists(const FilePath& path);
|
||||
static bool remove(const FilePath& path);
|
||||
static bool rename(const FilePath& from, const FilePath& to);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user