Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: eProsima/DDS-Pipe
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 9a32119b519eda0a14cbea4d2bc1f306bf14682a
Choose a base ref
..
head repository: eProsima/DDS-Pipe
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 5ac72b1563b50cbc23f6f96a12a0e09e6cdcb9a1
Choose a head ref
21 changes: 20 additions & 1 deletion ddspipe_yaml/include/ddspipe_yaml/YamlWriter.hpp
Original file line number Diff line number Diff line change
@@ -65,9 +65,28 @@ void set(
Yaml& yml,
const T& value);

//! Set the \c value in a new yaml in \c yml under \c tag .
/**
* @brief Set a new value in \c yml .
*
* This function is intended to be specialized for different types, defining the method to serialize into YAML
* when two possible formats (compact and extended) are available.
* Depending on the \c is_compact flag, the serialization will be in either compact or extended format.
*
* @param[in,out] yaml base yaml where to write the value
* @param[in] value value to write
* @param[in] is_compact boolean value to set the format of the yaml
*
* @tparam T type of the value to set in the yaml.
*/
template <typename T>
void set(
Yaml& yml,
const T& value,
bool is_compact);

//! Set the \c value in a new yaml in \c yml under \c tag .
template <typename T>
void set_in_tag(
Yaml& yml,
const TagType& tag,
const T& value);
31 changes: 30 additions & 1 deletion ddspipe_yaml/include/ddspipe_yaml/impl/YamlWriter.ipp
Original file line number Diff line number Diff line change
@@ -48,6 +48,12 @@ void set_collection(
Yaml& yml,
const std::vector<T>& collection);

template <typename T>
void set_collection(
Yaml& yml,
const std::vector<T>& collection,
bool is_compact);

template <typename K, typename T>
void set_map(
Yaml& yml,
@@ -87,6 +93,15 @@ void set(
set_collection(yml, collection);
}

template <typename T>
void set(
Yaml& yml,
const std::vector<T>& collection,
bool is_compact)
{
set_collection(yml, collection, is_compact);
}

template <typename T>
void set(
Yaml& yml,
@@ -108,7 +123,7 @@ void set(
////////////////////////////////////

template <typename T>
void set(
void set_in_tag(
Yaml& yml,
const TagType& tag,
const T& value)
@@ -130,6 +145,20 @@ void set_collection(
}
}

template <typename T>
void set_collection(
Yaml& yml,
const std::vector<T>& collection,
bool is_compact)
{
for (const auto& v : collection)
{
Yaml yml_value;
set<T>(yml_value, v, is_compact);
yml.push_back(yml_value);
}
}

template <typename K, typename T>
void set_map(
Yaml& yml,
12 changes: 6 additions & 6 deletions ddspipe_yaml/test/unittest/yaml_writer/YamlWriterTest.cpp
Original file line number Diff line number Diff line change
@@ -91,8 +91,8 @@ void set(
Yaml& yml,
const test::A& a)
{
set(yml, test::A_VALUE_TAG, a.value);
set(yml, test::A_NAME_TAG, a.name);
set_in_tag(yml, test::A_VALUE_TAG, a.value);
set_in_tag(yml, test::A_NAME_TAG, a.name);
}

//! Serialize an object B in a yaml
@@ -101,8 +101,8 @@ void set(
Yaml& yml,
const test::B& b)
{
set(yml, test::B_ACTIVE_TAG, b.active);
set(yml, test::B_A_TAG, b.a);
set_in_tag(yml, test::B_ACTIVE_TAG, b.active);
set_in_tag(yml, test::B_A_TAG, b.a);
}

//! Deserialize an object A from a yaml
@@ -393,7 +393,7 @@ TEST(YamlWriterTest, set_specific_type)

// Create yml
Yaml yml;
set(yml, "b", b);
set_in_tag(yml, "b", b);

// Check the b tag exists, and some inside
ASSERT_TRUE(yml["b"]);
@@ -407,7 +407,7 @@ TEST(YamlWriterTest, set_specific_type)
test::B b2;
b.a.value = 3;
Yaml yml2;
set(yml2, "b", b2);
set_in_tag(yml2, "b", b2);

// Check that ymls are not equal
ASSERT_NE(
Original file line number Diff line number Diff line change
@@ -71,17 +71,17 @@ void set(
Yaml& yml,
const test::A& a)
{
set(yml, test::A_VALUE_TAG, a.value);
set(yml, test::A_NAME_TAG, a.name);
set_in_tag(yml, test::A_VALUE_TAG, a.value);
set_in_tag(yml, test::A_NAME_TAG, a.name);
}

template <>
void set(
Yaml& yml,
const test::B& b)
{
set(yml, test::B_ACTIVE_TAG, b.active);
set(yml, test::B_A_TAG, b.a);
set_in_tag(yml, test::B_ACTIVE_TAG, b.active);
set_in_tag(yml, test::B_A_TAG, b.a);
}

template <>