Skip to content

Commit

Permalink
[FIX] sam_file_header ref_ids ownership
Browse files Browse the repository at this point in the history
  • Loading branch information
eseiler committed Nov 6, 2024
1 parent b6b60a6 commit bd90616
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions include/seqan3/io/sam_file/header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,10 @@ class sam_file_header
sam_file_header & operator=(sam_file_header &&) = default; //!< Defaulted.
~sam_file_header() = default; //!< Defaulted.

/*!\brief Construct from a range of reference ids which redirects the `ref_ids_ptr` member (non-owning).
* \param[in] ref_ids The range over reference ids to redirect the pointer at.
/*!\brief Construct from a range of reference ids which is moved into the `ref_ids_ptr` (owning).
* \param[in] ref_ids The range over reference ids.
*/
sam_file_header(ref_ids_type & ref_ids) : ref_ids_ptr{&ref_ids, ref_ids_deleter_noop}
{}

/*!\brief Construct from a rvalue range of reference ids which is moved into the `ref_ids_ptr` (owning).
* \param[in] ref_ids The range over reference ids to own.
*/
sam_file_header(ref_ids_type && ref_ids) :
ref_ids_ptr{new ref_ids_type{std::move(ref_ids)}, ref_ids_deleter_default}
sam_file_header(ref_ids_type ref_ids) : ref_ids_ptr{std::make_unique<ref_ids_type>(std::move(ref_ids))}
{}
//!\}

Expand All @@ -84,21 +77,14 @@ class sam_file_header

private:
//!\brief The type of the internal ref_ids pointer. Allows dynamically setting ownership management.
using ref_ids_ptr_t = std::unique_ptr<ref_ids_type, std::function<void(ref_ids_type *)>>;
//!\brief Stream deleter that does nothing (no ownership assumed).
static void ref_ids_deleter_noop(ref_ids_type *)
{}
//!\brief Stream deleter with default behaviour (ownership assumed).
static void ref_ids_deleter_default(ref_ids_type * ptr)
{
delete ptr;
}
using ref_ids_ptr_t = std::unique_ptr<ref_ids_type>;

//!\brief The key's type of ref_dict.
using key_type = std::conditional_t<std::ranges::contiguous_range<std::ranges::range_reference_t<ref_ids_type>>,
std::span<range_innermost_value_t<ref_ids_type> const>,
type_reduce_t<std::ranges::range_reference_t<ref_ids_type>>>;
//!\brief The pointer to reference ids information (non-owning if reference information is given).
ref_ids_ptr_t ref_ids_ptr{new ref_ids_type{}, ref_ids_deleter_default};
//!\brief The pointer to reference ids information (owning).
ref_ids_ptr_t ref_ids_ptr{std::make_unique<ref_ids_type>(ref_ids_type{})};

//!\brief Custom hash function since std::hash is not defined for all range types (e.g. std::span<char>).
struct key_hasher
Expand Down

0 comments on commit bd90616

Please sign in to comment.