8 #include "../helpers/Enum.h" 19 Author, First = Author,
20 SignedOffBy, FirstRole = SignedOffBy,
24 AckedBy, LastRole = AckedBy,
28 Upstream, Last = Upstream,
38 static constexpr
const std::string_view roleNames[] = {
50 static_assert(static_cast<size_t>(RoleType::Last) + 1 == std::size(roleNames));
59 RoleType
role()
const {
return m_role; }
63 return static_cast<std::size_t
>(
role);
93 m_role(std::move(r)), m_name(std::move(
name)), m_email(std::move(
email)),
99 const std::string &
name()
const {
return m_name; }
101 const std::string &
email()
const {
return m_email; }
103 std::string
userName()
const {
return m_email.substr(0, m_email.find(
"@")); }
109 auto count()
const {
return m_count; }
116 std::string
pretty(
bool includeName =
true)
const {
117 if (includeName && !
name().empty())
130 template <
typename T>
132 std::string
pretty(
const T &translate,
bool includeName =
true)
const {
133 if (includeName && !
name().empty())
134 return name() +
" <" + translate(
email()) +
">";
135 return translate(
email());
161 static std::optional<Person>
parse(std::string_view src)
164 for (
auto I: range) {
static constexpr auto index(RoleType role)
Convert Role to number/index.
Definition: Person.h:62
RoleType role() const
Get the actual RoleType.
Definition: Person.h:59
constexpr auto toString() const
Convert Role to string.
Definition: Person.h:73
auto count() const
Get count of changes historically done by this Person.
Definition: Person.h:109
Role(RoleType role)
Construct new Role with role set.
Definition: Person.h:56
static std::optional< Person > parsePerson(std::string_view src, Role role)
Parse src into a Person.
constexpr auto index() const
Convert Role to number/index.
Definition: Person.h:71
static std::optional< Person > parse(std::string_view src)
Try to parse a line.
Definition: Person.h:161
static constexpr auto toString(RoleType role)
Convert Role to string.
Definition: Person.h:66
Role(size_t index)
Construct new Role with role set by the index.
Definition: Person.h:54
const Role & role() const
Get Role of this Person.
Definition: Person.h:97
const std::string & email() const
Get e-mail of this Person.
Definition: Person.h:101
Role of a Person.
Definition: Person.h:36
Helper class to iterate over enum values from Enum::First to Enum::Last.
Definition: Enum.h:13
const std::string & name() const
Get name of this Person.
Definition: Person.h:99
requires requires(T t, std::string s)
Pretty format as "username <e-mail>".
Definition: Person.h:131
std::string userName() const
Get user name (from e-mail)
Definition: Person.h:103
Definition: Branches.h:15
Person(Role r, std::string name, std::string email, unsigned count=0)
Create a Person with Role r, name, email and count of changes.
Definition: Person.h:92
Information about a person (such as username, e-mail, Role)
Definition: Person.h:81
std::string pretty(bool includeName=true) const
Pretty format as "username <e-mail>".
Definition: Person.h:116
void setEmail(const std::string &email)
Re-set e-mail to email.
Definition: Person.h:142