From 8f2427996e421cd49e663a29a78e954af475b6ec Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Tue, 6 Jul 2021 04:16:15 +0700 Subject: [PATCH] instance and cinstance classes --- headers/meta.hpp/meta.hpp | 1 + headers/meta.hpp/meta_instance.hpp | 99 ++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 headers/meta.hpp/meta_instance.hpp diff --git a/headers/meta.hpp/meta.hpp b/headers/meta.hpp/meta.hpp index 5a4b00a..125d059 100644 --- a/headers/meta.hpp/meta.hpp +++ b/headers/meta.hpp/meta.hpp @@ -8,6 +8,7 @@ #include "meta_fwd.hpp" +#include "meta_instance.hpp" #include "meta_value.hpp" #include "meta_registry.hpp" diff --git a/headers/meta.hpp/meta_instance.hpp b/headers/meta.hpp/meta_instance.hpp new file mode 100644 index 0000000..dd01c77 --- /dev/null +++ b/headers/meta.hpp/meta_instance.hpp @@ -0,0 +1,99 @@ +/******************************************************************************* + * This file is part of the "https://github.com/blackmatov/meta.hpp" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#pragma once + +#include "meta_fwd.hpp" + +#include "meta_value.hpp" + +namespace meta_hpp +{ + class instance; + class cinstance; +} + +namespace meta_hpp +{ + class instance { + public: + instance() = delete; + + instance(instance&&) = default; + instance(const instance&) = default; + + instance& operator=(instance&&) = default; + instance& operator=(const instance&) = default; + + template < typename T + , typename = std::enable_if_t> + , typename = std::enable_if_t> + , typename = std::enable_if_t> > + instance(T& v) + : data_{std::addressof(v)} + , fid_{get_type_family_id()} {} + + instance(value& v) + : data_{v.data()} + , fid_{v.fid()} {} + + void* data() noexcept { + return data_; + } + + const void* data() const noexcept { + return data_; + } + + family_id fid() const noexcept { + return fid_; + } + private: + void* data_{}; + family_id fid_{}; + }; +} + +namespace meta_hpp +{ + class cinstance { + public: + cinstance() = delete; + + cinstance(cinstance&&) = default; + cinstance(const cinstance&) = default; + + cinstance& operator=(cinstance&&) = default; + cinstance& operator=(const cinstance&) = default; + + template < typename T + , typename = std::enable_if_t> + , typename = std::enable_if_t> + , typename = std::enable_if_t> > + cinstance(const T& data) + : data_{std::addressof(data)} + , fid_{get_type_family_id()} {} + + cinstance(const value& v) + : data_{v.data()} + , fid_{v.fid()} {} + + cinstance(const instance& v) + : data_{v.data()} + , fid_{v.fid()} {} + + const void* data() const noexcept { + return data_; + } + + family_id fid() const noexcept { + return fid_; + } + private: + const void* data_{}; + family_id fid_{}; + }; +}