A library for working with phylogenetic and population genetic data.
v0.27.0
stream_input_source.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_UTILS_IO_STREAM_INPUT_SOURCE_H_
2 #define GENESIS_UTILS_IO_STREAM_INPUT_SOURCE_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2020 Lucas Czech and HITS gGmbH
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 
21  Contact:
22  Lucas Czech <lucas.czech@h-its.org>
23  Exelixis Lab, Heidelberg Institute for Theoretical Studies
24  Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
25 */
26 
36 
37 #include <cstdio>
38 #include <cstring>
39 #include <istream>
40 #include <string>
41 
42 namespace genesis {
43 namespace utils {
44 
45 // =================================================================================================
46 // Stream Input Source
47 // =================================================================================================
48 
56 class StreamInputSource final : public BaseInputSource
57 {
58 public:
59 
60  // -------------------------------------------------------------
61  // Constructors and Rule of Five
62  // -------------------------------------------------------------
63 
67  explicit StreamInputSource( std::istream& in )
68  : source_( &in )
69  {}
70 
71  StreamInputSource( StreamInputSource const& ) = default;
72  StreamInputSource( StreamInputSource&& ) = default;
73 
74  StreamInputSource& operator= ( StreamInputSource const& ) = default;
76 
77  ~StreamInputSource() override
78  {}
79 
80  // -------------------------------------------------------------
81  // Overloaded Internal Members
82  // -------------------------------------------------------------
83 
84 private:
85 
89  size_t read_( char* buffer, size_t size ) override
90  {
91  source_->read( buffer, size );
92  return source_->gcount();
93  }
94 
98  std::string source_name_() const override
99  {
100  return "input stream";
101  }
102 
106  std::string source_string_() const override
107  {
108  return "stream";
109  }
110 
111  // -------------------------------------------------------------
112  // Member Variables
113  // -------------------------------------------------------------
114 
115  std::istream* source_;
116 };
117 
118 } // namespace utils
119 } // namespace genesis
120 
121 #endif // include guard
fs.hpp
Provides functions for accessing the file system.
base_input_source.hpp
genesis::utils::StreamInputSource::StreamInputSource
StreamInputSource(std::istream &in)
Construct the input source from an std::istream.
Definition: stream_input_source.hpp:67
genesis::utils::StreamInputSource::operator=
StreamInputSource & operator=(StreamInputSource const &)=default
genesis::utils::StreamInputSource::~StreamInputSource
~StreamInputSource() override
Definition: stream_input_source.hpp:77
genesis
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
Definition: placement/formats/edge_color.cpp:42
genesis::utils::StreamInputSource
Input source for reading byte data from an istream.
Definition: stream_input_source.hpp:56
genesis::utils::BaseInputSource
Abstract base class for reading byte data from input sources.
Definition: base_input_source.hpp:50