Skip to content
This repository was archived by the owner on Jul 16, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 89 additions & 4 deletions include/dart.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,24 @@ namespace dart {
>
explicit basic_object(Arg&& arg);

/**
* @brief
* Constructor allows an existing packet instance to be wrapped
* under the strongly typed API.
*
* @details
* If the passed packet is not an object, will throw an exception.
*/
template <class Arg,
std::enable_if_t<
std::is_same<
std::decay_t<Arg>,
Object
>::value
>* EnableIf = nullptr
>
explicit basic_object(Arg&& arg);

/**
* @brief
* Function is responsible for forwarding any constructors
Expand Down Expand Up @@ -258,6 +276,11 @@ namespace dart {
Arg,
Object
>::value
&&
!std::is_same<
std::decay_t<Arg>,
Object
>::value
>* EnableIf = nullptr
>
basic_object(Arg&& arg);
Expand Down Expand Up @@ -4781,6 +4804,16 @@ namespace dart {
>
explicit basic_null(basic_null<N> const&) {}

/**
* @brief
* Constructor allows an existing packet instance to be wrapped
* under the strongly typed API.
*
* @details
* If the passed packet is not a null, will throw an exception.
*/
explicit basic_null(Null const& null);

/**
* @brief
* Converting constructor to allow interoperability between underlying
Expand Down Expand Up @@ -5434,13 +5467,21 @@ namespace dart {
operator view() const& noexcept;
operator view() && = delete;

/**
* @brief
* Conversion operator to finalized type
*/
explicit operator basic_buffer<RefCount>() const;

/**
* @brief
* Generic conversion operator.
*/
template <class T, class EnableIf =
std::enable_if_t<
!meta::is_higher_specialization_of<T, basic_packet>::value
!detail::is_dart_type<T>::value
&&
!detail::is_wrapper_type<T>::value
&&
convert::is_castable<basic_heap, T>::value
>
Expand All @@ -5453,7 +5494,9 @@ namespace dart {
*/
template <class T, class EnableIf =
std::enable_if_t<
!meta::is_higher_specialization_of<T, basic_packet>::value
!detail::is_dart_type<T>::value
&&
!detail::is_wrapper_type<T>::value
&&
convert::is_castable<basic_heap, T>::value
>
Expand Down Expand Up @@ -8270,13 +8313,21 @@ namespace dart {
operator view() const& noexcept;
operator view() && = delete;

/**
* @brief
* Explicit conversion to non-finalized type
*/
explicit operator basic_heap<RefCount>() const;

/**
* @brief
* Generic conversion operator.
*/
template <class T, class EnableIf =
std::enable_if_t<
!meta::is_higher_specialization_of<T, basic_packet>::value
!detail::is_dart_type<T>::value
&&
!detail::is_wrapper_type<T>::value
&&
convert::is_castable<basic_buffer, T>::value
>
Expand All @@ -8289,7 +8340,9 @@ namespace dart {
*/
template <class T, class EnableIf =
std::enable_if_t<
!meta::is_higher_specialization_of<T, basic_packet>::value
!detail::is_dart_type<T>::value
&&
!detail::is_wrapper_type<T>::value
&&
convert::is_castable<basic_buffer, T>::value
>
Expand Down Expand Up @@ -10613,12 +10666,40 @@ namespace dart {
operator view() const& noexcept;
operator view() && = delete;

/**
* @brief
* Explicit conversion to non-finalized API.
*/
explicit operator basic_heap<RefCount>() const&;

/**
* @brief
* Explicit conversion to non-finalized API.
*/
explicit operator basic_heap<RefCount>() &&;

/**
* @brief
* Explicit conversion to finalized API.
*/
explicit operator basic_buffer<RefCount>() const&;

/**
* @brief
* Explicit conversion to non-finalized API.
*/
explicit operator basic_buffer<RefCount>() &&;

/**
* @brief
* Generic conversion operator.
*/
template <class T, class EnableIf =
std::enable_if_t<
!detail::is_dart_type<T>::value
&&
!detail::is_wrapper_type<T>::value
&&
convert::is_castable<basic_packet, T>::value
>
>
Expand All @@ -10630,6 +10711,10 @@ namespace dart {
*/
template <class T, class EnableIf =
std::enable_if_t<
!detail::is_dart_type<T>::value
&&
!detail::is_wrapper_type<T>::value
&&
convert::is_castable<basic_packet, T>::value
>
>
Expand Down
5 changes: 5 additions & 0 deletions include/dart/api.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@

namespace dart {

template <class Null>
basic_null<Null>::basic_null(Null const& null) {
if (!null.is_null()) throw type_error("dart::packet::null can only be constructed as a null");
}

template <class Object>
template <class Key, class Value, class Comp, class Alloc, class EnableIf>
basic_object<Object>& basic_object<Object>::operator =(std::map<Key, Value, Comp, Alloc> const& map) & {
Expand Down
5 changes: 5 additions & 0 deletions include/dart/buffer/api.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ namespace dart {
return tmp;
}

template <template <class> class RefCount>
basic_buffer<RefCount>::operator basic_heap<RefCount>() const {
return convert::cast<basic_heap<RefCount>>(*this);
}

template <template <class> class RefCount>
template <class T, class EnableIf>
basic_buffer<RefCount>::operator T() const& {
Expand Down
5 changes: 5 additions & 0 deletions include/dart/heap/api.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ namespace dart {
return view {detail::view_tag {}, data};
}

template <template <class> class RefCount>
basic_heap<RefCount>::operator basic_buffer<RefCount>() const {
return convert::cast<basic_buffer<RefCount>>(*this);
}

template <template <class> class RefCount>
template <class T, class EnableIf>
basic_heap<RefCount>::operator T() const& {
Expand Down
18 changes: 18 additions & 0 deletions include/dart/object.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ namespace dart {
ensure_object("dart::packet::object can only be constructed as an object");
}

template <class Object>
template <class Arg,
std::enable_if_t<
std::is_same<
std::decay_t<Arg>,
Object
>::value
>* EnableIf
>
basic_object<Object>::basic_object(Arg&& arg) : val(std::forward<Arg>(arg)) {
ensure_object("dart::packet::object can only be constructed as an object");
}

template <class Object>
template <class Arg,
std::enable_if_t<
Expand All @@ -43,6 +56,11 @@ namespace dart {
Arg,
Object
>::value
&&
!std::is_same<
std::decay_t<Arg>,
Object
>::value
>* EnableIf
>
basic_object<Object>::basic_object(Arg&& arg) : val(std::forward<Arg>(arg)) {
Expand Down
20 changes: 20 additions & 0 deletions include/dart/packet/api.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@ namespace dart {
}, impl);
}

template <template <class> class RefCount>
basic_packet<RefCount>::operator basic_heap<RefCount>() const& {
return convert::cast<basic_heap<RefCount>>(*this);
}

template <template <class> class RefCount>
basic_packet<RefCount>::operator basic_heap<RefCount>() && {
return convert::cast<basic_heap<RefCount>>(std::move(*this));
}

template <template <class> class RefCount>
basic_packet<RefCount>::operator basic_buffer<RefCount>() const& {
return convert::cast<basic_buffer<RefCount>>(*this);
}

template <template <class> class RefCount>
basic_packet<RefCount>::operator basic_buffer<RefCount>() && {
return convert::cast<basic_buffer<RefCount>>(std::move(*this));
}

template <template <class> class RefCount>
template <class T, class EnableIf>
basic_packet<RefCount>::operator T() const& {
Expand Down