From 8a93dcabba6b1e6f5aafb715417e0a08b66d41ba Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 7 Oct 2024 11:09:01 +0300 Subject: Switch to using odb::nested_*() functions directly rather than via adapters for containers of value types with containers --- libbrep/build-package.hxx | 74 ++++++++++++----------- libbrep/common.hxx | 146 +++------------------------------------------- libbrep/package.hxx | 74 ++++++++++++----------- 3 files changed, 79 insertions(+), 215 deletions(-) (limited to 'libbrep') diff --git a/libbrep/build-package.hxx b/libbrep/build-package.hxx index 13645eb..14217b2 100644 --- a/libbrep/build-package.hxx +++ b/libbrep/build-package.hxx @@ -288,50 +288,48 @@ namespace brep // #pragma db member(configs) id_column("") value_column("config_") - #pragma db member(config_builds) \ - virtual(build_class_exprs_map) \ - after(configs) \ - get(odb::nested_get ( \ - brep::build_package_config_builds (this.configs))) \ - set(brep::build_package_config_builds bs; \ - odb::nested_set (bs, std::move (?)); \ - move (bs).to_configs (this.configs)) \ - id_column("") key_column("") value_column("") \ + #pragma db member(config_builds) \ + virtual(build_class_exprs_map) \ + after(configs) \ + get(odb::nested_get (this.configs, \ + &brep::build_package_config::builds)) \ + set(odb::nested_set (this.configs, \ + &brep::build_package_config::builds, \ + std::move (?))) \ + id_column("") key_column("") value_column("") \ section(constraints_section) - #pragma db member(config_constraints) \ - virtual(build_constraints_map) \ - after(config_builds) \ - get(odb::nested_get ( \ - brep::build_package_config_constraints (this.configs))) \ - set(brep::build_package_config_constraints cs; \ - odb::nested_set (cs, std::move (?)); \ - move (cs).to_configs (this.configs)) \ - id_column("") key_column("") value_column("") \ + #pragma db member(config_constraints) \ + virtual(build_constraints_map) \ + after(config_builds) \ + get(odb::nested_get (this.configs, \ + &brep::build_package_config::constraints)) \ + set(odb::nested_set (this.configs, \ + &brep::build_package_config::constraints, \ + std::move (?))) \ + id_column("") key_column("") value_column("") \ section(constraints_section) - #pragma db member(config_auxiliaries) \ - virtual(build_auxiliaries_map) \ - after(config_constraints) \ - get(odb::nested_get ( \ - brep::build_package_config_auxiliaries (this.configs))) \ - set(brep::build_package_config_auxiliaries as; \ - odb::nested_set (as, std::move (?)); \ - move (as).to_configs (this.configs)) \ - id_column("") key_column("") value_column("") \ + #pragma db member(config_auxiliaries) \ + virtual(build_auxiliaries_map) \ + after(config_constraints) \ + get(odb::nested_get (this.configs, \ + &brep::build_package_config::auxiliaries)) \ + set(odb::nested_set (this.configs, \ + &brep::build_package_config::auxiliaries, \ + std::move (?))) \ + id_column("") key_column("") value_column("") \ section(auxiliaries_section) - #pragma db member(config_bot_keys) \ - virtual(build_package_bot_keys_map) \ - after(config_auxiliaries) \ - get(odb::nested_get ( \ - brep::build_package_config_bot_keys< \ - lazy_shared_ptr> (this.configs))) \ - set(brep::build_package_config_bot_keys< \ - lazy_shared_ptr> bks; \ - odb::nested_set (bks, std::move (?)); \ - move (bks).to_configs (this.configs)) \ - id_column("") key_column("") value_column("key_") \ + #pragma db member(config_bot_keys) \ + virtual(build_package_bot_keys_map) \ + after(config_auxiliaries) \ + get(odb::nested_get (this.configs, \ + &brep::build_package_config::bot_keys)) \ + set(odb::nested_set (this.configs, \ + &brep::build_package_config::bot_keys, \ + std::move (?))) \ + id_column("") key_column("") value_column("key_") \ section(bot_keys_section) #pragma db member(constraints_section) load(lazy) update(always) diff --git a/libbrep/common.hxx b/libbrep/common.hxx index 4be9ce9..8312b61 100644 --- a/libbrep/common.hxx +++ b/libbrep/common.hxx @@ -421,11 +421,10 @@ namespace brep return i != cs.end () ? &*i : nullptr; } - // Note that ODB doesn't support containers of value types which contain - // containers. Thus, we will persist/load - // build_package_config_template::{builds,constraint,auxiliaries,bot_keys} - // via the separate nested containers using the adapter classes. - // + // Note that build_package_configs_template is a container of the value + // type build_package_config_template, which contains multiple + // containers: builds, constraint, auxiliaries, bot_keys. We will + // persist/load each of them via a separate virtual container. // build_package_config_template::builds // @@ -436,39 +435,6 @@ namespace brep #pragma db member(build_class_expr_key::outer) column("config_index") #pragma db member(build_class_expr_key::inner) column("index") - // Adapter for build_package_config_template::builds. - // - // Note: 1 as for build_package_configs_template. - // - class build_package_config_builds: public small_vector - { - public: - build_package_config_builds () = default; - - template - explicit - build_package_config_builds (const build_package_configs_template& cs) - { - reserve (cs.size ()); - for (const build_package_config_template& c: cs) - push_back (c.builds); - } - - template - void - to_configs (build_package_configs_template& cs) && - { - // Note that the empty trailing entries will be missing (see ODB's - // nested-container.hxx for details). - // - assert (size () <= cs.size ()); - - auto i (cs.begin ()); - for (build_class_exprs& ces: *this) - i++->builds = move (ces); - } - }; - // build_package_config_template::constraints // using build_constraint_key = odb::nested_key; @@ -478,41 +444,6 @@ namespace brep #pragma db member(build_constraint_key::outer) column("config_index") #pragma db member(build_constraint_key::inner) column("index") - // Adapter for build_package_config_template::constraints. - // - // Note: 1 as for build_package_configs_template. - // - class build_package_config_constraints: - public small_vector - { - public: - build_package_config_constraints () = default; - - template - explicit - build_package_config_constraints ( - const build_package_configs_template& cs) - { - reserve (cs.size ()); - for (const build_package_config_template& c: cs) - push_back (c.constraints); - } - - template - void - to_configs (build_package_configs_template& cs) && - { - // Note that the empty trailing entries will be missing (see ODB's - // nested-container.hxx for details). - // - assert (size () <= cs.size ()); - - auto i (cs.begin ()); - for (build_constraints& bcs: *this) - i++->constraints = move (bcs); - } - }; - // build_package_config_template::auxiliaries // using build_auxiliary_key = odb::nested_key; @@ -522,74 +453,11 @@ namespace brep #pragma db member(build_auxiliary_key::outer) column("config_index") #pragma db member(build_auxiliary_key::inner) column("index") - // Adapter for build_package_config_template::auxiliaries. - // - // Note: 1 as for build_package_configs_template. - // - class build_package_config_auxiliaries: - public small_vector - { - public: - build_package_config_auxiliaries () = default; - - template - explicit - build_package_config_auxiliaries ( - const build_package_configs_template& cs) - { - reserve (cs.size ()); - for (const build_package_config_template& c: cs) - push_back (c.auxiliaries); - } - - template - void - to_configs (build_package_configs_template& cs) && - { - // Note that the empty trailing entries will be missing (see ODB's - // nested-container.hxx for details). - // - assert (size () <= cs.size ()); - - auto i (cs.begin ()); - for (build_auxiliaries& bas: *this) - i++->auxiliaries = move (bas); - } - }; - // build_package_config_template::bot_keys // - // Adapter for build_package_config_template::bot_keys. - // - // Note: 1 as for build_package_configs_template. - // - template - class build_package_config_bot_keys: public small_vector, 1> - { - public: - build_package_config_bot_keys () = default; - - explicit - build_package_config_bot_keys (const build_package_configs_template& cs) - { - this->reserve (cs.size ()); - for (const build_package_config_template& c: cs) - this->push_back (c.bot_keys); - } - - void - to_configs (build_package_configs_template& cs) && - { - // Note that the empty trailing entries will be missing (see ODB's - // nested-container.hxx for details). - // - assert (this->size () <= cs.size ()); - - auto i (cs.begin ()); - for (vector& bks: *this) - i++->bot_keys = move (bks); - } - }; + // Note that the nested container support types (*_key, *_map, etc) are + // package object type-specific for this container and are defined in the + // package.hxx and build-package.hxx headers, respectively. // The primary reason why a package is unbuildable by the build bot // controller service. diff --git a/libbrep/package.hxx b/libbrep/package.hxx index e2d2da5..79b2c68 100644 --- a/libbrep/package.hxx +++ b/libbrep/package.hxx @@ -902,50 +902,48 @@ namespace brep #pragma db member(build_configs) id_column("") value_column("config_") \ section(build_section) - #pragma db member(build_config_builds) \ - virtual(build_class_exprs_map) \ - after(build_configs) \ - get(odb::nested_get ( \ - brep::build_package_config_builds (this.build_configs))) \ - set(brep::build_package_config_builds bs; \ - odb::nested_set (bs, std::move (?)); \ - move (bs).to_configs (this.build_configs)) \ - id_column("") key_column("") value_column("") \ + #pragma db member(build_config_builds) \ + virtual(build_class_exprs_map) \ + after(build_configs) \ + get(odb::nested_get (this.build_configs, \ + &brep::package_build_config::builds)) \ + set(odb::nested_set (this.build_configs, \ + &brep::package_build_config::builds, \ + std::move (?))) \ + id_column("") key_column("") value_column("") \ section(build_section) - #pragma db member(build_config_constraints) \ - virtual(build_constraints_map) \ - after(build_config_builds) \ - get(odb::nested_get ( \ - brep::build_package_config_constraints (this.build_configs))) \ - set(brep::build_package_config_constraints cs; \ - odb::nested_set (cs, std::move (?)); \ - move (cs).to_configs (this.build_configs)) \ - id_column("") key_column("") value_column("") \ + #pragma db member(build_config_constraints) \ + virtual(build_constraints_map) \ + after(build_config_builds) \ + get(odb::nested_get (this.build_configs, \ + &brep::package_build_config::constraints)) \ + set(odb::nested_set (this.build_configs, \ + &brep::package_build_config::constraints, \ + std::move (?))) \ + id_column("") key_column("") value_column("") \ section(build_section) - #pragma db member(build_config_auxiliaries) \ - virtual(build_auxiliaries_map) \ - after(build_config_constraints) \ - get(odb::nested_get ( \ - brep::build_package_config_auxiliaries (this.build_configs))) \ - set(brep::build_package_config_auxiliaries as; \ - odb::nested_set (as, std::move (?)); \ - move (as).to_configs (this.build_configs)) \ - id_column("") key_column("") value_column("") \ + #pragma db member(build_config_auxiliaries) \ + virtual(build_auxiliaries_map) \ + after(build_config_constraints) \ + get(odb::nested_get (this.build_configs, \ + &brep::package_build_config::auxiliaries)) \ + set(odb::nested_set (this.build_configs, \ + &brep::package_build_config::auxiliaries, \ + std::move (?))) \ + id_column("") key_column("") value_column("") \ section(unused_section) - #pragma db member(build_config_bot_keys) \ - virtual(package_build_bot_keys_map) \ - after(build_config_auxiliaries) \ - get(odb::nested_get ( \ - brep::build_package_config_bot_keys< \ - lazy_shared_ptr> (this.build_configs))) \ - set(brep::build_package_config_bot_keys< \ - lazy_shared_ptr> bks; \ - odb::nested_set (bks, std::move (?)); \ - move (bks).to_configs (this.build_configs)) \ - id_column("") key_column("") value_column("key_") value_not_null \ + #pragma db member(build_config_bot_keys) \ + virtual(package_build_bot_keys_map) \ + after(build_config_auxiliaries) \ + get(odb::nested_get (this.build_configs, \ + &brep::package_build_config::bot_keys)) \ + set(odb::nested_set (this.build_configs, \ + &brep::package_build_config::bot_keys, \ + std::move (?))) \ + id_column("") key_column("") value_column("key_") value_not_null \ section(unused_section) #pragma db member(reviews) section(reviews_section) -- cgit v1.1