-
-
Notifications
You must be signed in to change notification settings - Fork 1k
visitor draft #4786
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
visitor draft #4786
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,6 +65,11 @@ bool dispatch_array_type(const CSGObject* obj, std::string_view name, | |
| #endif // DOXYGEN_SHOULD_SKIP_THIS | ||
| #endif // SWIG | ||
|
|
||
| struct InterfaceVisitor | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this might be better to place into a separate .h file and include it here. place it under src/shogun/util/visitors |
||
| { | ||
| CSGObject* value; | ||
| }; | ||
|
|
||
| template <class T, class K> class CMap; | ||
|
|
||
| struct TParameter; | ||
|
|
@@ -857,6 +862,13 @@ class CSGObject | |
| { | ||
| BaseTag tag(name); | ||
| create_parameter(tag, AnyParameter(make_any_ref(value), properties)); | ||
|
|
||
| if constexpr (is_sg_base<T>::value) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. imo if you wrap this whole block into a constexpr function then you could just call that instead of copy pasting things 4 times. |
||
| Any::register_visitor<T, InterfaceVisitor>([] (auto n_value, auto visitor) { | ||
| visitor->value = n_value; | ||
| }); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| /** Puts a pointer to some parameter into the parameter map. | ||
|
|
@@ -882,6 +894,12 @@ class CSGObject | |
| tag, | ||
| AnyParameter( | ||
| make_any_ref(value), properties, std::move(auto_init))); | ||
|
|
||
| if constexpr (is_sg_base<T>::value) { | ||
| Any::register_visitor<T, InterfaceVisitor>([] (auto n_value, auto visitor) { | ||
| visitor->value = n_value; | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| #ifndef SWIG | ||
|
|
@@ -915,6 +933,11 @@ class CSGObject | |
| constrain_function.run(casted_val, result); | ||
| return result; | ||
| })); | ||
| if constexpr (is_sg_base<T1>::value) { | ||
| Any::register_visitor<T1, InterfaceVisitor>([] (auto n_value, auto visitor) { | ||
| visitor->value = n_value; | ||
| }); | ||
| } | ||
| } | ||
| #endif | ||
|
|
||
|
|
@@ -954,6 +977,12 @@ class CSGObject | |
| BaseTag tag(name); | ||
| create_parameter( | ||
| tag, AnyParameter(make_any_ref(value, rows, cols), properties)); | ||
|
|
||
| if constexpr (is_sg_base<T>::value) { | ||
| Any::register_visitor<T, InterfaceVisitor>([] (auto n_value, auto visitor) { | ||
| visitor->value = n_value; | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| #ifndef SWIG | ||
|
|
@@ -1344,30 +1373,15 @@ CSGObject* get_if_possible(const CSGObject* obj, std::string_view name, GetByNam | |
| return result; | ||
| } | ||
|
|
||
| template<typename T> | ||
| CSGObject* get_dispatch_all_base_types(const CSGObject* obj, std::string_view name, | ||
| T&& how) | ||
| { | ||
| if (auto* result = get_if_possible<CKernel>(obj, name, how)) | ||
| return result; | ||
| if (auto* result = get_if_possible<CFeatures>(obj, name, how)) | ||
| return result; | ||
| if (auto* result = get_if_possible<CMachine>(obj, name, how)) | ||
| return result; | ||
| if (auto* result = get_if_possible<CLabels>(obj, name, how)) | ||
| return result; | ||
| if (auto* result = get_if_possible<CEvaluationResult>(obj, name, how)) | ||
| return result; | ||
|
|
||
| return nullptr; | ||
| } | ||
|
|
||
| template<class T> | ||
| CSGObject* get_by_tag(const CSGObject* obj, std::string_view name, | ||
| T&& how) | ||
| { | ||
| return get_dispatch_all_base_types(obj, name, how); | ||
| } | ||
| CSGObject* get_by_tag(const CSGObject* obj, std::string_view name) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this whole thing could be deleted and go into a private function that is implemented in .cpp |
||
| BaseTag tag(name); | ||
| auto param = obj->get_parameter(tag); | ||
| InterfaceVisitor iv; | ||
| param.get_value().visit_with(&iv); | ||
| if (iv.value) | ||
| return iv.value; | ||
| return nullptr; | ||
| } | ||
|
|
||
| #endif //DOXYGEN_SHOULD_SKIP_THIS | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the problem here that imo this ignores the
indexparameter. so the visitor that you've written only works in the expected manner forCSGObject::get(std::string_view name, std::nothrow_t). i need to see how we support getCSGObject* CSGObject::get(std::string_view name, index_t index) const. that's basically when the registered parameter is an array