sources as different names, explicit targets
This commit is contained in:
parent
cc4d8d1fc3
commit
1d9a6ec3f8
10 changed files with 252 additions and 62 deletions
129
src/source.cpp
Normal file
129
src/source.cpp
Normal file
|
@ -0,0 +1,129 @@
|
|||
#include "source.h"
|
||||
|
||||
Source::Source(const std::string& path) :
|
||||
path(path),
|
||||
target(std::nullopt),
|
||||
name(std::nullopt)
|
||||
{}
|
||||
|
||||
Source::Source(const std::string& path, const std::string& target) :
|
||||
path(path),
|
||||
target(target),
|
||||
name(std::nullopt)
|
||||
{}
|
||||
|
||||
Source::Source(const std::string& path, const std::string& target, const std::string& name) :
|
||||
path(path),
|
||||
target(target),
|
||||
name(name)
|
||||
{}
|
||||
|
||||
Source::Source(const std::string& path, const std::optional<std::string>& target, const std::optional<std::string>& name) :
|
||||
path(path),
|
||||
target(target),
|
||||
name(name)
|
||||
{}
|
||||
|
||||
void Source::clearName() {
|
||||
name = std::nullopt;
|
||||
}
|
||||
|
||||
void Source::clearTarget() {
|
||||
target = std::nullopt;
|
||||
}
|
||||
|
||||
std::string Source::getPath() const {
|
||||
return path;
|
||||
}
|
||||
|
||||
std::string Source::getTarget() const {
|
||||
if (target.has_value())
|
||||
return target.value();
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string Source::getName() const {
|
||||
if (name.has_value())
|
||||
return name.value();
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
std::optional<std::string> Source::getOptionalTarget() const {
|
||||
return target;
|
||||
}
|
||||
|
||||
std::optional<std::string> Source::getOptionalName() const {
|
||||
return name;
|
||||
}
|
||||
|
||||
bool Source::hasExplicitTarget() const {
|
||||
return target.has_value();
|
||||
}
|
||||
|
||||
bool Source::hasExplicitName() const {
|
||||
return name.has_value();
|
||||
}
|
||||
|
||||
void Source::setPath(const std::string& path) {
|
||||
Source::path = path;
|
||||
}
|
||||
|
||||
void Source::setTarget(const std::string& target) {
|
||||
Source::target = target;
|
||||
}
|
||||
|
||||
void Source::setName(const std::string& name) {
|
||||
Source::name = name;
|
||||
}
|
||||
|
||||
bool Source::operator < (const Source& other) const {
|
||||
if (path < other.path)
|
||||
return true;
|
||||
else if (path > other.path)
|
||||
return false;
|
||||
else {
|
||||
if (hasExplicitTarget()) {
|
||||
if (other.hasExplicitTarget()) {
|
||||
if (target.value() < other.target.value())
|
||||
return true;
|
||||
else if (target.value() > other.target.value()) {
|
||||
return false;
|
||||
} else {
|
||||
if (hasExplicitName()) {
|
||||
if (other.hasExplicitName()) {
|
||||
return name.value() < other.name.value();
|
||||
} else
|
||||
return false;
|
||||
} else
|
||||
return other.hasExplicitName();
|
||||
}
|
||||
} else
|
||||
return false;
|
||||
} else {
|
||||
if (other.hasExplicitTarget())
|
||||
return true;
|
||||
else {
|
||||
if (hasExplicitName()) {
|
||||
if (other.hasExplicitName()) {
|
||||
return name.value() < other.name.value();
|
||||
} else
|
||||
return false;
|
||||
} else
|
||||
return other.hasExplicitName();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string Source::print() const {
|
||||
std::string result = path;
|
||||
if (hasExplicitTarget())
|
||||
result += " -> " + target.value();
|
||||
|
||||
if (hasExplicitName())
|
||||
result += " (as " + name.value() + ")";
|
||||
|
||||
return result;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue