diff --git a/cmake/toolchain_clang.cmake b/cmake/toolchain_clang.cmake index f7d69b0e..b25b6885 100644 --- a/cmake/toolchain_clang.cmake +++ b/cmake/toolchain_clang.cmake @@ -1,2 +1,2 @@ -SET(CMAKE_C_COMPILER clang) -SET(CMAKE_CXX_COMPILER clang++) +SET(CMAKE_C_COMPILER clang-15) +SET(CMAKE_CXX_COMPILER clang++-15) diff --git a/extra_visitors/protobuf3/CMakeLists.txt b/extra_visitors/protobuf3/CMakeLists.txt index 227bbc32..49be9079 100644 --- a/extra_visitors/protobuf3/CMakeLists.txt +++ b/extra_visitors/protobuf3/CMakeLists.txt @@ -1,10 +1,17 @@ set (TGT_ARILES_VISITOR_LIB "${PROJECT_NAME}_visitor_${ARILES_VISITOR}") if(NOT ARILES_DEB_TARGETS) - find_package(Protobuf REQUIRED) + set(protobuf_MODULE_COMPATIBLE ON CACHE STRING "") + find_package(Protobuf CONFIG) - set(ARILES_VISITOR_${ARILES_VISITOR}_INCLUDES "${Protobuf_INCLUDE_DIRS}") - set(ARILES_VISITOR_${ARILES_VISITOR}_LIBS "${Protobuf_LIBRARIES}") + if(Protobuf_FOUND) + set(ARILES_VISITOR_${ARILES_VISITOR}_LIBS "protobuf::libprotobuf") + else() + find_package(Protobuf REQUIRED) + + set(ARILES_VISITOR_${ARILES_VISITOR}_INCLUDES "${Protobuf_INCLUDE_DIRS}") + set(ARILES_VISITOR_${ARILES_VISITOR}_LIBS "${Protobuf_LIBRARIES}") + endif() endif() add_library(${TGT_ARILES_VISITOR_LIB} INTERFACE) diff --git a/include/ariles2/visitors/aggregate.h b/include/ariles2/visitors/aggregate.h new file mode 100644 index 00000000..b9d3ce88 --- /dev/null +++ b/include/ariles2/visitors/aggregate.h @@ -0,0 +1,161 @@ +/** + @file + @author Alexander Sherikov + + @copyright 2017-2024 Alexander Sherikov, Licensed under the Apache License, Version 2.0. + (see @ref LICENSE or http://www.apache.org/licenses/LICENSE-2.0) + + @brief +*/ + +#pragma once + +#include "common.h" + + +namespace ariles2 +{ + /// @ingroup aggregate + namespace aggregate + { + template + class ARILES2_VISIBILITY_ATTRIBUTE ParametersWraper + { + public: + typename t_Visitor::Parameters parameters_; + + public: + ParametersWraper(const bool override_parameters = true) : parameters_(override_parameters) + { + } + + ParametersWraper(const typename t_Visitor::Parameters ¶meters) : parameters_(parameters) + { + } + + template < + class t_IdType, + typename = std::enable_if_t< + std::is_same::value + or std::is_base_of::value>> + typename t_Visitor::Parameters &get() + { + return (parameters_); + } + + template < + class t_IdType, + typename = std::enable_if_t< + std::is_same::value + or std::is_base_of::value>> + const typename t_Visitor::Parameters &get() const + { + return (parameters_); + } + }; + + template + class ARILES2_VISIBILITY_ATTRIBUTE Parameters; + + template <> + class ARILES2_VISIBILITY_ATTRIBUTE Parameters<> + { + public: + Parameters(const bool){}; + Parameters(){}; + + void get(){}; + }; + + template + class ARILES2_VISIBILITY_ATTRIBUTE Parameters : public ParametersWraper, + public Parameters + { + public: + Parameters(const bool override_parameters = true) + : ParametersWraper(override_parameters), Parameters(override_parameters) + { + } + + template + Parameters(const typename t_Visitor::Parameters ¶meters, t_Parameters &&...other_parameters) + : ParametersWraper(parameters) + , Parameters(std::forward(other_parameters)...) + { + } + + template + Parameters(const t_Parameters ¶meters, const bool override_parameters = true) + : ParametersWraper(override_parameters) + , Parameters(parameters, override_parameters) + { + } + + Parameters(const typename t_Visitor::Parameters ¶meters, const bool override_parameters = true) + : ParametersWraper(parameters), Parameters(override_parameters) + { + } + + using ParametersWraper::get; + using Parameters::get; + }; + + + + /* + template + class ARILES2_VISIBILITY_ATTRIBUTE BaseVisitorWraper + { + public: + t_Visitor visitor_; + + public: + BaseVisitorWraper() {}; + + template + BaseVisitorWraper(t_Args &&... args) : visitor_(std::forward(args)...) + { + } + + template ::value>> + t_Visitor &get() + { + return (visitor_); + } + + template ::value>> + const t_Visitor &get() const + { + return (visitor_); + } + }; + */ + + template + class ARILES2_VISIBILITY_ATTRIBUTE BaseVisitor; + + template <> + class ARILES2_VISIBILITY_ATTRIBUTE BaseVisitor<> + { + }; + + template + class ARILES2_VISIBILITY_ATTRIBUTE BaseVisitor : // public BaseVisitorWraper, + public BaseVisitor + { + }; + + + template + class ARILES2_VISIBILITY_ATTRIBUTE Visitor + : public BaseVisitor, + public visitor::Base> + { + public: + using Parameters = aggregate::Parameters; + + public: + using visitor::Base::getDefaultParameters; + }; + } // namespace aggregate +} // namespace ariles2 diff --git a/include/ariles2/visitors/config.h b/include/ariles2/visitors/config.h index 1733536c..5cf6ae37 100644 --- a/include/ariles2/visitors/config.h +++ b/include/ariles2/visitors/config.h @@ -6,7 +6,6 @@ (see @ref LICENSE or http://www.apache.org/licenses/LICENSE-2.0) @brief - @todo compound visitor */ #pragma once @@ -16,6 +15,7 @@ #include "prewrite.h" #include "read.h" #include "write.h" +#include "aggregate.h" /** @defgroup config Configuration @@ -30,74 +30,27 @@ namespace ariles2 namespace cfgread { template - class ARILES2_VISIBILITY_ATTRIBUTE Parameters + class ARILES2_VISIBILITY_ATTRIBUTE Visitor : public aggregate::Visitor { public: - ariles2::preread::Visitor::Parameters preread_; - typename t_Reader::Parameters read_; - ariles2::postread::Visitor::Parameters postread_; + using AggregateBase = aggregate::Visitor; + using typename AggregateBase::Parameters; public: - Parameters(const bool override_parameters = true) - : preread_(override_parameters), read_(override_parameters), postread_(override_parameters) - { - } - - Parameters(const typename t_Reader::Parameters ¶m, const bool override_parameters = true) - : preread_(override_parameters), postread_(override_parameters) - { - this->read_ = param; - } - - Parameters( - const ariles2::preread::Visitor::Parameters &preread, - const typename t_Reader::Parameters &reader, - const ariles2::postread::Visitor::Parameters &postread) - { - this->preread_ = preread; - this->read_ = reader; - this->postread_ = postread; - } - }; - - - template - class ARILES2_VISIBILITY_ATTRIBUTE Visitor : public visitor::Base> - { - public: - using Parameters = cfgread::Parameters; - - - public: - ariles2::preread::Visitor preread_; + preread::Visitor preread_; t_Reader read_; - ariles2::postread::Visitor postread_; + postread::Visitor postread_; public: - template - Visitor(t_Initializer &initializer) : read_(initializer) - { - ARILES2_TRACE_FUNCTION; - } - - template - Visitor(const t_Initializer &initializer) : read_(initializer) - { - ARILES2_TRACE_FUNCTION; - } - - template - Visitor(t_Initializer0 &initializer0, const t_Initializer1 &initializer1) - : read_(initializer0, initializer1) + template + Visitor(t_Initializers &&...initializers) : read_(std::forward(initializers)...) { ARILES2_TRACE_FUNCTION; } - using visitor::Base::getDefaultParameters; - template const Parameters getParameters(const t_Ariles &ariles_class) const { @@ -109,26 +62,15 @@ namespace ariles2 } - template - void visit(t_Entry &entry, const std::string &name, const Parameters ¶m) + template + void visit(t_Entry &entry, const t_Path &path, const Parameters ¶m) { ARILES2_TRACE_FUNCTION; ARILES2_TRACE_VALUE(name); ARILES2_TRACE_TYPE(entry); - ariles2::apply(preread_, entry, name, param.preread_); - ariles2::apply(read_, entry, name, param.read_); - ariles2::apply(postread_, entry, name, param.postread_); - } - - - template - void visit(t_Entry &entry, const std::vector &subtree, const Parameters ¶m) - { - ARILES2_TRACE_FUNCTION; - ARILES2_TRACE_TYPE(entry); - ariles2::apply(preread_, entry, subtree.empty() ? "" : subtree.back(), param.preread_); - ariles2::apply(read_, entry, subtree, param.read_); - ariles2::apply(postread_, entry, subtree.empty() ? "" : subtree.back(), param.postread_); + ariles2::apply(preread_, entry, path, param.template get()); + ariles2::apply(read_, entry, path, param.template get()); + ariles2::apply(postread_, entry, path, param.template get()); } @@ -147,77 +89,26 @@ namespace ariles2 namespace cfgwrite { template - class ARILES2_VISIBILITY_ATTRIBUTE Parameters - { - public: - ariles2::prewrite::Visitor::Parameters prewrite_; - typename t_Writer::Parameters write_; - - - public: - Parameters(const bool override_parameters = true) - : prewrite_(override_parameters), write_(override_parameters) - { - } - - Parameters(const typename t_Writer::Parameters ¶m, const bool override_parameters = true) - : prewrite_(override_parameters) - { - this->write_ = param; - } - - Parameters( - const ariles2::prewrite::Visitor::Parameters &prewrite, - const typename t_Writer::Parameters &writer) - { - this->prewrite_ = prewrite; - this->write_ = writer; - } - }; - - - template - class ARILES2_VISIBILITY_ATTRIBUTE Visitor : public visitor::Base> + class ARILES2_VISIBILITY_ATTRIBUTE Visitor : public aggregate::Visitor { public: - using Parameters = cfgwrite::Parameters; + using AggregateBase = aggregate::Visitor; + using typename AggregateBase::Parameters; public: - ariles2::prewrite::Visitor prewrite_; + prewrite::Visitor prewrite_; t_Writer write_; public: - template - Visitor(t_Initializer &initializer) : write_(initializer) - { - ARILES2_TRACE_FUNCTION; - } - - template - Visitor(const t_Initializer &initializer) : write_(initializer) - { - ARILES2_TRACE_FUNCTION; - } - - template - Visitor(t_Initializer0 *initializer0, const t_Initializer1 &initializer1) - : write_(initializer0, initializer1) - { - ARILES2_TRACE_FUNCTION; - } - - template - Visitor(t_Initializer0 &initializer0, const t_Initializer1 &initializer1) - : write_(initializer0, initializer1) + template + Visitor(t_Initializers &&...initializers) : write_(std::forward(initializers)...) { ARILES2_TRACE_FUNCTION; } - using visitor::Base::getDefaultParameters; - template const Parameters getParameters(const t_Ariles &ariles_class) const { @@ -233,8 +124,8 @@ namespace ariles2 ARILES2_TRACE_FUNCTION; ARILES2_TRACE_VALUE(name); ARILES2_TRACE_TYPE(entry); - ariles2::apply(prewrite_, entry, name, param.prewrite_); - ariles2::apply(write_, entry, name, param.write_); + ariles2::apply(prewrite_, entry, name, param.template get()); + ariles2::apply(write_, entry, name, param.template get()); } diff --git a/include/ariles2/visitors/defaults.h b/include/ariles2/visitors/defaults.h index 7a61dc5b..c5d25ab0 100644 --- a/include/ariles2/visitors/defaults.h +++ b/include/ariles2/visitors/defaults.h @@ -77,6 +77,12 @@ namespace ariles2 this->visitMapEntry(entry, name, param); } + template + void visit(t_Entry &entry, const std::vector &subtree, const Parameters ¶m) const + { + visit(entry, subtree.empty() ? "" : subtree.back(), param); + } + template void visitMapEntry(t_Entry &entry, const std::string &name, const Parameters ¶m) const diff --git a/include/ariles2/visitors/finalize.h b/include/ariles2/visitors/finalize.h index 50415515..3f971cf2 100644 --- a/include/ariles2/visitors/finalize.h +++ b/include/ariles2/visitors/finalize.h @@ -37,6 +37,14 @@ namespace ariles2 class ARILES2_VISIBILITY_ATTRIBUTE Visitor : public ariles2::process::Visitor { + public: + using ariles2::process::Visitor::visit; + + template + void visit(t_Entry &entry, const std::vector &subtree, const Parameters ¶m) const + { + visit(entry, subtree.empty() ? "" : subtree.back(), param); + } }; diff --git a/tests/api_v2/demo_api_v2.cpp b/tests/api_v2/demo_api_v2.cpp index 7ac03a46..49f78696 100644 --- a/tests/api_v2/demo_api_v2.cpp +++ b/tests/api_v2/demo_api_v2.cpp @@ -158,7 +158,7 @@ int main() // Adjust visitor parameters ariles2::yaml_cpp::Writer::Parameters parameters; - parameters.write_.allow_missing_entries_ = true; + parameters.get().allow_missing_entries_ = true; ariles2::apply(std::cout, my_container_class, parameters); // In some situations it is more convenient to instantiate Reader and diff --git a/tests/api_v2/fixtures/000_basic_interface.h b/tests/api_v2/fixtures/000_basic_interface.h index a9456231..502a84da 100644 --- a/tests/api_v2/fixtures/000_basic_interface.h +++ b/tests/api_v2/fixtures/000_basic_interface.h @@ -73,8 +73,8 @@ namespace ariles_tests t_Configurable configurable; typename t_Visitor::Reader::Parameters parameters; - parameters.read_.override_parameters_ = false; - parameters.read_.allow_missing_entries_ = true; + parameters.template get().override_parameters_ = false; + parameters.template get().allow_missing_entries_ = true; typename t_Visitor::Reader reader(getReaderInitializer("configurable.cfg")); ariles2::apply(reader, configurable, parameters); } diff --git a/tests/api_v2/fixtures/012_basic_interface_add_filename.h b/tests/api_v2/fixtures/012_basic_interface_add_filename.h index 781044a1..f9fde680 100644 --- a/tests/api_v2/fixtures/012_basic_interface_add_filename.h +++ b/tests/api_v2/fixtures/012_basic_interface_add_filename.h @@ -67,7 +67,7 @@ namespace ariles_tests configurable.randomize(); typename t_Visitor::Writer::Parameters parameters; - parameters.write_.allow_missing_entries_ = true; + parameters.template get().allow_missing_entries_ = true; typename t_Visitor::Writer writer(std::string("configurable3") + ".cfg"); ariles2::apply(writer, configurable, parameters); @@ -77,8 +77,8 @@ namespace ariles_tests t_Configurable configurable; typename t_Visitor::Reader::Parameters parameters; - parameters.read_.override_parameters_ = true; - parameters.read_.allow_missing_entries_ = true; + parameters.template get().override_parameters_ = true; + parameters.template get().allow_missing_entries_ = true; typename t_Visitor::Reader reader(std::string("configurable3") + ".cfg"); ariles2::apply(reader, configurable, parameters); } @@ -92,7 +92,7 @@ namespace ariles_tests configurable.randomize(); typename t_Visitor::Writer::Parameters parameters; - parameters.write_.allow_missing_entries_ = true; + parameters.template get().allow_missing_entries_ = true; ariles2::apply( std::string("configurable4") + ".cfg", configurable, parameters); @@ -101,8 +101,8 @@ namespace ariles_tests { t_Configurable configurable; typename t_Visitor::Reader::Parameters parameters; - parameters.read_.override_parameters_ = true; - parameters.read_.allow_missing_entries_ = true; + parameters.template get().override_parameters_ = true; + parameters.template get().allow_missing_entries_ = true; ariles2::apply( std::string("configurable4") + ".cfg", configurable, parameters); } diff --git a/tests/api_v2/fixtures/019_defaults.h b/tests/api_v2/fixtures/019_defaults.h index 72bb1d8b..ff59219e 100644 --- a/tests/api_v2/fixtures/019_defaults.h +++ b/tests/api_v2/fixtures/019_defaults.h @@ -68,7 +68,7 @@ namespace ariles_tests typename t_Visitor::Writer writer(getWriterInitializer("configurable.cfg")); typename t_Visitor::Writer::Parameters parameters; - parameters.write_.allow_missing_entries_ = true; + parameters.template get().allow_missing_entries_ = true; ariles2::apply(writer, configurable, parameters); } @@ -78,8 +78,8 @@ namespace ariles_tests configurable.defaults_check_flag_ = false; typename t_Visitor::Reader::Parameters parameters; - parameters.read_.override_parameters_ = false; - parameters.read_.allow_missing_entries_ = true; + parameters.template get().override_parameters_ = false; + parameters.template get().allow_missing_entries_ = true; typename t_Visitor::Reader reader(getReaderInitializer("configurable.cfg")); ariles2::apply(reader, configurable, parameters); BOOST_CHECK(configurable.defaults_check_flag_); @@ -92,7 +92,7 @@ namespace ariles_tests { t_Configurable configurable; typename t_Visitor::Writer::Parameters parameters; - parameters.write_.allow_missing_entries_ = true; + parameters.template get().allow_missing_entries_ = true; ariles2::apply( getWriterInitializer("configurable2.cfg"), configurable, parameters); diff --git a/tests/api_v2/fixtures/021_optional_comparison.h b/tests/api_v2/fixtures/021_optional_comparison.h index db432ac7..32dba923 100644 --- a/tests/api_v2/fixtures/021_optional_comparison.h +++ b/tests/api_v2/fixtures/021_optional_comparison.h @@ -37,10 +37,10 @@ namespace ariles_tests void test() { typename t_Visitor::Writer::Parameters writer_parameters; - writer_parameters.write_.allow_missing_entries_ = true; + writer_parameters.template get().allow_missing_entries_ = true; typename t_Visitor::Reader::Parameters reader_parameters; - reader_parameters.read_.allow_missing_entries_ = true; + reader_parameters.template get().allow_missing_entries_ = true; { t_Configurable configurable_out; diff --git a/tests/api_v2/regression_test_223.cpp b/tests/api_v2/regression_test_223.cpp index 7a71117c..9a0c9a58 100644 --- a/tests/api_v2/regression_test_223.cpp +++ b/tests/api_v2/regression_test_223.cpp @@ -79,7 +79,7 @@ namespace ariles_tests BOOST_CHECK_NO_THROW({ typename t_Visitor::Writer::Parameters parameters; - parameters.write_.fallback_to_string_floats_ = false; + parameters.template get().fallback_to_string_floats_ = false; typename t_Visitor::Writer writer("configurable.cfg"); ariles2::apply(writer, configurable, parameters); }); diff --git a/tests/api_v2/types/copy/Header.h b/tests/api_v2/types/copy/Header.h index 750a5388..e08038ea 100644 --- a/tests/api_v2/types/copy/Header.h +++ b/tests/api_v2/types/copy/Header.h @@ -30,7 +30,7 @@ namespace std_msgs _stamp_type stamp; typedef std:: - basic_string, typename ContainerAllocator::template rebind::other> + basic_string> _frame_id_type; _frame_id_type frame_id; }; // struct Header_ diff --git a/tests/api_v2/types/copy/MultiDOFJointTrajectory.h b/tests/api_v2/types/copy/MultiDOFJointTrajectory.h index 00cdc69f..7b1b2635 100644 --- a/tests/api_v2/types/copy/MultiDOFJointTrajectory.h +++ b/tests/api_v2/types/copy/MultiDOFJointTrajectory.h @@ -31,19 +31,12 @@ namespace trajectory_msgs typedef std::vector< std::basic_string< char, - std::char_traits, - typename ContainerAllocator::template rebind::other>, - typename ContainerAllocator::template rebind, - typename ContainerAllocator::template rebind::other>>::other> + std::char_traits>> _joint_names_type; _joint_names_type joint_names; typedef std::vector< - ::trajectory_msgs::MultiDOFJointTrajectoryPoint_, - typename ContainerAllocator::template rebind< - ::trajectory_msgs::MultiDOFJointTrajectoryPoint_>::other> + ::trajectory_msgs::MultiDOFJointTrajectoryPoint_> _points_type; _points_type points; }; // struct MultiDOFJointTrajectory_ diff --git a/tests/api_v2/types/copy/MultiDOFJointTrajectoryPoint.h b/tests/api_v2/types/copy/MultiDOFJointTrajectoryPoint.h index 533919d5..b91df0f4 100644 --- a/tests/api_v2/types/copy/MultiDOFJointTrajectoryPoint.h +++ b/tests/api_v2/types/copy/MultiDOFJointTrajectoryPoint.h @@ -27,20 +27,17 @@ namespace trajectory_msgs typedef std::vector< - ::geometry_msgs::Transform_, - typename ContainerAllocator::template rebind<::geometry_msgs::Transform_>::other> + ::geometry_msgs::Transform_> _transforms_type; _transforms_type transforms; typedef std::vector< - ::geometry_msgs::Twist_, - typename ContainerAllocator::template rebind<::geometry_msgs::Twist_>::other> + ::geometry_msgs::Twist_> _velocities_type; _velocities_type velocities; typedef std::vector< - ::geometry_msgs::Twist_, - typename ContainerAllocator::template rebind<::geometry_msgs::Twist_>::other> + ::geometry_msgs::Twist_> _accelerations_type; _accelerations_type accelerations;