• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MikkelSchubert / adapterremoval / #36

22 Jul 2024 09:33AM UTC coverage: 87.26% (-12.7%) from 100.0%
#36

push

travis-ci

MikkelSchubert
remove duplicate tests

2185 of 2504 relevant lines covered (87.26%)

16293.15 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.33
/src/linereader.hpp
1
/*************************************************************************\
2
 * AdapterRemoval - cleaning next-generation sequencing reads            *
3
 *                                                                       *
4
 * Copyright (C) 2015 by Mikkel Schubert - mikkelsch@gmail.com           *
5
 *                                                                       *
6
 * This program is free software: you can redistribute it and/or modify  *
7
 * it under the terms of the GNU General Public License as published by  *
8
 * the Free Software Foundation, either version 3 of the License, or     *
9
 * (at your option) any later version.                                   *
10
 *                                                                       *
11
 * This program is distributed in the hope that it will be useful,       *
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14
 * GNU General Public License for more details.                          *
15
 *                                                                       *
16
 * You should have received a copy of the GNU General Public License     *
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>. *
18
\*************************************************************************/
19
#pragma once
20

21
#include "managed_io.hpp" // for managed_reader
22
#include <array>          // for array
23
#include <cstdio>         // for BUFSIZ
24
#include <ios>            // for ios_base, ios_base::failure
25
#include <isa-l.h>        // for ISAL_MAJOR_VERSION, ISAL_MINOR_VERSION
26
#include <memory>         // for shared_ptr, unique_ptr
27
#include <string>         // for string
28
#include <vector>         // for vector
29

30
struct inflate_state;
31
struct isal_gzip_header;
32

33
// Required due to 2.30 fixing issues when reading concatenated gzip files
34
static_assert((ISAL_MAJOR_VERSION > 2 ||
35
               (ISAL_MAJOR_VERSION == 2 && ISAL_MINOR_VERSION >= 30)),
36
              "isa-l v2.30+ required");
37

38
namespace adapterremoval {
39

40
//! Buffer used for compressed and uncompressed line data
41
using line_buffer = std::array<char, 10LLU * BUFSIZ>;
42

43
/** Base-class for line reading; used by receivers. */
44
class line_reader_base
45
{
46
public:
47
  /** Does nothing. */
48
  line_reader_base() = default;
34✔
49

50
  /** Closes the file, if still open. */
51
  virtual ~line_reader_base() = default;
34✔
52

53
  /** Reads a line into dst, returning false on EOF. */
54
  virtual bool getline(std::string& dst) = 0;
55

56
  line_reader_base(const line_reader_base&) = delete;
57
  line_reader_base(line_reader_base&&) = delete;
58
  line_reader_base& operator=(const line_reader_base&) = delete;
59
  line_reader_base& operator=(line_reader_base&&) = delete;
60
};
61

62
/** Simple helper class for reading strings from memory */
63
class vec_reader : public line_reader_base
38✔
64
{
65
public:
66
  /** Constructs a reader from a set of lines (not copied) */
67
  explicit vec_reader(const std::vector<std::string>& lines);
68

69
  /** Reads a line into dst, returning false on EOF. */
70
  bool getline(std::string& dst) override;
71

72
private:
73
  //! Reference to vector containing lines of text
74
  const std::vector<std::string>& m_lines;
75
  //! Current position in m_lines
76
  std::vector<std::string>::const_iterator m_it;
77
};
78

79
/**
80
 * Simple line reader.
81
 *
82
 * Currently reads
83
 *  - uncompressed files
84
 *  - gzip compressed files
85
 *
86
 * Errors are reported using either 'io_error' or 'gzip_error'.
87
 */
88
class line_reader : public line_reader_base
89
{
90
public:
91
  /** Creates a line handler from an existing handle */
92
  explicit line_reader(FILE* handle);
93
  /** Constructor; opens file and throws on errors. */
94
  explicit line_reader(std::string filename);
95

96
  ~line_reader() override = default;
78✔
97

×
98
  /** Reads a line into dst, returning false on EOF. */
78✔
99
  bool getline(std::string& dst) override;
100

101
  line_reader(const line_reader&) = delete;
102
  line_reader(line_reader&&) = delete;
103
  line_reader& operator=(const line_reader&) = delete;
104
  line_reader& operator=(line_reader&&) = delete;
105

106
private:
107
  //! Refills 'm_buffer' and sets 'm_buffer_ptr' and 'm_buffer_end'.
108
  void refill_buffers();
109

110
  //! Reader used to fill unparsed buffers
111
  managed_reader m_reader;
112
  /** Refills 'm_raw_buffer'; sets 'm_raw_buffer_ptr' and 'm_raw_buffer_end'. */
113
  void refill_raw_buffer(size_t avail_in = 0);
114
  /** Points 'm_buffer' and other points to corresponding 'm_raw_buffer's. */
115
  void refill_buffers_uncompressed();
116

117
  std::unique_ptr<inflate_state> m_gzip_stream;
118
  std::unique_ptr<isal_gzip_header> m_gzip_header;
119

120
  /** Returns true if the raw buffer contains gzip'd data. */
121
  bool is_raw_buffer_gzip() const;
122
  /** Initializes gzip stream and output buffers. */
123
  void initialize_buffers_gzip();
124
  /** Refills 'm_buffer' from compressed data; may refill raw buffers. */
125
  void refill_buffers_gzip();
126

127
  //! Pointer to buffer of decompressed data; may be equal to m_raw_buffer.
128
  std::shared_ptr<line_buffer> m_buffer;
129
  //! Pointer to current location in input buffer.
130
  line_buffer::iterator m_buffer_ptr;
131
  //! Pointer to end of current buffer.
132
  line_buffer::iterator m_buffer_end;
133

134
  //! Pointer to buffer of raw data.
135
  std::shared_ptr<line_buffer> m_raw_buffer;
136
  //! Pointer to end of current raw buffer.
137
  line_buffer::iterator m_raw_buffer_end;
138

139
  //! Indicates if a read across the EOF has been attempted.
140
  bool m_eof;
141
};
142

143
} // namespace adapterremoval
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc