Skip to content

Commit

Permalink
Refs 17138. API update fixes...part 1
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 16, 2023
1 parent de51522 commit 16c1501
Show file tree
Hide file tree
Showing 14 changed files with 159 additions and 129 deletions.
16 changes: 8 additions & 8 deletions include/fastrtps/types/TypesBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ class DynamicType;
class DynamicTypeBuilder;

template<class T>
std::function<void(T*)> dynamic_object_deleter(T*);
std::function<void(const T*)> dynamic_object_deleter(const T*);

using namespace xtypes_names;

Expand All @@ -940,10 +940,10 @@ constexpr uint32_t LENGTH_UNLIMITED = std::numeric_limits<uint32_t>::max();

namespace std {

template<> class weak_ptr<v1_3::DynamicTypeBuilder>;
template<> class shared_ptr<v1_3::DynamicTypeBuilder>;
template<> class weak_ptr<const v1_3::DynamicType>;
template<> class shared_ptr<const v1_3::DynamicType>;
template<> class weak_ptr<eprosima::fastrtps::types::v1_3::DynamicTypeBuilder>;
template<> class shared_ptr<eprosima::fastrtps::types::v1_3::DynamicTypeBuilder>;
template<> class weak_ptr<const eprosima::fastrtps::types::v1_3::DynamicType>;
template<> class shared_ptr<const eprosima::fastrtps::types::v1_3::DynamicType>;

} // namespace std

Expand All @@ -952,9 +952,9 @@ namespace fastrtps {
namespace types {
namespace v1_3 {

class DynamicType_ptr = std::shared_ptr<const DynamicType>;
class DynamicTypeBuilder_ptr = std::shared_ptr<DynamicTypeBuilder>;
class DynamicTypeBuilder_cptr = std::shared_ptr<const DynamicTypeBuilder>;
using DynamicType_ptr = std::shared_ptr<DynamicType>;
using DynamicTypeBuilder_ptr = std::shared_ptr<DynamicTypeBuilder>;
using DynamicTypeBuilder_cptr = std::shared_ptr<const DynamicTypeBuilder>;

} // namespace v1_3
} // namespace types
Expand Down
6 changes: 3 additions & 3 deletions include/fastrtps/types/v1_3/AnnotationDescriptor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define TYPES_1_3_ANNOTATION_DESCRIPTOR_H

#include <fastrtps/types/TypesBase.h>
#include <fastrtps/types/v1_3/DynamicTypePtr.hpp>

#include <functional>

Expand All @@ -24,8 +25,6 @@ namespace fastrtps {
namespace types {
namespace v1_3 {

class MemberDescriptor;
class DynamicType;
class DynamicTypeBuilderFactory;

class AnnotationDescriptor final
Expand Down Expand Up @@ -79,7 +78,8 @@ class AnnotationDescriptor final
void set_type(
const D& type)
{
type_.swap(DynamicType_ptr{type});
DynamicType_ptr tmp{type};
type_.swap(tmp);
}

void set_type(
Expand Down
1 change: 1 addition & 0 deletions include/fastrtps/types/v1_3/DynamicData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define TYPES_1_3_DYNAMIC_DATA_H

#include <fastrtps/types/TypesBase.h>
#include <fastrtps/types/v1_3/DynamicType.hpp>
#include <fastrtps/types/v1_3/DynamicDataPtr.hpp>
#include <fastrtps/types/v1_3/MemberId.hpp>

Expand Down
1 change: 1 addition & 0 deletions include/fastrtps/types/v1_3/DynamicPubSubType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <fastrtps/types/TypesBase.h>
#include <fastdds/dds/topic/TopicDataType.hpp>
#include <fastrtps/types/v1_3/DynamicTypePtr.hpp>
#include <fastrtps/types/v1_3/DynamicDataPtr.hpp>
#include <fastrtps/utils/md5.h>

Expand Down
8 changes: 5 additions & 3 deletions include/fastrtps/types/v1_3/DynamicType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef TYPES_1_3_DYNAMIC_TYPE_H
#define TYPES_1_3_DYNAMIC_TYPE_H
#ifndef TYPES_1_3_DYNAMIC_TYPE_HPP
#define TYPES_1_3_DYNAMIC_TYPE_HPP

#include <fastrtps/types/v1_3/DynamicTypePtr.hpp>
#include <fastrtps/types/v1_3/TypeDescriptor.hpp>
Expand Down Expand Up @@ -47,6 +47,8 @@ class DynamicType final
explicit use_the_create_method() = default;
};

friend std::function<void(const DynamicType*)> dynamic_object_deleter(const DynamicType*);

public:

DynamicType(
Expand Down Expand Up @@ -138,4 +140,4 @@ class DynamicType final
} // namespace fastrtps
} // namespace eprosima

#endif // TYPES_1_3_DYNAMIC_TYPE_H
#endif // TYPES_1_3_DYNAMIC_TYPE_HPP
15 changes: 6 additions & 9 deletions include/fastrtps/types/v1_3/DynamicTypeBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef TYPES_1_3_DYNAMIC_TYPE_BUILDER_H
#define TYPES_1_3_DYNAMIC_TYPE_BUILDER_H
#ifndef TYPES_1_3_DYNAMIC_TYPE_BUILDER_HPP
#define TYPES_1_3_DYNAMIC_TYPE_BUILDER_HPP

#include <fastdds/dds/log/Log.hpp>
#include <fastrtps/types/v1_3/DynamicTypeBuilderPtr.hpp>
#include <fastrtps/types/v1_3/TypeDescriptor.hpp>
#include <fastrtps/utils/custom_allocators.hpp>

Expand Down Expand Up @@ -50,6 +51,8 @@ class DynamicTypeBuilder final
explicit use_the_create_method() = default;
};

friend std::function<void(const DynamicTypeBuilder*)> dynamic_object_deleter(const DynamicTypeBuilder*);

MemberId current_member_id_{0};

mutable DynamicType_ptr instance_; //!< Instance of the associated type object
Expand Down Expand Up @@ -182,15 +185,9 @@ class DynamicTypeBuilder final
using TypeDescriptor::set_base_type;
};

template<>
void dynamic_object_deleter(const DynamicTypeBuilder* )
{

}

} // namespace v1_3
} // namespace types
} // namespace fastrtps
} // namespace eprosima

