container: root: common: PluggablePath: expand parent path, refactor

This commit is contained in:
2025-12-23 08:49:50 -08:00
parent f11c139359
commit b775992d63

View File

@@ -301,38 +301,41 @@ class PluggablePath
auto& parse()
{
// Parse out pseudo tag
const std::string type{m_pseudo.substr(0, m_pseudo.find('/'))};
std::string pruned{m_pseudo};
pruned.erase(0, pruned.find('/') + 1);
auto pos = m_pseudo.find('/');
throw_ex_if<type::RuntimeError>(!pos, "no pseudo tag");
const std::string tag{m_pseudo.substr(0, pos)};
// Set family group
m_family = pruned;
// Set parent directory
m_parent = pruned.substr(0, pruned.find('/'));
// Set child (filename)
m_child = pruned.substr(pruned.find_last_of('/') + 1);
m_family = m_pseudo;
m_family.erase(0, pos + 1);
throw_ex_if<type::RuntimeError>(m_family.empty(), "no family found");
// Set absolute path
std::string absolute{pruned};
if (type == "repo")
m_absolute = m_family;
if (tag == "repo")
{
m_is_repo = true;
absolute.insert(0, m_path.repo());
m_absolute.insert(0, m_path.repo());
}
else if (type == "custom")
else if (tag == "custom")
{
m_is_custom = true;
absolute.insert(0, m_path.custom());
m_absolute.insert(0, m_path.custom());
}
else
{
throw_ex<type::RuntimeError>(
"must be of type 'repo/<relative>' or 'custom/<relative>'");
"must be of tag 'repo' or 'custom' | was given: '" + tag + "'");
}
m_absolute = std::move(absolute);
// Set parent path (director(y|ies))
pos = m_family.find_last_of('/');
m_parent = m_family.substr(0, pos);
// Set child (filename)
m_child = m_family.substr(pos + 1);
throw_ex_if<type::RuntimeError>(
m_child.empty() || m_child == m_parent, "child not found");
return *this;
}
@@ -365,22 +368,21 @@ class PluggablePath
const auto& operator()() const { return m_path; }
public:
//! \return The pluggable's pseudo-path
//! \return The pluggable's complete pseudo-path
const std::string& pseudo() const { return m_pseudo; }
//! \return The pluggable's operating system absolute path
//! \return The pluggable's operating system absolute path (with parsed pseudo-path)
const std::string& absolute() const { return m_absolute; }
// TODO(unassigned): relative() to current working dir
//! \return The pluggable's parent directory
//! \return The pluggable's relative parent director(y|ies) derived from pseudo-path
//! \warning Trailing slash is removed
//! \note This also represents the expected namespace used for pluggable auto-loading
const std::string& parent() const { return m_parent; }
//! \return The pluggable's child (filename)
const std::string& child() const { return m_child; }
//! \return The pluggable's group of parent member and child filename
//! \return The pluggable's group of parent and child members
const std::string& family() const { return m_family; }
//! \return true if pseudo-path describes a repository location
@@ -392,7 +394,7 @@ class PluggablePath
private:
type::PluggablePath m_path;
std::string m_pseudo, m_absolute;
std::string m_parent, m_family, m_child;
std::string m_family, m_parent, m_child;
bool m_is_repo, m_is_custom;
};