Skip to content

Commit

Permalink
Improve any_data
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-PLACET committed Jul 9, 2024
1 parent 00f30ff commit 5cf1f22
Show file tree
Hide file tree
Showing 2 changed files with 532 additions and 84 deletions.
52 changes: 48 additions & 4 deletions include/sparrow/any_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ namespace sparrow
// The type U must be the same as the type of the data. Otherwise std::bad_any_cast exception is
// thrown.
template <class U>
U& get_data();
U get_data();

template <class U>
const U& get_data() const;
const U get_data() const;

[[nodiscard]] bool owns_data() const noexcept;

std::type_index type_id() const;

Expand Down Expand Up @@ -115,18 +117,24 @@ namespace sparrow

template <typename T>
template <class U>
U& any_data<T>::get_data()
U any_data<T>::get_data()
{
return std::any_cast<U>(m_owner);
}

template <typename T>
template <class U>
const U& any_data<T>::get_data() const
const U any_data<T>::get_data() const
{
return std::any_cast<U>(m_owner);
}

template <typename T>
bool any_data<T>::owns_data() const noexcept
{
return m_owner.has_value();
}

template <typename T>
std::type_index any_data<T>::type_id() const
{
Expand Down Expand Up @@ -176,8 +184,18 @@ namespace sparrow

[[nodiscard]] std::vector<T*>& get_pointers_vec() noexcept;

[[nodiscard]] const std::vector<T*>& get_pointers_vec() const noexcept;

[[nodiscard]] T** get() noexcept;

[[nodiscard]] const T** get() const noexcept;

template <class U>
[[nodiscard]] U get_data();

template <class U>
[[nodiscard]] const U get_data() const;

[[nodiscard]] bool owns_data() const noexcept;

[[nodiscard]] size_t size() const noexcept;
Expand Down Expand Up @@ -289,12 +307,38 @@ namespace sparrow
return m_pointers_vec;
}

template <typename T>
const std::vector<T*>& any_data_container<T>::get_pointers_vec() const noexcept
{
return m_pointers_vec;
}

template <typename T>
T** any_data_container<T>::get() noexcept
{
return m_raw_pointers;
}

template <typename T>
const T** any_data_container<T>::get() const noexcept
{
return m_raw_pointers;
}

template <typename T>
template <typename U>
U any_data_container<T>::get_data()
{
return std::any_cast<U>(m_owner);
}

template <typename T>
template <typename U>
const U any_data_container<T>::get_data() const
{
return std::any_cast<U>(m_owner);
}

template <typename T>
bool any_data_container<T>::owns_data() const noexcept
{
Expand Down
Loading

0 comments on commit 5cf1f22

Please sign in to comment.