Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
Expunge the copy-then-move idiom
Browse files Browse the repository at this point in the history
closes #256 and make @droazen happy.
  • Loading branch information
Mauricio Carneiro committed Sep 24, 2014
1 parent 5bb653a commit 91b6e14
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions gamgee/indexed_sam_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ class IndexedSamReader {
* @param filename the name of the bam/cram file
* @param interval_list Samtools style intervals to look for records
*/
IndexedSamReader(const std::string& filename, std::vector<std::string> interval_list) :
IndexedSamReader(const std::string& filename, const std::vector<std::string>& interval_list) :
m_sam_file_ptr {utils::make_shared_hts_file(sam_open(filename.c_str(), "r"))}, // TODO: Not checking for errors.
m_sam_index_ptr {utils::make_shared_hts_index(sam_index_load(m_sam_file_ptr.get(), filename.c_str()))}, // TODO: Not checking for errors.
m_sam_header_ptr { utils::make_shared_sam_header(sam_hdr_read(m_sam_file_ptr.get())) }, // TODO: Not checking for errors.
m_interval_list {std::move(interval_list)} {
m_interval_list {interval_list} {
}

/**
Expand Down
4 changes: 2 additions & 2 deletions gamgee/indexed_variant_iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ IndexedVariantIterator::IndexedVariantIterator() :
IndexedVariantIterator::IndexedVariantIterator(const std::shared_ptr<htsFile>& file_ptr,
const std::shared_ptr<hts_idx_t>& index_ptr,
const std::shared_ptr<bcf_hdr_t>& header_ptr,
const std::vector<std::string> interval_list) :
const std::vector<std::string>& interval_list) :
VariantIterator { file_ptr, header_ptr },
m_variant_index_ptr { index_ptr },
m_interval_list { interval_list.empty() ? all_intervals : move(interval_list) },
m_interval_list { interval_list.empty() ? all_intervals : interval_list },
m_interval_iter { m_interval_list.begin() },
m_index_iter_ptr { utils::make_unique_hts_itr(bcf_itr_querys(m_variant_index_ptr.get(), m_variant_header_ptr.get(), m_interval_iter->c_str())) }
{
Expand Down
2 changes: 1 addition & 1 deletion gamgee/indexed_variant_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class IndexedVariantIterator : public VariantIterator {
IndexedVariantIterator(const std::shared_ptr<htsFile>& file_ptr,
const std::shared_ptr<hts_idx_t>& index_ptr,
const std::shared_ptr<bcf_hdr_t>& header_ptr,
const std::vector<std::string> interval_list = all_intervals);
const std::vector<std::string>& interval_list = all_intervals);

/**
* @brief an IndexedVariantIterator cannot be copied safely, as it is iterating over a stream.
Expand Down
4 changes: 2 additions & 2 deletions gamgee/indexed_variant_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ class IndexedVariantReader {
* @param interval_list a vector of intervals represented by strings. Empty vector for all intervals.
*
*/
IndexedVariantReader(const std::string& filename, const std::vector<std::string> interval_list) :
IndexedVariantReader(const std::string& filename, const std::vector<std::string>& interval_list) :
m_variant_file_ptr { utils::make_shared_hts_file(bcf_open(filename.c_str(), "r")) },
m_variant_index_ptr { utils::make_shared_hts_index(bcf_index_load(filename.c_str())) },
m_variant_header_ptr { utils::make_shared_variant_header(bcf_hdr_read(m_variant_file_ptr.get())) },
m_interval_list { std::move(interval_list) }
m_interval_list { interval_list }
{}

/**
Expand Down
4 changes: 2 additions & 2 deletions gamgee/interval.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class Interval {
* @param stop stop location (inclusive)
* @param output_type desired output format (only used if Interval is sent to output stream)
*/
explicit Interval(std::string chr, const uint32_t start, const uint32_t stop, const IntervalType output_type = IntervalType::GATK) :
m_chr{std::move(chr)},
explicit Interval(const std::string& chr, const uint32_t start, const uint32_t stop, const IntervalType output_type = IntervalType::GATK) :
m_chr{chr},
m_start{start},
m_stop{stop},
m_output_type{output_type}
Expand Down
2 changes: 1 addition & 1 deletion gamgee/multiple_variant_iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ MultipleVariantIterator::MultipleVariantIterator() :
m_variant_vector {}
{}

MultipleVariantIterator::MultipleVariantIterator(const std::vector<std::shared_ptr<htsFile>> variant_files, const std::shared_ptr<bcf_hdr_t> variant_header) :
MultipleVariantIterator::MultipleVariantIterator(const std::vector<std::shared_ptr<htsFile>>& variant_files, const std::shared_ptr<bcf_hdr_t>& variant_header) :
m_queue {},
m_variant_vector {}
{
Expand Down
2 changes: 1 addition & 1 deletion gamgee/multiple_variant_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class MultipleVariantIterator {
* @param variant_files vector of vcf/bcf files opened via the bcf_open() macro from htslib
* @param variant_header the combined vcf/bcf file header
*/
MultipleVariantIterator(const std::vector<std::shared_ptr<htsFile>> variant_files, const std::shared_ptr<bcf_hdr_t> variant_header);
MultipleVariantIterator(const std::vector<std::shared_ptr<htsFile>>& variant_files, const std::shared_ptr<bcf_hdr_t>& variant_header);

/**
* @brief a MultipleVariantIterator move constructor guarantees all objects will have the same state.
Expand Down

0 comments on commit 91b6e14

Please sign in to comment.