#endif // TYPES_1_3_DYNAMIC_TYPE_BUILDER_H
#endif // TYPES_1_3_DYNAMIC_TYPE_BUILDER_HPP
81 changes: 48 additions & 33 deletions include/fastrtps/types/v1_3/DynamicTypeBuilderPtr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace types {
namespace v1_3 {

template<>
std::function<void(DynamicTypeBuilder*)> dynamic_object_deleter(const DynamicTypeBuilder*);
std::function<void(const DynamicTypeBuilder*)> dynamic_object_deleter(const DynamicTypeBuilder*);

} // namespace v1_3
} // namespace types
Expand All @@ -35,17 +35,17 @@ namespace std

template<>
class shared_ptr<const eprosima::fastrtps::types::v1_3::DynamicTypeBuilder>
: public shared_ptr<void>
: public shared_ptr<const void>
{
public:

using element_type = const eprosima::fastrtps::types::v1_3::DynamicTypeBuilder;
using base = shared_ptr<void>;
using base = shared_ptr<const void>;

constexpr shared_ptr() = default;

explicit shared_ptr(const eprosima::fastrtps::types::v1_3::DynamicTypeBuilder* pA)
: base(const_cast<eprosima::fastrtps::types::v1_3::DynamicTypeBuilder*>(pA), dynamic_object_deleter<element_type>) {}
explicit shared_ptr(const element_type* pA)
: base(pA, dynamic_object_deleter(pA)) {}

shared_ptr(const shared_ptr& r) noexcept
: base(r) {}
Expand All @@ -55,9 +55,9 @@ class shared_ptr<const eprosima::fastrtps::types::v1_3::DynamicTypeBuilder>

template< class Y >
shared_ptr(const shared_ptr<Y>& r, element_type* ptr) noexcept
: base(r, const_cast<eprosima::fastrtps::types::v1_3::DynamicTypeBuilder*>(ptr)) {}
: base(r, ptr) {}

template <class T, enable_if_t<is_convertible<element_type, T>::value, int> = 0>
template <class T, enable_if_t<is_convertible<T*, element_type*>::value, int> = 0>
explicit shared_ptr(const weak_ptr<T>& r)
: base(r) {}

Expand All @@ -76,23 +76,22 @@ class shared_ptr<const eprosima::fastrtps::types::v1_3::DynamicTypeBuilder>
base::reset();
}

void reset(const eprosima::fastrtps::types::v1_3::DynamicTypeBuilder* pA)
void reset(element_type* pA)
{
base::reset(const_cast<eprosima::fastrtps::types::v1_3::DynamicTypeBuilder*>(pA),
dynamic_object_deleter<element_type>);
base::reset(pA, dynamic_object_deleter(pA));
}

element_type* get() const noexcept
{
return static_cast<element_type*>(base::get());
}

const eprosima::fastrtps::types::v1_3::DynamicTypeBuilder& operator*() const noexcept
element_type& operator*() const noexcept
{
return *get();
}

const eprosima::fastrtps::types::v1_3::DynamicTypeBuilder* operator->() const noexcept
element_type* operator->() const noexcept
{
return get();
}
Expand All @@ -112,17 +111,17 @@ class shared_ptr<eprosima::fastrtps::types::v1_3::DynamicTypeBuilder>
shared_ptr(const shared_ptr& r) noexcept
: base(r) {}

