container: root: common: PluggablePath: expand parent path, refactor
This commit is contained in:
@@ -301,38 +301,41 @@ class PluggablePath
|
|||||||
auto& parse()
|
auto& parse()
|
||||||
{
|
{
|
||||||
// Parse out pseudo tag
|
// Parse out pseudo tag
|
||||||
const std::string type{m_pseudo.substr(0, m_pseudo.find('/'))};
|
auto pos = m_pseudo.find('/');
|
||||||
|
throw_ex_if<type::RuntimeError>(!pos, "no pseudo tag");
|
||||||
std::string pruned{m_pseudo};
|
const std::string tag{m_pseudo.substr(0, pos)};
|
||||||
pruned.erase(0, pruned.find('/') + 1);
|
|
||||||
|
|
||||||
// Set family group
|
// Set family group
|
||||||
m_family = pruned;
|
m_family = m_pseudo;
|
||||||
|
m_family.erase(0, pos + 1);
|
||||||
// Set parent directory
|
throw_ex_if<type::RuntimeError>(m_family.empty(), "no family found");
|
||||||
m_parent = pruned.substr(0, pruned.find('/'));
|
|
||||||
|
|
||||||
// Set child (filename)
|
|
||||||
m_child = pruned.substr(pruned.find_last_of('/') + 1);
|
|
||||||
|
|
||||||
// Set absolute path
|
// Set absolute path
|
||||||
std::string absolute{pruned};
|
m_absolute = m_family;
|
||||||
if (type == "repo")
|
if (tag == "repo")
|
||||||
{
|
{
|
||||||
m_is_repo = true;
|
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;
|
m_is_custom = true;
|
||||||
absolute.insert(0, m_path.custom());
|
m_absolute.insert(0, m_path.custom());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw_ex<type::RuntimeError>(
|
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;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -365,22 +368,21 @@ class PluggablePath
|
|||||||
const auto& operator()() const { return m_path; }
|
const auto& operator()() const { return m_path; }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//! \return The pluggable's pseudo-path
|
//! \return The pluggable's complete pseudo-path
|
||||||
const std::string& pseudo() const { return m_pseudo; }
|
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; }
|
const std::string& absolute() const { return m_absolute; }
|
||||||
|
|
||||||
// TODO(unassigned): relative() to current working dir
|
//! \return The pluggable's relative parent director(y|ies) derived from pseudo-path
|
||||||
|
//! \warning Trailing slash is removed
|
||||||
//! \return The pluggable's parent directory
|
|
||||||
//! \note This also represents the expected namespace used for pluggable auto-loading
|
//! \note This also represents the expected namespace used for pluggable auto-loading
|
||||||
const std::string& parent() const { return m_parent; }
|
const std::string& parent() const { return m_parent; }
|
||||||
|
|
||||||
//! \return The pluggable's child (filename)
|
//! \return The pluggable's child (filename)
|
||||||
const std::string& child() const { return m_child; }
|
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; }
|
const std::string& family() const { return m_family; }
|
||||||
|
|
||||||
//! \return true if pseudo-path describes a repository location
|
//! \return true if pseudo-path describes a repository location
|
||||||
@@ -392,7 +394,7 @@ class PluggablePath
|
|||||||
private:
|
private:
|
||||||
type::PluggablePath m_path;
|
type::PluggablePath m_path;
|
||||||
std::string m_pseudo, m_absolute;
|
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;
|
bool m_is_repo, m_is_custom;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user