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/extra_visitors/protobuf3/ariles2/visitors/protobuf3/reader.h b/extra_visitors/protobuf3/ariles2/visitors/protobuf3/reader.h index ef48a68a..2cf96b55 100644 --- a/extra_visitors/protobuf3/ariles2/visitors/protobuf3/reader.h +++ b/extra_visitors/protobuf3/ariles2/visitors/protobuf3/reader.h @@ -14,15 +14,13 @@ namespace ariles2 { namespace ns_protobuf3 { - class ARILES2_VISIBILITY_ATTRIBUTE Reader : public visitor::Base + class ARILES2_VISIBILITY_ATTRIBUTE Reader : public visitor::Base { public: using Parameters = visitor::Parameters; public: - using visitor::Base::getDefaultParameters; - template const Parameters &getParameters(const t_Ariles &ariles_class) const { diff --git a/extra_visitors/protobuf3/ariles2/visitors/protobuf3/writer.h b/extra_visitors/protobuf3/ariles2/visitors/protobuf3/writer.h index 1bd59994..9e6ebeaa 100644 --- a/extra_visitors/protobuf3/ariles2/visitors/protobuf3/writer.h +++ b/extra_visitors/protobuf3/ariles2/visitors/protobuf3/writer.h @@ -14,15 +14,13 @@ namespace ariles2 { namespace ns_protobuf3 { - class ARILES2_VISIBILITY_ATTRIBUTE Writer : public visitor::Base + class ARILES2_VISIBILITY_ATTRIBUTE Writer : public visitor::Base { public: using Parameters = visitor::Parameters; public: - using visitor::Base::getDefaultParameters; - template const Parameters &getParameters(const t_Ariles &ariles_class) const { diff --git a/include/ariles2/adapters/basic.h b/include/ariles2/adapters/basic.h index c40b9227..15e9c2f1 100644 --- a/include/ariles2/adapters/basic.h +++ b/include/ariles2/adapters/basic.h @@ -148,7 +148,7 @@ namespace ariles2 const t_Left &left, const t_Right &right, const typename t_Visitor::Parameters ¶m, - ARILES2_IS_BASE_ENABLER(ariles2::Ariles, t_Left)) + ARILES2_IS_ARILES_ENABLER(t_Left)) { ARILES2_TRACE_FUNCTION; if (param.compare_number_of_entries_) @@ -294,7 +294,7 @@ namespace ariles2 const t_Visitor &visitor, t_Entry &entry, const typename t_Visitor::Parameters ¶m, - ARILES2_IS_BASE_ENABLER(ariles2::Ariles, t_Entry)) + ARILES2_IS_ARILES_ENABLER(t_Entry)) { ARILES2_TRACE_FUNCTION; entry.arilesVirtualVisit(visitor, param); @@ -306,7 +306,7 @@ namespace ariles2 const t_Visitor &, t_Entry &, const typename t_Visitor::Parameters &, - ARILES2_IS_BASE_DISABLER(ariles2::Ariles, t_Entry)) + ARILES2_IS_ARILES_DISABLER(t_Entry)) { ARILES2_TRACE_FUNCTION; } @@ -325,7 +325,7 @@ namespace ariles2 t_Left &left, const t_Right &right, const typename t_Visitor::Parameters ¶m, - ARILES2_IS_BASE_ENABLER(ariles2::Ariles, t_Left)) + ARILES2_IS_ARILES_ENABLER(t_Left)) { ARILES2_TRACE_FUNCTION; ARILES2_TRACE_TYPE(left); @@ -371,7 +371,7 @@ namespace ariles2 const t_Left &left, t_Right &right, const typename t_Visitor::Parameters ¶m, - ARILES2_IS_BASE_ENABLER(ariles2::Ariles, t_Left)) + ARILES2_IS_ARILES_ENABLER(t_Left)) { ARILES2_TRACE_FUNCTION; ARILES2_TRACE_TYPE(left); diff --git a/include/ariles2/internal/helpers.h b/include/ariles2/internal/helpers.h index 9b3088a2..71157982 100644 --- a/include/ariles2/internal/helpers.h +++ b/include/ariles2/internal/helpers.h @@ -26,18 +26,24 @@ #define ARILES2_IS_FLOATING_POINT_ENABLER_TYPE(Real) std::enable_if<(std::is_floating_point::value)>::type * -#define ARILES2_IS_BASE_OF(Base, Derived) std::is_base_of::value - #define ARILES2_IS_BASE_ENABLER(Base, Derived) \ - const typename std::enable_if<(ARILES2_IS_BASE_OF(Base, Derived))>::type * = nullptr + const typename std::enable_if::value>::type * = nullptr #define ARILES2_IS_BASE_DISABLER(Base, Derived) \ - const typename std::enable_if::type * = nullptr + const typename std::enable_if::value>::type * = nullptr #define ARILES2_IS_ANY_OF(Type, Type1, Type2) \ const typename std::enable_if::value or std::is_base_of::value>::type \ * = nullptr +#define ARILES2_IS_VISITOR_ENABLER(Derived) \ + const typename std::enable_if::value>::type * = nullptr + +#define ARILES2_IS_ARILES_ENABLER(Derived) \ + const typename std::enable_if::value>::type * = nullptr + +#define ARILES2_IS_ARILES_DISABLER(Derived) \ + const typename std::enable_if::value>::type * = nullptr #include "build_config.h" diff --git a/include/ariles2/members/visit_generic_parent.h b/include/ariles2/members/visit_generic_parent.h index eb0c2acf..594ca118 100644 --- a/include/ariles2/members/visit_generic_parent.h +++ b/include/ariles2/members/visit_generic_parent.h @@ -14,7 +14,7 @@ void arilesVisitParents( \ t_Visitor &visitor, \ const typename t_Visitor::Parameters ¶meters, \ - ARILES2_IS_BASE_ENABLER(ariles2::visitor::GenericVisitor, t_Visitor)) \ + ARILES2_IS_VISITOR_ENABLER(t_Visitor)) \ { \ ARILES2_UNUSED_ARG(visitor); \ ARILES2_UNUSED_ARG(parameters); \ @@ -25,7 +25,7 @@ void arilesVisitParents( \ t_Visitor &visitor, \ const typename t_Visitor::Parameters ¶meters, \ - ARILES2_IS_BASE_ENABLER(ariles2::visitor::GenericVisitor, t_Visitor)) const \ + ARILES2_IS_VISITOR_ENABLER(t_Visitor)) const \ { \ ARILES2_UNUSED_ARG(visitor); \ ARILES2_UNUSED_ARG(parameters); \ diff --git a/include/ariles2/visitors/aggregate.h b/include/ariles2/visitors/aggregate.h new file mode 100644 index 00000000..2fa7afd7 --- /dev/null +++ b/include/ariles2/visitors/aggregate.h @@ -0,0 +1,158 @@ +/** + @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 ParametersWrapper + { + public: + typename t_Visitor::Parameters parameters_; + + public: + ParametersWrapper(const bool override_parameters = true) : parameters_(override_parameters) + { + } + + ParametersWrapper(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 ParametersWrapper, + public Parameters + { + public: + Parameters(const bool override_parameters = true) + : ParametersWrapper(override_parameters), Parameters(override_parameters) + { + } + + template + Parameters(const typename t_Visitor::Parameters ¶meters, t_Parameters &&...other_parameters) + : ParametersWrapper(parameters) + , Parameters(std::forward(other_parameters)...) + { + } + + template + Parameters(const t_Parameters ¶meters, const bool override_parameters = true) + : ParametersWrapper(override_parameters) + , Parameters(parameters, override_parameters) + { + } + + Parameters(const typename t_Visitor::Parameters ¶meters, const bool override_parameters = true) + : ParametersWrapper(parameters), Parameters(override_parameters) + { + } + + using ParametersWrapper::get; + using Parameters::get; + }; + + + + /* + template + class ARILES2_VISIBILITY_ATTRIBUTE BaseVisitorWrapper + { + public: + t_Visitor visitor_; + + public: + BaseVisitorWrapper() {}; + + template + BaseVisitorWrapper(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 BaseVisitorWrapper, + public BaseVisitor + { + }; + + + template + class ARILES2_VISIBILITY_ATTRIBUTE Visitor + : public BaseVisitor, + public visitor::Base> + { + public: + using Parameters = aggregate::Parameters; + }; + } // namespace aggregate +} // namespace ariles2 diff --git a/include/ariles2/visitors/common.h b/include/ariles2/visitors/common.h index 25ffc8a4..3b26146d 100644 --- a/include/ariles2/visitors/common.h +++ b/include/ariles2/visitors/common.h @@ -31,7 +31,7 @@ namespace ariles2 }; - class ARILES2_VISIBILITY_ATTRIBUTE Visitor + class Visitor { protected: Visitor(){}; @@ -39,29 +39,25 @@ namespace ariles2 }; - class ARILES2_VISIBILITY_ATTRIBUTE GenericVisitor : public Visitor - { - protected: - GenericVisitor(){}; - ~GenericVisitor(){}; - }; - - - template - class ARILES2_VISIBILITY_ATTRIBUTE Base : public t_Visitor + template + class ARILES2_VISIBILITY_ATTRIBUTE Base : public Visitor { public: using ReturnType = t_ReturnType; + using Parameters = t_Parameters; - protected: - Base(){}; - ~Base(){}; - + public: const t_Parameters &getDefaultParameters() const { const static t_Parameters parameters(false); return parameters; } + + template + const t_Parameters &getParameters(const t_Ariles &ariles_class) const + { + return (ariles_class.arilesGetParameters(*static_cast(this))); + } }; } // namespace visitor @@ -130,7 +126,7 @@ namespace ariles2 const t_Subtree &subtree, const typename t_Visitor::Parameters ¶m, ARILES2_IS_ANY_OF(t_Subtree, std::string, std::vector), - ARILES2_IS_BASE_ENABLER(ariles2::visitor::Visitor, t_Visitor)) + ARILES2_IS_VISITOR_ENABLER(t_Visitor)) { ARILES2_TRACE_FUNCTION; return (visitor.visit(ariles_class, subtree, param)); @@ -143,7 +139,7 @@ namespace ariles2 t_Ariles &ariles_class, const char *name, const typename t_Visitor::Parameters ¶m, - ARILES2_IS_BASE_ENABLER(ariles2::visitor::Visitor, t_Visitor)) + ARILES2_IS_VISITOR_ENABLER(t_Visitor)) { ARILES2_TRACE_FUNCTION; return (visitor.visit(ariles_class, name, param)); @@ -155,7 +151,7 @@ namespace ariles2 t_Visitor &visitor, t_Ariles &ariles_class, const typename t_Visitor::Parameters ¶m, - ARILES2_IS_BASE_ENABLER(ariles2::visitor::Visitor, t_Visitor)) + ARILES2_IS_VISITOR_ENABLER(t_Visitor)) { ARILES2_TRACE_FUNCTION; return (ariles2::apply(visitor, ariles_class, ariles_class.arilesDefaultID(), param)); @@ -168,7 +164,7 @@ namespace ariles2 t_Ariles &ariles_class, const t_Subtree &subtree, ARILES2_IS_ANY_OF(t_Subtree, std::string, std::vector), - ARILES2_IS_BASE_ENABLER(ariles2::visitor::Visitor, t_Visitor)) + ARILES2_IS_VISITOR_ENABLER(t_Visitor)) { ARILES2_TRACE_FUNCTION; return (visitor.visit(ariles_class, subtree, visitor.getParameters(ariles_class))); @@ -180,7 +176,7 @@ namespace ariles2 t_Visitor &visitor, t_Ariles &ariles_class, const char *name, - ARILES2_IS_BASE_ENABLER(ariles2::visitor::Visitor, t_Visitor)) + ARILES2_IS_VISITOR_ENABLER(t_Visitor)) { ARILES2_TRACE_FUNCTION; return (visitor.visit(ariles_class, name, visitor.getParameters(ariles_class))); @@ -191,7 +187,7 @@ namespace ariles2 typename t_Visitor::ReturnType apply( t_Visitor &visitor, t_Ariles &ariles_class, - ARILES2_IS_BASE_ENABLER(ariles2::visitor::Visitor, t_Visitor)) + ARILES2_IS_VISITOR_ENABLER(t_Visitor)) { ARILES2_TRACE_FUNCTION; return (ariles2::apply(visitor, ariles_class, ariles_class.arilesDefaultID())); @@ -201,8 +197,8 @@ namespace ariles2 template typename t_Visitor::ReturnType apply( t_Ariles &ariles_class, - ARILES2_IS_BASE_ENABLER(ariles2::Ariles, t_Ariles), - ARILES2_IS_BASE_ENABLER(ariles2::visitor::Visitor, t_Visitor)) + ARILES2_IS_ARILES_ENABLER(t_Ariles), + ARILES2_IS_VISITOR_ENABLER(t_Visitor)) { ARILES2_TRACE_FUNCTION; t_Visitor visitor; @@ -257,8 +253,8 @@ namespace ariles2 typename t_Visitor::ReturnType apply( t_Left &left, t_Right &right, - ARILES2_IS_BASE_ENABLER(ariles2::visitor::Visitor, t_Visitor), - ARILES2_IS_BASE_ENABLER(ariles2::Ariles, t_Left)) + ARILES2_IS_VISITOR_ENABLER(t_Visitor), + ARILES2_IS_ARILES_ENABLER(t_Left)) { ARILES2_TRACE_FUNCTION; t_Visitor visitor; @@ -273,7 +269,7 @@ namespace ariles2 t_Right &right, const std::string &name, const typename t_Visitor::Parameters ¶m, - ARILES2_IS_BASE_ENABLER(ariles2::visitor::Visitor, t_Visitor)) + ARILES2_IS_VISITOR_ENABLER(t_Visitor)) { ARILES2_TRACE_FUNCTION; return (visitor.visit(left, right, name, param)); @@ -287,7 +283,7 @@ namespace ariles2 t_Right &right, ARILES2_IS_BASE_DISABLER(typename t_Visitor::Parameters, t_Right), ARILES2_IS_BASE_DISABLER(std::string, t_Right), - ARILES2_IS_BASE_ENABLER(ariles2::visitor::Visitor, t_Visitor)) + ARILES2_IS_VISITOR_ENABLER(t_Visitor)) { ARILES2_TRACE_FUNCTION; return (visitor.visit(left, right, left.arilesDefaultID(), visitor.getParameters(left))); @@ -300,7 +296,7 @@ namespace ariles2 t_Left &left, t_Right &right, const typename t_Visitor::Parameters ¶m, - ARILES2_IS_BASE_ENABLER(ariles2::visitor::Visitor, t_Visitor)) + ARILES2_IS_VISITOR_ENABLER(t_Visitor)) { ARILES2_TRACE_FUNCTION; return (ariles2::apply(visitor, left, right, left.arilesDefaultID(), param)); diff --git a/include/ariles2/visitors/compare.h b/include/ariles2/visitors/compare.h index ede2c8e6..49efe1f0 100644 --- a/include/ariles2/visitors/compare.h +++ b/include/ariles2/visitors/compare.h @@ -64,7 +64,7 @@ namespace ariles2 }; - class ARILES2_VISIBILITY_ATTRIBUTE Visitor : public visitor::Base + class ARILES2_VISIBILITY_ATTRIBUTE Visitor : public visitor::Base { public: using Parameters = compare::Parameters; @@ -76,15 +76,6 @@ namespace ariles2 public: - using visitor::Base::getDefaultParameters; - - template - const Parameters &getParameters(const t_Ariles &ariles_class) const - { - return (ariles_class.arilesGetParameters(*this)); - } - - template bool visit(const t_Left &left, const t_Right &right, const std::string &name, const Parameters ¶m) { diff --git a/include/ariles2/visitors/config.h b/include/ariles2/visitors/config.h index 1733536c..36dca91d 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,29 @@ namespace ariles2 namespace cfgread { template - class ARILES2_VISIBILITY_ATTRIBUTE Parameters + class ARILES2_VISIBILITY_ATTRIBUTE Visitor + : public aggregate::Visitor, preread::Visitor, t_Reader, postread::Visitor> { public: - ariles2::preread::Visitor::Parameters preread_; - typename t_Reader::Parameters read_; - ariles2::postread::Visitor::Parameters postread_; + using AggregateBase = + aggregate::Visitor, preread::Visitor, t_Reader, postread::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 +64,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 +91,27 @@ 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, prewrite::Visitor, t_Writer> { public: - using Parameters = cfgwrite::Parameters; + using AggregateBase = aggregate::Visitor, prewrite::Visitor, t_Writer>; + 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 +127,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/copyfrom.h b/include/ariles2/visitors/copyfrom.h index f04fbad8..76f5b1c3 100644 --- a/include/ariles2/visitors/copyfrom.h +++ b/include/ariles2/visitors/copyfrom.h @@ -36,22 +36,13 @@ namespace ariles2 }; - class ARILES2_VISIBILITY_ATTRIBUTE Visitor : public visitor::Base + class ARILES2_VISIBILITY_ATTRIBUTE Visitor : public visitor::Base { public: using Parameters = copyfrom::Parameters; public: - using visitor::Base::getDefaultParameters; - - template - const Parameters &getParameters(const t_Ariles &ariles_class) const - { - return (ariles_class.arilesGetParameters(*this)); - } - - template void visit(t_Left &left, const t_Right &right, const std::string &name, const Parameters ¶m) { diff --git a/include/ariles2/visitors/copyto.h b/include/ariles2/visitors/copyto.h index 047460ac..e2cfd7b2 100644 --- a/include/ariles2/visitors/copyto.h +++ b/include/ariles2/visitors/copyto.h @@ -36,22 +36,13 @@ namespace ariles2 }; - class ARILES2_VISIBILITY_ATTRIBUTE Visitor : public visitor::Base + class ARILES2_VISIBILITY_ATTRIBUTE Visitor : public visitor::Base { public: using Parameters = copyto::Parameters; public: - using visitor::Base::getDefaultParameters; - - template - const Parameters &getParameters(const t_Ariles &ariles_class) const - { - return (ariles_class.arilesGetParameters(*this)); - } - - template void visit(const t_Left &left, t_Right &right, const std::string &name, const Parameters ¶m) { diff --git a/include/ariles2/visitors/count.h b/include/ariles2/visitors/count.h index 24c9555b..a3cdbe3d 100644 --- a/include/ariles2/visitors/count.h +++ b/include/ariles2/visitors/count.h @@ -33,22 +33,13 @@ namespace ariles2 class ARILES2_VISIBILITY_ATTRIBUTE Visitor - : public ariles2::visitor::Base + : public ariles2::visitor::Base { public: using Parameters = count::Parameters; public: - using visitor::Base::getDefaultParameters; - - template - const Parameters &getParameters(const t_Ariles &ariles_class) const - { - return (ariles_class.arilesGetParameters(*this)); - } - - template std::size_t visit(const t_Entry &entry, const std::string &, const Parameters ¶m) const { diff --git a/include/ariles2/visitors/count_missing.h b/include/ariles2/visitors/count_missing.h index 9d0673c6..62ef0338 100644 --- a/include/ariles2/visitors/count_missing.h +++ b/include/ariles2/visitors/count_missing.h @@ -33,22 +33,13 @@ namespace ariles2 class ARILES2_VISIBILITY_ATTRIBUTE Visitor - : public ariles2::visitor::Base + : public ariles2::visitor::Base { public: using Parameters = count::Parameters; public: - using visitor::Base::getDefaultParameters; - - template - const Parameters &getParameters(const t_Ariles &ariles_class) const - { - return (ariles_class.arilesGetParameters(*this)); - } - - template std::size_t visit(const t_Entry &entry, const std::string &, const Parameters ¶m) const { diff --git a/include/ariles2/visitors/defaults.h b/include/ariles2/visitors/defaults.h index 7a61dc5b..d4814229 100644 --- a/include/ariles2/visitors/defaults.h +++ b/include/ariles2/visitors/defaults.h @@ -55,21 +55,13 @@ namespace ariles2 class ARILES2_VISIBILITY_ATTRIBUTE Visitor - : public ariles2::visitor::Base + : public ariles2::visitor::Base { public: using Parameters = defaults::Parameters; public: - using visitor::Base::getDefaultParameters; - - template - const Parameters &getParameters(const t_Ariles &ariles_class) const - { - return (ariles_class.arilesGetParameters(*this)); - } - template void visit(t_Entry &entry, const std::string &name, const Parameters ¶m) const { @@ -77,6 +69,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/include/ariles2/visitors/process.h b/include/ariles2/visitors/process.h index eec60270..b23a923c 100644 --- a/include/ariles2/visitors/process.h +++ b/include/ariles2/visitors/process.h @@ -24,22 +24,13 @@ namespace ariles2 { template class ARILES2_VISIBILITY_ATTRIBUTE Visitor - : public ariles2::visitor::Base + : public ariles2::visitor::Base { public: using Parameters = t_Parameters; public: - using visitor::Base::getDefaultParameters; - - template - const t_Parameters &getParameters(const t_Ariles &ariles_class) const - { - return (ariles_class.arilesGetParameters(*(static_cast(this)))); - } - - template void visit(t_Entry &entry, const std::string &name, const Parameters ¶m) const { diff --git a/include/ariles2/visitors/read.h b/include/ariles2/visitors/read.h index 0a8d7753..a197f8ce 100644 --- a/include/ariles2/visitors/read.h +++ b/include/ariles2/visitors/read.h @@ -44,10 +44,6 @@ namespace ariles2 protected: - Visitor(){}; - ~Visitor(){}; - - void checkSize( const SizeLimitEnforcementType limit_type, const std::size_t size = 0, diff --git a/include/ariles2/visitors/serialization.h b/include/ariles2/visitors/serialization.h index 32584b98..e7333906 100644 --- a/include/ariles2/visitors/serialization.h +++ b/include/ariles2/visitors/serialization.h @@ -145,21 +145,7 @@ namespace ariles2 }; - template - class ARILES2_VISIBILITY_ATTRIBUTE Base : public visitor::Base - { - public: - using Parameters = t_Parameters; - - - public: - using visitor::Base::getDefaultParameters; - - template - const t_Parameters &getParameters(const t_Ariles &ariles_class) const - { - return (ariles_class.arilesGetParameters(*static_cast(this))); - } - }; + template + using Base = visitor::Base; } // namespace serialization } // namespace ariles2 diff --git a/include/ariles2/visitors/write.h b/include/ariles2/visitors/write.h index 756f8e37..c0b28bbb 100644 --- a/include/ariles2/visitors/write.h +++ b/include/ariles2/visitors/write.h @@ -44,11 +44,6 @@ namespace ariles2 template class ARILES2_VISIBILITY_ATTRIBUTE VisitorBase : public serialization::Base { - protected: - VisitorBase(){}; - ~VisitorBase(){}; - - public: /** * @brief open configuration file 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;