schema progress (does not compile)

This commit is contained in:
2025-12-31 11:56:12 +01:00
parent d104222fdd
commit ab2d39407c
65 changed files with 1355 additions and 922 deletions
@@ -0,0 +1,57 @@
#ifndef MATADOR_OBSERVER_LIST_COPY_CREATOR_HPP
#define MATADOR_OBSERVER_LIST_COPY_CREATOR_HPP
#include "matador/object/observer.hpp"
#include <memory>
#include <vector>
namespace matador::object::internal {
template <typename SourceType, typename DestType, template <typename> class... ObserverType>
class observer_list_copy_creator
{
public:
using source_observer_vector = std::vector<std::unique_ptr<observer<SourceType>>>;
using observer_vector = std::vector<std::unique_ptr<observer<DestType>>>;
using iterator = typename observer_vector::iterator;
static observer_vector copy_create(const source_observer_vector &source_observers) {
observer_list_copy_creator creator(source_observers);
return std::move(creator.observers_);
}
private:
explicit observer_list_copy_creator(const source_observer_vector &source_observers)
: source_observers_(source_observers) {
if constexpr (sizeof...(ObserverType) != 0) {
copy_observer<ObserverType...>();
}
}
template <template <typename> class FirstObserverType>
void copy_observer() {
try_copy_observer<FirstObserverType>();
}
template <template <typename> class FirstObserverType, template <typename> class NextObserverType, template <typename> class... RestObserverType>
void copy_observer() {
try_copy_observer<FirstObserverType>();
copy_observer<NextObserverType, RestObserverType...>();
}
template <template <typename> class CurrentObserverType>
void try_copy_observer() {
for ( const auto &obs : source_observers_ ) {;
if (const auto *casted_observer = dynamic_cast<const CurrentObserverType<SourceType>*>(obs.get()); casted_observer != nullptr) {
observers_.emplace_back(std::make_unique<CurrentObserverType<DestType>>(*casted_observer));
break;
}
}
}
private:
const source_observer_vector &source_observers_;
observer_vector observers_;
};
}
#endif //MATADOR_OBSERVER_LIST_COPY_CREATOR_HPP
@@ -0,0 +1,69 @@
#ifndef MATADOR_OBSERVER_LIST_CREATOR_HPP
#define MATADOR_OBSERVER_LIST_CREATOR_HPP
#include "matador/object/observer.hpp"
#include <memory>
#include <vector>
namespace matador::object::internal {
template <typename Type, template <typename> class... ObserverType>
class observer_list_creator
{
public:
using observer_vector = std::vector<std::unique_ptr<observer<Type>>>;
static void create_missing(observer_vector &observers) {
observer_list_creator creator(observers);
}
private:
explicit observer_list_creator(observer_vector &observers)
: observers_(observers) {
if constexpr (sizeof...(ObserverType) != 0) {
build_observer<ObserverType...>();
}
}
template <template <typename> class FirstObserverType>
void build_observer() {
try_copy_on_missing<FirstObserverType>();
}
template <template <typename> class FirstObserverType, template <typename> class NextObserverType, template <typename> class... RestObserverType>
void build_observer() {
try_copy_on_missing<FirstObserverType>();
build_observer<NextObserverType, RestObserverType...>();
}
template <template <typename> class CurrentObserverType>
void try_copy_on_missing() {
bool is_missing{true};
for ( const auto &obs : observers_ ) {;
if (dynamic_cast<const CurrentObserverType<Type>*>(obs.get())) {
is_missing = false;
break;
}
}
if (is_missing) {
append<CurrentObserverType<Type>>();
}
}
template <class CurrentObserverType>
void append(std::enable_if_t<std::is_default_constructible_v<CurrentObserverType> || std::is_trivially_default_constructible_v<CurrentObserverType>>* = nullptr) {
observers_.emplace_back(std::make_unique<CurrentObserverType>());
}
template <class CurrentObserverType>
void append(std::enable_if_t<!std::is_default_constructible_v<CurrentObserverType> && !std::is_trivially_default_constructible_v<CurrentObserverType>>* = nullptr) {
static_assert("no default constructor");
}
private:
observer_vector &observers_;
};
}
#endif //MATADOR_OBSERVER_LIST_CREATOR_HPP
@@ -40,6 +40,11 @@ public:
[[nodiscard]] std::shared_ptr<object> object_for_type(const std::type_index &ti) const;
void remove_object_for_type(const std::type_index &ti) const;
[[nodiscard]] bool is_node_announced(const std::type_index &ti) const;
void push_announce_node(const std::type_index &ti, const node_ptr &node) const;
[[nodiscard]] node_ptr announce_node(const std::type_index &ti) const;
[[nodiscard]] node_ptr pop_announce_node(const std::type_index &ti) const;
private:
repository& repo_;
};