Skip to content

Commit

Permalink
Fix std::vector<bool> handling
Browse files Browse the repository at this point in the history
  • Loading branch information
asherikov committed Jul 22, 2024
1 parent 604a9bb commit d1b7efc
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 0 deletions.
32 changes: 32 additions & 0 deletions include/ariles2/adapters/std_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,23 @@ namespace ariles2
}
visitor.endArray();
}

template <class t_Visitor, class... t_Args>
void ARILES2_VISIBILITY_ATTRIBUTE apply_read(
t_Visitor &visitor,
std::vector<bool, t_Args...> &entry,
const typename t_Visitor::Parameters &param)
{
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

Expand Down Expand Up @@ -126,6 +143,21 @@ namespace ariles2
apply_process(visitor, value, param);
}
}

template <class t_Visitor, class... t_Args>
void ARILES2_VISIBILITY_ATTRIBUTE apply_process(
const t_Visitor &visitor,
std::vector<bool, t_Args...> &entry,
const typename t_Visitor::Parameters &param)
{
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

Expand Down
10 changes: 10 additions & 0 deletions tests/api_v2/regression_test_226.ref
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down
1 change: 1 addition & 0 deletions tests/api_v2/types/complex_auto_declare.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace ariles_tests
ARILES2_TYPED_ENTRY_(v, complex_float, std::complex<float>) \
ARILES2_TYPED_ENTRY_(v, string, std::string) \
ARILES2_TYPED_ENTRY_(v, std_vector, std::vector<double>) \
ARILES2_TYPED_ENTRY_(v, std_vector_bool, std::vector<bool>) \
ARILES2_TYPED_ENTRY_(v, std_nested_vector, std::vector<std::vector<double>>) \
ARILES2_TYPED_ENTRY_(v, some_enum, SomeEnum) \
ARILES2_TYPED_ENTRY_(v, boolean_true, bool) \
Expand Down
9 changes: 9 additions & 0 deletions tests/api_v2/types/complex_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -221,13 +225,18 @@ 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)
{
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)
{
Expand Down
2 changes: 2 additions & 0 deletions tests/api_v2/types/complex_verbose.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down Expand Up @@ -71,6 +72,7 @@ namespace ariles_tests


std::vector<double> std_vector_;
std::vector<bool> std_vector_bool_;
std::vector<std::vector<double>> std_nested_vector_;

std::string string_;
Expand Down
1 change: 1 addition & 0 deletions tests/api_v2/types/copy/complex.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace ariles_tests


std::vector<double> std_vector;
std::vector<bool> std_vector_bool;
std::vector<std::vector<double>> std_nested_vector;

std::string string;
Expand Down

0 comments on commit d1b7efc

Please sign in to comment.