Skip to content

Commit

Permalink
REfs 17138. API update fixes .. ongoing
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Barro <[email protected]>
  • Loading branch information
Miguel Barro committed Jun 20, 2023
1 parent 5b37876 commit b6ae13f
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 67 deletions.
12 changes: 6 additions & 6 deletions include/fastrtps/types/v1_3/DynamicData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class DynamicData
explicit DynamicData(
const DynamicData* pData);
DynamicData(
DynamicType_ptr pType);
const DynamicType& type);

~DynamicData();

Expand All @@ -64,7 +64,7 @@ class DynamicData
MemberId id);

void create_members(
DynamicType_ptr pType);
const DynamicType& type);

void create_members(
const DynamicData* pData);
Expand Down Expand Up @@ -1167,18 +1167,18 @@ class DynamicData
size_t current_alignment = 0);

RTPS_DllAPI static size_t getEmptyCdrSerializedSize(
const DynamicType* type,
const DynamicType& type,
size_t current_alignment = 0);

RTPS_DllAPI static size_t getKeyMaxCdrSerializedSize(
const DynamicType_ptr type,
const DynamicType& type,
size_t current_alignment = 0);

RTPS_DllAPI static size_t getMaxCdrSerializedSize(
const DynamicType_ptr type,
const DynamicType& type,
size_t current_alignment = 0);

RTPS_DllAPI DynamicType_ptr get_type() const;
RTPS_DllAPI const DynamicType* get_type() const;

void serializeKey(
eprosima::fastcdr::Cdr& cdr) const;
Expand Down
4 changes: 2 additions & 2 deletions include/fastrtps/types/v1_3/DynamicDataFactory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ class DynamicDataFactory
RTPS_DllAPI static ReturnCode_t delete_instance();

RTPS_DllAPI DynamicData* create_data(
DynamicTypeBuilder* pBuilder);
const DynamicTypeBuilder& builder);

RTPS_DllAPI DynamicData* create_data(
DynamicType_ptr pType);
const DynamicType& pType);

RTPS_DllAPI DynamicData* create_copy(
const DynamicData* pData);
Expand Down
2 changes: 1 addition & 1 deletion include/fastrtps/types/v1_3/DynamicType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class DynamicType final
use_the_create_method,
TypeDescriptor&& descriptor);

RTPS_DllAPI ~DynamicType();
~DynamicType();

using TypeDescriptor::get_descriptor;

Expand Down
68 changes: 33 additions & 35 deletions src/cpp/dynamic-types/v1_3/DynamicData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ bool map_compare(
}

DynamicData::DynamicData(
DynamicType_ptr pType)
: type_(pType)
const DynamicType& type)
: type_(DynamicTypeBuilderFactory::get_instance().create_copy(type))
{
create_members(type_);
create_members(*type_);
}

DynamicData::DynamicData(
Expand Down Expand Up @@ -97,9 +97,9 @@ DynamicData::~DynamicData()
clean();
}

DynamicType_ptr DynamicData::get_type() const
const DynamicType* DynamicData::get_type() const
{
return type_;
return DynamicTypeBuilderFactory::get_instance().create_copy(*type_);
}

