0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2025-03-16 22:41:46 +01:00

ircd::info::version: Allow both monotonic and semantic numbers; add string generator ctor.

This commit is contained in:
Jason Volk 2019-05-31 14:50:25 -07:00
parent 1f7ad67805
commit 0a225085b3
3 changed files with 44 additions and 12 deletions

View file

@ -97,17 +97,26 @@ struct ircd::info::versions
/// information has been sourced. Defaults to INCLUDE.
enum type {INCLUDE, LIBRARY} type {INCLUDE};
/// Semantic version number. If the version number is a single (likely
/// monotonic) integer, use the major number (i.e [0]).
std::array<long, 3> number {0};
/// If the version number is a single (likely monotonic) integer.
long monotonic {0};
/// Alternative semantic version number.
std::array<long, 3> semantic {0};
/// Version string buffer. Copy any provided version string here.
char string[128] {0};
versions(const string_view &name,
const enum type &type = type::INCLUDE,
const long &monotonic = 0,
const std::array<long, 3> &semantic = {0L},
const string_view &string = {});
versions(const string_view &name,
const enum type &type,
const std::array<long, 3> &number = {0L},
const string_view &string = {});
const long &monotonic,
const std::array<long, 3> &semantic,
const std::function<void (versions &, const mutable_buffer &)> &generator);
versions() = default;
versions(versions &&) = delete;

View file

@ -152,17 +152,36 @@ ircd::util::instance_list<ircd::info::versions>::list
allocator
};
/// Straightforward construction of versions members; string is copied
/// into member buffer with null termination.
ircd::info::versions::versions(const string_view &name,
const enum type &type,
const std::array<long, 3> &number,
const long &monotonic,
const std::array<long, 3> &semantic,
const string_view &string)
:name{name}
,type{type}
,number{number}
,monotonic{monotonic}
,semantic{semantic}
{
strlcpy(this->string, string);
}
/// Construction of versions members with closure for custom string generation.
/// The version string must be stored into buffer with null termination.
ircd::info::versions::versions(const string_view &name,
const enum type &type,
const long &monotonic,
const std::array<long, 3> &semantic,
const std::function<void (versions &, const mutable_buffer &)> &closure)
:name{name}
,type{type}
,monotonic{monotonic}
,semantic{semantic}
{
closure(*this, this->string);
}
//
// Primary information
//

View file

@ -695,7 +695,9 @@ console_cmd__versions(opt &out, const string_view &line)
<< " "
<< std::left << std::setw(12) << "TYPE"
<< " "
<< std::left << std::setw(16) << "VERSION"
<< std::left << std::setw(16) << "MONOTONIC"
<< " "
<< std::left << std::setw(16) << "SEMANTIC"
<< " "
<< std::left << std::setw(16) << ":STRING"
<< " "
@ -714,15 +716,17 @@ console_cmd__versions(opt &out, const string_view &line)
const string_view semantic{fmt::sprintf
{
buf, "%ld.%ld.%ld",
version->number[0],
version->number[1],
version->number[2],
version->semantic[0],
version->semantic[1],
version->semantic[2],
}};
out
<< std::left << std::setw(12) << version->name
<< " "
<< std::left << std::setw(12) << type
<< std::left << std::setw(12) << type
<< " "
<< std::left << std::setw(16) << version->monotonic
<< " "
<< std::left << std::setw(16) << semantic
<< " :"