idol
A C++ Framework for Optimization
Loading...
Searching...
No Matches
impl_Annotation.h
1//
2// Created by henri on 03/02/23.
3//
4
5#ifndef IDOL_IMPL_ANNOTATION_H
6#define IDOL_IMPL_ANNOTATION_H
7
8#include <string>
9#include <memory>
10#include <any>
11
12namespace idol {
13 class Env;
14
15 namespace impl {
16 class Annotation;
17 }
18
19}
20
21class idol::impl::Annotation {
22 struct Id {
23 Env& env;
24 const unsigned int id;
25 const std::string name;
26 std::any default_value;
27 Id(Env& t_env, unsigned int t_id, std::string&& t_name) : env(t_env), id(t_id), name(std::move(t_name)) {}
28 };
29 std::shared_ptr<Id> m_id;
30protected:
31 template<class T, class ...ArgsT> void set_default_value(ArgsT&& ...t_args);
32 template<class T> [[nodiscard]] const T& cast_default_value() const { return std::any_cast<const T&>(m_id->default_value); }
33public:
34 Annotation(::idol::Env& t_env, std::string&& t_name);
35
36 virtual ~Annotation() = default;
37
44 [[nodiscard]] unsigned int id() const { return m_id->id; }
45
50 [[nodiscard]] const std::string& name() const { return m_id->name; }
51
56 [[nodiscard]] bool has_default() const { return m_id->default_value.has_value(); }
57
61 void free();
62
67 [[nodiscard]] Env& env() const { return m_id->env; }
68};
69
70template<class T, class... ArgsT>
71void idol::impl::Annotation::set_default_value(ArgsT &&... t_args) {
72 m_id->default_value.emplace<T>(std::forward<ArgsT>(t_args)...);
73}
74
75#endif //IDOL_IMPL_ANNOTATION_H