added session class
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#ifndef BASIC_PROTOTYPE_INFO_HPP
|
||||
#define BASIC_PROTOTYPE_INFO_HPP
|
||||
|
||||
#include <string>
|
||||
#include <typeindex>
|
||||
|
||||
namespace matador::object {
|
||||
@@ -12,6 +13,7 @@ public:
|
||||
virtual ~basic_object_info() = default;
|
||||
|
||||
[[nodiscard]] std::type_index type_index() const;
|
||||
[[nodiscard]] std::string name() const;
|
||||
|
||||
protected:
|
||||
basic_object_info(schema_node &node, std::type_index type_index);
|
||||
@@ -27,8 +29,15 @@ public:
|
||||
explicit object_info(schema_node &node)
|
||||
: basic_object_info(node, typeid(Type)) {}
|
||||
|
||||
const Type &prototype() const { return prototype_; }
|
||||
|
||||
private:
|
||||
Type prototype_;
|
||||
};
|
||||
|
||||
template<typename Type>
|
||||
using object_info_ref = std::reference_wrapper<const object_info<Type>>;
|
||||
|
||||
namespace detail {
|
||||
struct null_type {};
|
||||
}
|
||||
|
||||
@@ -83,6 +83,16 @@ public:
|
||||
*/
|
||||
[[nodiscard]] std::string name() const;
|
||||
|
||||
template <typename Type>
|
||||
[[nodiscard]] utils::result<object_info_ref<Type>, utils::error> info() const {
|
||||
auto result = find_node(std::type_index(typeid(Type)));
|
||||
if (!result) {
|
||||
return utils::failure(result.err());
|
||||
}
|
||||
|
||||
return utils::ok(result.value()->info<Type>());
|
||||
}
|
||||
|
||||
private:
|
||||
using node_ptr = std::shared_ptr<schema_node>;
|
||||
using t_node_map = std::unordered_map<std::string, node_ptr>;
|
||||
|
||||
@@ -46,6 +46,11 @@ public:
|
||||
[[nodiscard]] node_ptr next() const;
|
||||
[[nodiscard]] node_ptr prev() const;
|
||||
|
||||
template <typename Type>
|
||||
object_info_ref<Type> info() const {
|
||||
return std::ref(static_cast<const object_info<Type>&>(*info_));
|
||||
}
|
||||
|
||||
private:
|
||||
explicit schema_node(schema& tree);
|
||||
template < typename Type >
|
||||
|
||||
Reference in New Issue
Block a user