Skip to content

Commit

Permalink
Accept type_config template argument for into_toml()
Browse files Browse the repository at this point in the history
Since the new toml11-devel-4.0.0 version the `type_config` is required
for conversion.

https://toruniina.github.io/toml11/docs/features/value/#converting-to-tomlvalue
  • Loading branch information
kontura committed Aug 13, 2024
1 parent 6924826 commit cf06886
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
3 changes: 3 additions & 0 deletions libdnf5/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ target_link_libraries(libdnf5_static PRIVATE common)
# link libraries and set pkg-config requires

find_package(toml11 REQUIRED)
if (toml11_VERSION VERSION_LESS 4.0.0)
add_definitions(-DTOML11_COMPAT)
endif()

pkg_check_modules(LIBFMT REQUIRED fmt)
list(APPEND LIBDNF5_PC_REQUIRES "${LIBFMT_MODULE_NAME}")
Expand Down
12 changes: 12 additions & 0 deletions libdnf5/rpm/versionlock_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,14 @@ struct from<libdnf5::rpm::VersionlockCondition> {

template <>
struct into<libdnf5::rpm::VersionlockCondition> {
#ifdef TOML11_COMPAT
static toml::value into_toml(const libdnf5::rpm::VersionlockCondition & condition) {
toml::value res;
#else
template <typename TC>
static toml::basic_value<TC> into_toml(const libdnf5::rpm::VersionlockCondition & condition) {
toml::basic_value<TC> res;
#endif // #ifdef TOML11_COMPAT

res["key"] = condition.get_key_str();
res["comparator"] = condition.get_comparator_str();
Expand All @@ -83,8 +89,14 @@ struct from<libdnf5::rpm::VersionlockPackage> {

template <>
struct into<libdnf5::rpm::VersionlockPackage> {
#ifdef TOML11_COMPAT
static toml::value into_toml(const libdnf5::rpm::VersionlockPackage & package) {
toml::value res;
#else
template <typename TC>
static toml::basic_value<TC> into_toml(const libdnf5::rpm::VersionlockPackage & package) {
toml::basic_value<TC> res;
#endif // #ifdef TOML11_COMPAT

res["name"] = package.get_name();
auto comment = package.get_comment();
Expand Down
43 changes: 42 additions & 1 deletion libdnf5/system/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,14 @@ struct from<libdnf5::system::PackageState> {

template <>
struct into<libdnf5::system::PackageState> {
#ifdef TOML11_COMPAT
static toml::value into_toml(const libdnf5::system::PackageState & pkg_state) {
toml::value res;
#else
template <typename TC>
static toml::basic_value<TC> into_toml(const libdnf5::system::PackageState & pkg_state) {
toml::basic_value<TC> res;
#endif // #ifdef TOML11_COMPAT

res["reason"] = pkg_state.reason;

Expand All @@ -72,8 +78,14 @@ struct from<libdnf5::system::NevraState> {

template <>
struct into<libdnf5::system::NevraState> {
#ifdef TOML11_COMPAT
static toml::value into_toml(const libdnf5::system::NevraState & nevra_state) {
toml::value res;
#else
template <typename TC>
static toml::basic_value<TC> into_toml(const libdnf5::system::NevraState & nevra_state) {
toml::basic_value<TC> res;
#endif // #ifdef TOML11_COMPAT

res["from_repo"] = nevra_state.from_repo;

Expand All @@ -92,7 +104,12 @@ struct from<libdnf5::comps::PackageType> {

template <>
struct into<libdnf5::comps::PackageType> {
static toml::value into_toml(const libdnf5::comps::PackageType & package_types) {
#ifdef TOML11_COMPAT
static toml::value into_toml(const libdnf5::comps::PackageType & package_types){
#else
template <typename TC>
static toml::basic_value<TC> into_toml(const libdnf5::comps::PackageType & package_types) {
#endif // #ifdef TOML11_COMPAT
return libdnf5::comps::package_types_to_strings(package_types);
}
};
Expand All @@ -117,8 +134,14 @@ struct from<libdnf5::system::GroupState> {

template <>
struct into<libdnf5::system::GroupState> {
#ifdef TOML11_COMPAT
static toml::value into_toml(const libdnf5::system::GroupState & group_state) {
toml::value res;
#else
template <typename TC>
static toml::basic_value<TC> into_toml(const libdnf5::system::GroupState & group_state) {
toml::basic_value<TC> res;
#endif // #ifdef TOML11_COMPAT

res["userinstalled"] = group_state.userinstalled;
res["package_types"] = group_state.package_types;
Expand All @@ -145,8 +168,14 @@ struct from<libdnf5::system::EnvironmentState> {

template <>
struct into<libdnf5::system::EnvironmentState> {
#ifdef TOML11_COMPAT
static toml::value into_toml(const libdnf5::system::EnvironmentState & environment_state) {
toml::value res;
#else
template <typename TC>
static toml::basic_value<TC> into_toml(const libdnf5::system::EnvironmentState & environment_state) {
toml::basic_value<TC> res;
#endif // #ifdef TOML11_COMPAT

res["groups"] = environment_state.groups;

Expand All @@ -172,8 +201,14 @@ struct from<libdnf5::system::ModuleState> {

template <>
struct into<libdnf5::system::ModuleState> {
#ifdef TOML11_COMPAT
static toml::value into_toml(const libdnf5::system::ModuleState & module_state) {
toml::value res;
#else
template <typename TC>
static toml::basic_value<TC> into_toml(const libdnf5::system::ModuleState & module_state) {
toml::basic_value<TC> res;
#endif // #ifdef TOML11_COMPAT

res["enabled_stream"] = module_state.enabled_stream;
res["state"] = libdnf5::module::module_status_to_string(module_state.status);
Expand All @@ -199,8 +234,14 @@ struct from<libdnf5::system::SystemState> {

template <>
struct into<libdnf5::system::SystemState> {
#ifdef TOML11_COMPAT
static toml::value into_toml(const libdnf5::system::SystemState & system_state) {
toml::value res;
#else
template <typename TC>
static toml::basic_value<TC> into_toml(const libdnf5::system::SystemState & system_state) {
toml::basic_value<TC> res;
#endif // #ifdef TOML11_COMPAT

res["rpmdb_cookie"] = system_state.rpmdb_cookie;

Expand Down

0 comments on commit cf06886

Please sign in to comment.