fs/{,Allocated}Path: add typedef Traits

This commit is contained in:
Max Kellermann 2018-07-18 13:05:23 +02:00
parent 641447bf9b
commit 2b1d6ad396
2 changed files with 19 additions and 17 deletions

View File

@ -36,10 +36,11 @@
* stored.
*/
class AllocatedPath {
typedef PathTraitsFS::string string;
typedef PathTraitsFS::value_type value_type;
typedef PathTraitsFS::pointer_type pointer_type;
typedef PathTraitsFS::const_pointer_type const_pointer_type;
using Traits = PathTraitsFS;
typedef Traits::string string;
typedef Traits::value_type value_type;
typedef Traits::pointer_type pointer_type;
typedef Traits::const_pointer_type const_pointer_type;
string value;
@ -52,7 +53,7 @@ class AllocatedPath {
static AllocatedPath Build(const_pointer_type a, size_t a_size,
const_pointer_type b, size_t b_size) {
return AllocatedPath(PathTraitsFS::Build(a, a_size, b, b_size));
return AllocatedPath(Traits::Build(a, a_size, b, b_size));
}
public:
/**
@ -88,8 +89,8 @@ public:
gcc_pure gcc_nonnull_all
static AllocatedPath Build(const_pointer_type a,
const_pointer_type b) noexcept {
return Build(a, PathTraitsFS::GetLength(a),
b, PathTraitsFS::GetLength(b));
return Build(a, Traits::GetLength(a),
b, Traits::GetLength(b));
}
gcc_pure gcc_nonnull_all
@ -105,7 +106,7 @@ public:
gcc_pure gcc_nonnull_all
static AllocatedPath Build(const_pointer_type a,
const AllocatedPath &b) noexcept {
return Build(a, PathTraitsFS::GetLength(a),
return Build(a, Traits::GetLength(a),
b.value.c_str(), b.value.size());
}
@ -113,7 +114,7 @@ public:
static AllocatedPath Build(const AllocatedPath &a,
const_pointer_type b) noexcept {
return Build(a.value.c_str(), a.value.size(),
b, PathTraitsFS::GetLength(b));
b, Traits::GetLength(b));
}
gcc_pure
@ -260,7 +261,7 @@ public:
*/
gcc_pure
const_pointer_type Relative(Path other_fs) const noexcept {
return PathTraitsFS::Relative(c_str(), other_fs.c_str());
return Traits::Relative(c_str(), other_fs.c_str());
}
/**
@ -270,7 +271,7 @@ public:
gcc_pure
bool IsAbsolute() const noexcept {
return PathTraitsFS::IsAbsolute(c_str());
return Traits::IsAbsolute(c_str());
}
};

View File

@ -37,7 +37,8 @@ class AllocatedPath;
* instance lives, the string must not be invalidated.
*/
class Path : public PathTraitsFS::Pointer {
typedef PathTraitsFS::Pointer Base;
using Traits = PathTraitsFS;
typedef Traits::Pointer Base;
constexpr Path(const_pointer_type _value):Base(_value) {}
@ -93,7 +94,7 @@ public:
size_t length() const noexcept {
assert(!IsNull());
return PathTraitsFS::GetLength(c_str());
return Traits::GetLength(c_str());
}
/**
@ -122,7 +123,7 @@ public:
*/
gcc_pure
bool HasNewline() const noexcept {
return PathTraitsFS::Find(c_str(), '\n') != nullptr;
return Traits::Find(c_str(), '\n') != nullptr;
}
/**
@ -139,7 +140,7 @@ public:
*/
gcc_pure
Path GetBase() const noexcept {
return FromFS(PathTraitsFS::GetBase(c_str()));
return FromFS(Traits::GetBase(c_str()));
}
/**
@ -157,12 +158,12 @@ public:
*/
gcc_pure
const_pointer_type Relative(Path other_fs) const noexcept {
return PathTraitsFS::Relative(c_str(), other_fs.c_str());
return Traits::Relative(c_str(), other_fs.c_str());
}
gcc_pure
bool IsAbsolute() const noexcept {
return PathTraitsFS::IsAbsolute(c_str());
return Traits::IsAbsolute(c_str());
}
gcc_pure