void DynamicData::create_members(
Expand Down Expand Up @@ -137,24 +137,22 @@ void DynamicData::create_members(
}

void DynamicData::create_members(
DynamicType_ptr pType)
const DynamicType& type)
{
assert(pType);

if (pType->is_complex_kind())
if (type.is_complex_kind())
{
// Bitmasks and enums register their members but only manages one value.
if (pType->get_kind() == TypeKind::TK_BITMASK || pType->get_kind() == TypeKind::TK_ENUM)
if (type.get_kind() == TypeKind::TK_BITMASK || type.get_kind() == TypeKind::TK_ENUM)
{
add_value(pType->get_kind(), MEMBER_ID_INVALID);
add_value(type.get_kind(), MEMBER_ID_INVALID);
}
else
{
for (auto pm : pType->get_all_members())
for (auto pm : type.get_all_members())
{
assert(pm);

DynamicData* data = DynamicDataFactory::get_instance()->create_data(pm->get_type());
DynamicData* data = DynamicDataFactory::get_instance()->create_data(*pm->get_type());
if (pm->get_kind() != TypeKind::TK_BITSET &&
pm->get_kind() != TypeKind::TK_STRUCTURE &&
pm->get_kind() != TypeKind::TK_UNION &&
Expand All @@ -175,7 +173,7 @@ void DynamicData::create_members(
#endif // ifdef DYNAMIC_TYPES_CHECKING

// Set the default value for unions.
if (pType->get_kind() == TypeKind::TK_UNION &&
if (type.get_kind() == TypeKind::TK_UNION &&
pm->is_default_union_value())
{
set_union_id(pm->get_id());
Expand All @@ -184,23 +182,23 @@ void DynamicData::create_members(
}

// If there isn't a default value... set the first element of the union
if (pType->get_kind() == TypeKind::TK_UNION &&
if (type.get_kind() == TypeKind::TK_UNION &&
get_union_id() == MEMBER_ID_INVALID &&
pType->get_member_count())
type.get_member_count())
{
set_union_id(get_member_id_at_index(0));
}
}
else
{
// Resolve alias type, avoid reference counting
const DynamicType* type = pType.get();
while ( type->get_kind() == TypeKind::TK_ALIAS )
DynamicType_ptr alias_type{DynamicTypeBuilderFactory::get_instance().create_copy(type)};
while ( alias_type->get_kind() == TypeKind::TK_ALIAS )
{
type = type->get_base_type().get();
alias_type = alias_type->get_base_type();
}

add_value(type->get_kind(), MEMBER_ID_INVALID);
add_value(alias_type->get_kind(), MEMBER_ID_INVALID);
}
}

Expand All @@ -221,7 +219,7 @@ bool DynamicData::equals(
{
return true;
}
else if (type_ == other->type_ || type_->equals(*other->type_.get()))
else if (type_ == other->type_ || type_->equals(*other->type_))
{
// Optimization for unions, only check the selected element.
if (get_kind() == TypeKind::TK_UNION)
Expand Down Expand Up @@ -4521,7 +4519,8 @@ ReturnCode_t DynamicData::insert_array_data(
DynamicDataFactory::get_instance()->delete_data((DynamicData*)it->second);
values_.erase(it);
}
DynamicData* value = DynamicDataFactory::get_instance()->create_data(type_->get_element_type());
DynamicType_ptr element_type {type_->get_element_type()};
DynamicData* value = DynamicDataFactory::get_instance()->create_data(*element_type);
values_.insert(std::make_pair(indexId, value));
return ReturnCode_t::RETCODE_OK;
}
Expand Down Expand Up @@ -5000,17 +4999,17 @@ ReturnCode_t DynamicData::insert_sequence_data(
{
if (type_->get_bounds() == BOUND_UNLIMITED || get_item_count() < type_->get_bounds())
{
DynamicType_ptr element_type {type_->get_element_type()};
#ifdef DYNAMIC_TYPES_CHECKING
DynamicData* new_element = DynamicDataFactory::get_instance()->create_data(type_->get_element_type());
DynamicData* new_element = DynamicDataFactory::get_instance()->create_data(*element_type);
outId = complex_values_.size();
complex_values_.insert(std::make_pair(outId, new_element));
return ReturnCode_t::RETCODE_OK;
#else
DynamicData* new_element = DynamicDataFactory::get_instance()->create_data(type_->get_element_type());
DynamicData* new_element = DynamicDataFactory::get_instance()->create_data(*element_type);
outId = values_.size();
values_.insert(std::make_pair(outId, new_element));
return ReturnCode_t::RETCODE_OK;
#endif // ifdef DYNAMIC_TYPES_CHECKING
return ReturnCode_t::RETCODE_OK;
}
else
{
Expand Down Expand Up @@ -5111,7 +5110,8 @@ ReturnCode_t DynamicData::insert_map_data(
keyCopy->key_element_ = true;
values_.insert(std::make_pair(outKeyId, keyCopy));

DynamicData* new_element = DynamicDataFactory::get_instance()->create_data(type_->get_element_type());
DynamicType_ptr element_type {type_->get_element_type()};
DynamicData* new_element = DynamicDataFactory::get_instance()->create_data(*element_type);
outValueId = outKeyId + 1u;
values_.insert(std::make_pair(outValueId, new_element));
return ReturnCode_t::RETCODE_OK;
Expand Down Expand Up @@ -5581,19 +5581,17 @@ size_t DynamicData::getCdrSerializedSize(
}

size_t DynamicData::getKeyMaxCdrSerializedSize(
const DynamicType_ptr type,
const DynamicType& type,
size_t current_alignment /*= 0*/)
{
assert(type);
return type->getKeyMaxCdrSerializedSize(current_alignment);
return type.getKeyMaxCdrSerializedSize(current_alignment);
}

size_t DynamicData::getMaxCdrSerializedSize(
const DynamicType_ptr type,
const DynamicType& type,
size_t current_alignment /*= 0*/)
{
assert(type);
return type->getMaxCdrSerializedSize(current_alignment);
return type.getMaxCdrSerializedSize(current_alignment);
}

void DynamicData::serialize(
Expand All @@ -5611,10 +5609,10 @@ void DynamicData::serializeKey(
}

size_t DynamicData::getEmptyCdrSerializedSize(
const DynamicType* type,
const DynamicType& type,
size_t current_alignment /*= 0*/)
{
return type->getEmptyCdrSerializedSize(current_alignment);
return type.getEmptyCdrSerializedSize(current_alignment);
}

bool DynamicData::has_children() const
Expand Down
46 changes: 24 additions & 22 deletions src/cpp/dynamic-types/v1_3/DynamicDataFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ DynamicData* DynamicDataFactory::create_copy(
}

DynamicData* DynamicDataFactory::create_data(
DynamicTypeBuilder* pBuilder)
const DynamicTypeBuilder& builder)
{
if (pBuilder != nullptr && pBuilder->is_consistent())
if (builder.is_consistent())
{
DynamicType_ptr pType{pBuilder->build()};
return create_data(pType);
DynamicType_ptr type{builder.build()};
return create_data(*type);
}
else
{
Expand All @@ -99,24 +99,25 @@ DynamicData* DynamicDataFactory::create_data(
}

DynamicData* DynamicDataFactory::create_data(
DynamicType_ptr pType)
const DynamicType& type)
{
if (pType != nullptr && pType->is_consistent())
if (type.is_consistent())
{
try
{
DynamicData* newData = nullptr;
// ALIAS types create a DynamicData based on the base type and renames it with the name of the ALIAS.
if (pType->get_base_type())
DynamicType_ptr base_type{type.get_base_type()};
if (base_type)
{
if (pType->get_kind() == TypeKind::TK_ALIAS)
if (type.get_kind() == TypeKind::TK_ALIAS)
{
newData = create_data(pType->get_base_type());
// newData->set_type_name(pType->get_name());
newData = create_data(*base_type);
// newData->set_type_name(type.get_name());
}
else if (pType->get_kind() == TypeKind::TK_STRUCTURE || pType->get_kind() == TypeKind::TK_BITSET)
else if (type.get_kind() == TypeKind::TK_STRUCTURE || type.get_kind() == TypeKind::TK_BITSET)
{
newData = new DynamicData(pType);
newData = new DynamicData(type);
#ifndef DISABLE_DYNAMIC_MEMORY_CHECK
{
std::unique_lock<std::recursive_mutex> scoped(mutex_);
Expand All @@ -127,7 +128,7 @@ DynamicData* DynamicDataFactory::create_data(
}
else
{
newData = new DynamicData(pType);
newData = new DynamicData(type);
#ifndef DISABLE_DYNAMIC_MEMORY_CHECK
{
std::unique_lock<std::recursive_mutex> scoped(mutex_);
Expand All @@ -136,19 +137,20 @@ DynamicData* DynamicDataFactory::create_data(
#endif // ifndef DISABLE_DYNAMIC_MEMORY_CHECK

// Enums must have a default value
if (pType->get_kind() == TypeKind::TK_ENUM)
if (type.get_kind() == TypeKind::TK_ENUM)
{
MemberId id = pType->get_member_id_at_index(0);
MemberId id = type.get_member_id_at_index(0);
// enums cannot be instantiated without members
assert(MEMBER_ID_INVALID != id);
// initialize the enum
newData->set_uint32_value(*id);
}

// Arrays must have created every members for serialization.
if (pType->get_kind() == TypeKind::TK_ARRAY)
if (type.get_kind() == TypeKind::TK_ARRAY)
{
DynamicData* defaultArrayData = new DynamicData(pType->get_element_type());
DynamicType_ptr element_type{type.get_element_type()};
DynamicData* defaultArrayData = new DynamicData(*element_type);
assert(nullptr != defaultArrayData);
#ifndef DISABLE_DYNAMIC_MEMORY_CHECK
{
Expand Down Expand Up @@ -178,13 +180,13 @@ ReturnCode_t DynamicDataFactory::create_members(
DynamicData* pData,
DynamicType_ptr pType)
{
if (pType != nullptr && pData != nullptr)
if (pType && pData != nullptr)
{
pData->create_members(pType);
if ((pType->get_kind() == TypeKind::TK_STRUCTURE || pType->get_kind() == TypeKind::TK_BITSET) &&
pType->get_base_type() != nullptr)
pData->create_members(*pType);
DynamicType_ptr base_type {pType->get_base_type()};
if ((pType->get_kind() == TypeKind::TK_STRUCTURE || pType->get_kind() == TypeKind::TK_BITSET) && base_type)
{
create_members(pData, pType->get_base_type());
create_members(pData, base_type);
}
return ReturnCode_t::RETCODE_OK;
}
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/fastdds/topic/DDSSQLFilter/DDSFilterExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,5 @@ void DDSFilterExpression::set_type(
const DynamicType_ptr& type)
{
dyn_type_ = type;
dyn_data_.reset(DynamicDataFactory::get_instance()->create_data(type));
dyn_data_.reset(DynamicDataFactory::get_instance()->create_data(*type));
}

0 comments on commit b6ae13f

Please sign in to comment.