Added path views for abs and rel paths

This commit is contained in:
catalinvasile
2024-07-10 11:52:47 +02:00
parent 51cf1887cd
commit 2195ccfc28
15 changed files with 4637 additions and 957 deletions
+48 -30
View File
@@ -28,36 +28,38 @@ public:
using key_less = path_key_less<PathSystems>;
using value_type = std::string;
//checked indexing
const string& at(size_t index) const noexcept;
//both have checked indexing
const string& operator[](size_t index) const noexcept;
string& operator[](size_t index) noexcept;
const string& at(size_t index) const noexcept;
string& at(size_t index) noexcept;
void shrink(size_t size) noexcept;
bool empty() const noexcept;
size_t size() const noexcept;
size_t size() const noexcept;
void reserve(size_t capacity) noexcept;
// if the path is empty, these operations have no effect. They return the removed element as a string.
string pop_back() noexcept;
virtual bool push_back(string element) noexcept;
string pop_back() noexcept;
virtual bool push_back(string element) noexcept;
virtual void take_elements(tl::vector<string>&& elements) noexcept;
virtual void take_elements(tl::vector<string>&& elements) noexcept;
iterator begin() noexcept;
iterator end() noexcept;
iterator begin() noexcept;
iterator end() noexcept;
const_iterator begin() const noexcept;
const_iterator end() const noexcept;
const_reverse_iterator rbegin() const noexcept;
const_reverse_iterator rend() const noexcept;
uint32_t hash() const noexcept;
uint32_t hash() const noexcept;
protected:
bool validate_element(const string& element) noexcept;
void push_element(string element) noexcept;
void push_element(string element) noexcept;
tl::vector<string> m_elements;
mutable uint32_t m_hash = 0;
mutable uint32_t m_hash = 0;
friend bool path_key_less<PathSystems>::operator()(const path_base<PathSystems>& a1, const path_base<PathSystems>& a2) const noexcept;
};
@@ -87,9 +89,43 @@ namespace path_system
//////////////////////////////////////////////////////////////////////////
template <typename PathSystems>
const string& path_base<PathSystems>::operator[](size_t index) const noexcept
{
if (index >= m_elements.size())
TL_PLAIN_CRASH("Illegal access");
return m_elements[index];
}
//////////////////////////////////////////////////////////////////////////
template <typename PathSystems>
string& path_base<PathSystems>::operator[](size_t index) noexcept
{
if (index >= m_elements.size())
TL_PLAIN_CRASH("Illegal access");
m_hash = 0;
return m_elements[index];
}
//////////////////////////////////////////////////////////////////////////
template <typename PathSystems>
const string& path_base<PathSystems>::at(size_t index) const noexcept
{
if (index >= m_elements.size())
TL_PLAIN_CRASH("Illegal access");
return m_elements[index];
}
//////////////////////////////////////////////////////////////////////////
template <typename PathSystems>
string& path_base<PathSystems>::at(size_t index) noexcept
{
if (index >= m_elements.size())
TL_PLAIN_CRASH("Illegal access");
m_hash = 0;
return m_elements[index];
}
@@ -164,25 +200,7 @@ string path_base<PathSystems>::pop_back() noexcept
template <typename PathSystems>
bool path_base<PathSystems>::push_back(string element) noexcept
{
if (!validate_element(element))
{
TL_PLAIN_FAIL("Pushed an invalid path element.");
return false;
}
push_element(std::move(element));
return true;
}
//////////////////////////////////////////////////////////////////////////
template <typename PathSystems>
bool path_base<PathSystems>::validate_element(const string& /*element*/) noexcept
{
// validate element to be added here
// if not return false
return true;
}