shared_ptr(shared_ptr<eprosima::fastrtps::types::v1_3::DynamicTypeBuilder>&& r) noexcept
shared_ptr(shared_ptr&& r) noexcept
: base(move(r)) {}

explicit shared_ptr(eprosima::fastrtps::types::v1_3::DynamicTypeBuilder* pA)
explicit shared_ptr(element_type* pA)
: base(pA) {}

template< class Y >
shared_ptr(const shared_ptr<Y>& r, element_type* ptr) noexcept
: base(r, ptr) {}

template <class T, enable_if_t<is_convertible<element_type, T>::value, int> = 0>
template <class T, enable_if_t<is_convertible<T*, element_type*>::value, int> = 0>
explicit shared_ptr(const weak_ptr<T>& r)
: base(r) {}

Expand All @@ -136,30 +135,30 @@ class shared_ptr<eprosima::fastrtps::types::v1_3::DynamicTypeBuilder>
return static_cast<shared_ptr&>(base::operator=(move(r)));
}

eprosima::fastrtps::types::v1_3::DynamicTypeBuilder* get() const noexcept
element_type* get() const noexcept
{
return const_cast<eprosima::fastrtps::types::v1_3::DynamicTypeBuilder*>(base::get());
return const_cast<element_type*>(base::get());
}

eprosima::fastrtps::types::v1_3::DynamicTypeBuilder& operator*() const noexcept
element_type& operator*() const noexcept
{
return const_cast<eprosima::fastrtps::types::v1_3::DynamicTypeBuilder&>(*get());
return const_cast<element_type&>(*get());
}

eprosima::fastrtps::types::v1_3::DynamicTypeBuilder* operator->() const noexcept
element_type* operator->() const noexcept
{
return get();
}
};

template<>
class weak_ptr<const eprosima::fastrtps::types::v1_3::DynamicTypeBuilder>
: public weak_ptr<void>
: public weak_ptr<const void>
{
public:

using element_type = const eprosima::fastrtps::types::v1_3::DynamicTypeBuilder;
using base = weak_ptr<void>;
using base = weak_ptr<const void>;

constexpr weak_ptr() noexcept = default;

Expand All @@ -169,22 +168,24 @@ class weak_ptr<const eprosima::fastrtps::types::v1_3::DynamicTypeBuilder>
weak_ptr(weak_ptr&& r) noexcept
: base(move(r)) {}

weak_ptr(const shared_ptr<const eprosima::fastrtps::types::v1_3::DynamicTypeBuilder>& r) noexcept
: base(const_pointer_cast<eprosima::fastrtps::types::v1_3::DynamicTypeBuilder>(r)) {}
weak_ptr(const shared_ptr<element_type>& r) noexcept
: base(r) {}

weak_ptr& operator=( const weak_ptr& r) noexcept
weak_ptr& operator=(const weak_ptr& r) noexcept
{
return static_cast<weak_ptr&>(base::operator=(r));
base::operator=(r);
return *this;
}

weak_ptr& operator=( weak_ptr&& r) noexcept
weak_ptr& operator=(weak_ptr&& r) noexcept
{
return static_cast<weak_ptr&>(base::operator=(move(r)));
base::operator=(move(r));
return *this;
}

shared_ptr<const eprosima::fastrtps::types::v1_3::DynamicTypeBuilder> lock() const noexcept
shared_ptr<element_type> lock() const noexcept
{
return static_pointer_cast<const eprosima::fastrtps::types::v1_3::DynamicTypeBuilder>(base::lock());
return static_pointer_cast<element_type>(base::lock());
}
};

Expand All @@ -197,18 +198,32 @@ class weak_ptr<eprosima::fastrtps::types::v1_3::DynamicTypeBuilder>
using element_type = eprosima::fastrtps::types::v1_3::DynamicTypeBuilder;
using base = weak_ptr<const eprosima::fastrtps::types::v1_3::DynamicTypeBuilder>;

constexpr weak_ptr() noexcept = default;

weak_ptr(const weak_ptr& r) noexcept
: base(r) {}

weak_ptr(weak_ptr&& r) noexcept
: base(move(r)) {}

weak_ptr(const shared_ptr<eprosima::fastrtps::types::v1_3::DynamicTypeBuilder>& r) noexcept
weak_ptr(const shared_ptr<element_type>& r) noexcept
: base(r) {}

shared_ptr<eprosima::fastrtps::types::v1_3::DynamicTypeBuilder> lock() const noexcept
weak_ptr& operator=(const weak_ptr& r) noexcept
{
base::operator=(r);
return *this;
}

weak_ptr& operator=(weak_ptr&& r) noexcept
{
base::operator=(move(r));
return *this;
}

shared_ptr<element_type> lock() const noexcept
{
return const_pointer_cast<eprosima::fastrtps::types::v1_3::DynamicTypeBuilder>(base::lock());
return const_pointer_cast<element_type>(base::lock());
}
};

Expand Down
Loading

0 comments on commit 16c1501

Please sign in to comment.