Skip to content

Commit

Permalink
clean up ownership semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
molpopgen committed Jul 7, 2021
1 parent 29ab1f2 commit cf96361
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
25 changes: 21 additions & 4 deletions fwdpp/ts/types/tree_sequence.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ namespace fwdpp
template <typename SignedInteger> class tree_iterator
{
private:
const tree_sequence<SignedInteger>* treeseq_;
std::reference_wrapper<const tree_sequence<SignedInteger>> treeseq_;
marginal_tree<SignedInteger> tree_;

public:
tree_iterator(const tree_sequence<SignedInteger>* ts,
const std::vector<SignedInteger>& samples,
tree_iterator(const tree_sequence<SignedInteger>& ts,
std::uint32_t flags)
: treeseq_{ts}, tree_{ts->nodes.size(), samples,
: treeseq_{ts}, tree_{ts.num_nodes(), ts.samples(),
static_cast<bool>(flags
& tree_flags::TRACK_SAMPLES)}
{
Expand Down Expand Up @@ -139,6 +138,24 @@ namespace fwdpp
num_trees_{init_num_trees()}
{
}

std::size_t
num_nodes() const
{
return tables_->nodes.size();
}

const std::vector<SignedInteger>&
samples() const
{
return samples_;
}

tree_iterator<SignedInteger>
trees(std::uint32_t flags)
{
return tree_iterator<SignedInteger>{*this, flags};
}
};

#if __cplusplus < 201703L
Expand Down
2 changes: 2 additions & 0 deletions testsuite/tree_sequences/test_tree_sequence.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ using tree_sequence64 = fwdpp::ts::types::tree_sequence<std::int64_t>;
//explicit instantiations
template class fwdpp::ts::types::tree_sequence<std::int32_t>;
template class fwdpp::ts::types::tree_sequence<std::int64_t>;
template class fwdpp::ts::types::tree_iterator<std::int32_t>;
template class fwdpp::ts::types::tree_iterator<std::int64_t>;

0 comments on commit cf96361

Please sign in to comment.