forked from qt-creator/qt-creator
Clang: Derive FilePath from Utils::PathString
We don't want to implement all the methods again. Change-Id: I2f89ea59607b59f5ca49e6790e8a868942e1f96f Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
@@ -37,22 +37,22 @@
|
|||||||
|
|
||||||
namespace ClangBackEnd {
|
namespace ClangBackEnd {
|
||||||
|
|
||||||
class FilePath
|
class FilePath : public Utils::PathString
|
||||||
{
|
{
|
||||||
using size_type = Utils::PathString::size_type;
|
using size_type = Utils::PathString::size_type;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FilePath() = default;
|
FilePath() = default;
|
||||||
explicit FilePath(Utils::PathString &&filePath)
|
explicit FilePath(Utils::PathString &&filePath)
|
||||||
: m_path(std::move(filePath))
|
: Utils::PathString(std::move(filePath))
|
||||||
{
|
{
|
||||||
FilePathView view{m_path};
|
FilePathView view{*this};
|
||||||
|
|
||||||
m_slashIndex = view.slashIndex();
|
m_slashIndex = view.slashIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
FilePath(FilePathView filePathView)
|
FilePath(FilePathView filePathView)
|
||||||
: m_path(filePathView.toStringView()),
|
: Utils::PathString(filePathView.toStringView()),
|
||||||
m_slashIndex(filePathView.slashIndex())
|
m_slashIndex(filePathView.slashIndex())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -70,7 +70,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
explicit FilePath(Utils::PathString &&filePath, std::ptrdiff_t slashIndex)
|
explicit FilePath(Utils::PathString &&filePath, std::ptrdiff_t slashIndex)
|
||||||
: m_path(std::move(filePath)),
|
: Utils::PathString(std::move(filePath)),
|
||||||
m_slashIndex(slashIndex)
|
m_slashIndex(slashIndex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -81,44 +81,39 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
FilePath(Utils::SmallStringView directory, Utils::SmallStringView name)
|
FilePath(Utils::SmallStringView directory, Utils::SmallStringView name)
|
||||||
: m_path({directory, "/", name}),
|
: Utils::PathString({directory, "/", name}),
|
||||||
m_slashIndex(std::ptrdiff_t(directory.size()))
|
m_slashIndex(std::ptrdiff_t(directory.size()))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Utils::SmallStringView directory() const noexcept
|
Utils::SmallStringView directory() const noexcept
|
||||||
{
|
{
|
||||||
return m_path.mid(0, std::size_t(std::max(std::ptrdiff_t(0), m_slashIndex)));
|
return mid(0, std::size_t(std::max(std::ptrdiff_t(0), m_slashIndex)));
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::SmallStringView name() const noexcept
|
Utils::SmallStringView name() const noexcept
|
||||||
{
|
{
|
||||||
return m_path.mid(std::size_t(m_slashIndex + 1),
|
return mid(std::size_t(m_slashIndex + 1),
|
||||||
std::size_t(std::ptrdiff_t(m_path.size()) - m_slashIndex - std::ptrdiff_t(1)));
|
std::size_t(std::ptrdiff_t(size()) - m_slashIndex - std::ptrdiff_t(1)));
|
||||||
}
|
|
||||||
|
|
||||||
bool empty() const
|
|
||||||
{
|
|
||||||
return m_path.empty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Utils::PathString &path() const noexcept
|
const Utils::PathString &path() const noexcept
|
||||||
{
|
{
|
||||||
return m_path;
|
return *this;
|
||||||
}
|
|
||||||
|
|
||||||
operator const Utils::PathString&() const noexcept
|
|
||||||
{
|
|
||||||
return m_path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
operator FilePathView() const noexcept
|
operator FilePathView() const noexcept
|
||||||
{
|
{
|
||||||
return FilePathView(Utils::SmallStringView(m_path));
|
return FilePathView(toStringView());
|
||||||
|
}
|
||||||
|
|
||||||
|
operator Utils::SmallStringView() const noexcept
|
||||||
|
{
|
||||||
|
return toStringView();
|
||||||
}
|
}
|
||||||
|
|
||||||
friend QDataStream &operator<<(QDataStream &out, const FilePath &filePath)
|
friend QDataStream &operator<<(QDataStream &out, const FilePath &filePath)
|
||||||
{
|
{
|
||||||
out << filePath.m_path;
|
out << static_cast<const Utils::PathString&>(filePath);
|
||||||
out << uint(filePath.m_slashIndex);
|
out << uint(filePath.m_slashIndex);
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
@@ -128,7 +123,7 @@ public:
|
|||||||
{
|
{
|
||||||
uint slashIndex;
|
uint slashIndex;
|
||||||
|
|
||||||
in >> filePath.m_path;
|
in >> static_cast<Utils::PathString&>(filePath);
|
||||||
in >> slashIndex;
|
in >> slashIndex;
|
||||||
|
|
||||||
filePath.m_slashIndex = slashIndex;
|
filePath.m_slashIndex = slashIndex;
|
||||||
@@ -138,12 +133,12 @@ public:
|
|||||||
|
|
||||||
friend bool operator==(const FilePath &first, const FilePath &second)
|
friend bool operator==(const FilePath &first, const FilePath &second)
|
||||||
{
|
{
|
||||||
return first.m_path == second.m_path;
|
return first.toStringView() == second.toStringView();
|
||||||
}
|
}
|
||||||
|
|
||||||
friend bool operator==(const FilePath &first, const FilePathView &second)
|
friend bool operator==(const FilePath &first, const FilePathView &second)
|
||||||
{
|
{
|
||||||
return first.path() == second.toStringView();
|
return first.toStringView() == second.toStringView();
|
||||||
}
|
}
|
||||||
|
|
||||||
friend bool operator==(const FilePathView &first, const FilePath &second)
|
friend bool operator==(const FilePathView &first, const FilePath &second)
|
||||||
@@ -153,7 +148,7 @@ public:
|
|||||||
|
|
||||||
friend bool operator<(const FilePath &first, const FilePath &second)
|
friend bool operator<(const FilePath &first, const FilePath &second)
|
||||||
{
|
{
|
||||||
return first.m_path < second.m_path;
|
return first.toStringView() < second.toStringView();
|
||||||
}
|
}
|
||||||
|
|
||||||
FilePath clone() const
|
FilePath clone() const
|
||||||
@@ -178,7 +173,6 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Utils::PathString m_path;
|
|
||||||
std::ptrdiff_t m_slashIndex = -1;
|
std::ptrdiff_t m_slashIndex = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user