From d1b7efc973746cd78a891644c71d617082b5e253 Mon Sep 17 00:00:00 2001 From: Alexander Sherikov Date: Tue, 23 Jul 2024 00:00:41 +0400 Subject: [PATCH] Fix std::vector handling --- include/ariles2/adapters/std_vector.h | 32 +++++++++++++++++++++++ tests/api_v2/regression_test_226.ref | 10 +++++++ tests/api_v2/types/complex_auto_declare.h | 1 + tests/api_v2/types/complex_base.h | 9 +++++++ tests/api_v2/types/complex_verbose.h | 2 ++ tests/api_v2/types/copy/complex.h | 1 + 6 files changed, 55 insertions(+) diff --git a/include/ariles2/adapters/std_vector.h b/include/ariles2/adapters/std_vector.h index 41df9855..0569c7b0 100644 --- a/include/ariles2/adapters/std_vector.h +++ b/include/ariles2/adapters/std_vector.h @@ -42,6 +42,23 @@ namespace ariles2 } visitor.endArray(); } + + template + void ARILES2_VISIBILITY_ATTRIBUTE apply_read( + t_Visitor &visitor, + std::vector &entry, + const typename t_Visitor::Parameters ¶m) + { + CPPUT_TRACE_FUNCTION; + entry.resize(visitor.startArray()); + for (std::size_t i = 0; i < entry.size(); ++i) + { + bool value; + visitor.visitArrayElement(value, param); + entry[i] = value; + } + visitor.endArray(); + } } // namespace read } // namespace ariles2 @@ -126,6 +143,21 @@ namespace ariles2 apply_process(visitor, value, param); } } + + template + void ARILES2_VISIBILITY_ATTRIBUTE apply_process( + const t_Visitor &visitor, + std::vector &entry, + const typename t_Visitor::Parameters ¶m) + { + CPPUT_TRACE_FUNCTION; + for (std::size_t i = 0; i < entry.size(); ++i) + { + bool value = entry[i]; + apply_process(visitor, value, param); + entry[i] = value; + } + } } // namespace process } // namespace ariles2 diff --git a/tests/api_v2/regression_test_226.ref b/tests/api_v2/regression_test_226.ref index 84a0e5ff..20dbc33d 100644 --- a/tests/api_v2/regression_test_226.ref +++ b/tests/api_v2/regression_test_226.ref @@ -23,6 +23,16 @@ ariles_std_vector_3[label="std_vector_3"]; ariles_std_vector->ariles_std_vector_3; ariles_std_vector_4[label="std_vector_4"]; ariles_std_vector->ariles_std_vector_4; +ariles_std_vector_bool[label="std_vector_bool"]; +ariles->ariles_std_vector_bool; +ariles_std_vector_bool_0[label="std_vector_bool_0"]; +ariles_std_vector_bool->ariles_std_vector_bool_0; +ariles_std_vector_bool_1[label="std_vector_bool_1"]; +ariles_std_vector_bool->ariles_std_vector_bool_1; +ariles_std_vector_bool_2[label="std_vector_bool_2"]; +ariles_std_vector_bool->ariles_std_vector_bool_2; +ariles_std_vector_bool_3[label="std_vector_bool_3"]; +ariles_std_vector_bool->ariles_std_vector_bool_3; ariles_std_nested_vector[label="std_nested_vector"]; ariles->ariles_std_nested_vector; ariles_std_nested_vector_0[label="std_nested_vector_0"]; diff --git a/tests/api_v2/types/complex_auto_declare.h b/tests/api_v2/types/complex_auto_declare.h index 6aac749a..de0ed8da 100644 --- a/tests/api_v2/types/complex_auto_declare.h +++ b/tests/api_v2/types/complex_auto_declare.h @@ -23,6 +23,7 @@ namespace ariles_tests ARILES2_TYPED_ENTRY_(v, complex_float, std::complex) \ ARILES2_TYPED_ENTRY_(v, string, std::string) \ ARILES2_TYPED_ENTRY_(v, std_vector, std::vector) \ + ARILES2_TYPED_ENTRY_(v, std_vector_bool, std::vector) \ ARILES2_TYPED_ENTRY_(v, std_nested_vector, std::vector>) \ ARILES2_TYPED_ENTRY_(v, some_enum, SomeEnum) \ ARILES2_TYPED_ENTRY_(v, boolean_true, bool) \ diff --git a/tests/api_v2/types/complex_base.h b/tests/api_v2/types/complex_base.h index 12e277eb..446c83f2 100644 --- a/tests/api_v2/types/complex_base.h +++ b/tests/api_v2/types/complex_base.h @@ -51,6 +51,8 @@ namespace ariles_tests impl->std_vector_[i] = i * 5.22 + 2.3; } + impl->std_vector_bool_ = {false, false, true, false}; + impl->std_nested_vector_.resize(3); for (std::size_t i = 0; i < impl->std_nested_vector_.size(); ++i) { @@ -131,6 +133,8 @@ namespace ariles_tests impl->std_vector_[i] = GET_RANDOM_REAL; } + impl->std_vector_bool_ = {false, true, false}; + impl->std_nested_vector_.resize(3); for (std::size_t i = 0; i < impl->std_nested_vector_.size(); ++i) { @@ -221,6 +225,7 @@ namespace ariles_tests BOOST_CHECK_EQUAL(configurable_out.better_enum_, configurable_in.better_enum_); BOOST_CHECK_EQUAL(configurable_out.std_vector_.size(), configurable_in.std_vector_.size()); + BOOST_CHECK_EQUAL(configurable_out.std_vector_bool_.size(), configurable_in.std_vector_bool_.size()); BOOST_CHECK_EQUAL(configurable_out.std_nested_vector_.size(), configurable_in.std_nested_vector_.size()); for (std::size_t i = 0; i < configurable_out.std_vector_.size(); ++i) @@ -228,6 +233,10 @@ namespace ariles_tests BOOST_CHECK_CLOSE(configurable_out.std_vector_[i], configurable_in.std_vector_[i], g_tolerance); } + for (std::size_t i = 0; i < configurable_out.std_vector_bool_.size(); ++i) + { + BOOST_CHECK_EQUAL(configurable_out.std_vector_bool_[i], configurable_in.std_vector_bool_[i]); + } for (std::size_t i = 0; i < configurable_out.std_nested_vector_.size(); ++i) { diff --git a/tests/api_v2/types/complex_verbose.h b/tests/api_v2/types/complex_verbose.h index a0aa6e2e..12be0e4f 100644 --- a/tests/api_v2/types/complex_verbose.h +++ b/tests/api_v2/types/complex_verbose.h @@ -24,6 +24,7 @@ namespace ariles_tests ARILES2_ENTRY_(v, complex_float) \ ARILES2_ENTRY_(v, string) \ ARILES2_ENTRY_(v, std_vector) \ + ARILES2_ENTRY_(v, std_vector_bool) \ ARILES2_ENTRY_(v, std_nested_vector) \ ARILES2_ENTRY_(v, some_enum) \ ARILES2_ENTRY_(v, boolean_true) \ @@ -71,6 +72,7 @@ namespace ariles_tests std::vector std_vector_; + std::vector std_vector_bool_; std::vector> std_nested_vector_; std::string string_; diff --git a/tests/api_v2/types/copy/complex.h b/tests/api_v2/types/copy/complex.h index cf4dd461..c090b8a6 100644 --- a/tests/api_v2/types/copy/complex.h +++ b/tests/api_v2/types/copy/complex.h @@ -22,6 +22,7 @@ namespace ariles_tests std::vector std_vector; + std::vector std_vector_bool; std::vector> std_nested_vector; std::string string;