A library for working with phylogenetic and population genetic data.
v0.32.0
base_input_source.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_UTILS_IO_BASE_INPUT_SOURCE_H_
2 #define GENESIS_UTILS_IO_BASE_INPUT_SOURCE_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2024 Lucas Czech
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@sund.ku.dk>
23  University of Copenhagen, Globe Institute, Section for GeoGenetics
24  Oster Voldgade 5-7, 1350 Copenhagen K, Denmark
25 */
26 
35 
36 #include <string>
37 
38 namespace genesis {
39 namespace utils {
40 
41 // =================================================================================================
42 // Base Input Source
43 // =================================================================================================
44 
51 {
52 public:
53 
54  // -------------------------------------------------------------
55  // Constructors and Rule of Five
56  // -------------------------------------------------------------
57 
58  BaseInputSource() = default;
59 
60  BaseInputSource( BaseInputSource const& ) = default;
61  BaseInputSource( BaseInputSource&& ) = default;
62 
63  BaseInputSource& operator= ( BaseInputSource const& ) = default;
65 
66  virtual ~BaseInputSource()
67  {}
68 
69  // -------------------------------------------------------------
70  // Members
71  // -------------------------------------------------------------
72 
79  size_t read( char* buffer, size_t size )
80  {
81  // Non-virtual interface.
82  return read_( buffer, size );
83  }
84 
88  std::string source_name() const
89  {
90  // Non-virtual interface.
91  return source_name_();
92  }
93 
98  std::string source_string() const
99  {
100  // Non-virtual interface.
101  return source_string_();
102  }
103 
116  bool is_trivial() const
117  {
118  // Non-virtual interface.
119  return is_trivial_();
120  }
121 
122  // -------------------------------------------------------------
123  // Internal Members
124  // -------------------------------------------------------------
125 
126 private:
127 
128  virtual size_t read_( char* buffer, size_t size ) = 0;
129 
130  virtual std::string source_name_() const = 0;
131  virtual std::string source_string_() const = 0;
132 
133  // By default, we just assume trivial reading unless the derived class overrides this.
134  virtual bool is_trivial_() const
135  {
136  return true;
137  }
138 
139 };
140 
141 } // namespace utils
142 } // namespace genesis
143 
144 #endif // include guard
genesis::utils::BaseInputSource::BaseInputSource
BaseInputSource()=default
fs.hpp
Provides functions for accessing the file system.
genesis::utils::BaseInputSource::source_name
std::string source_name() const
Get a name of the input source. This is intended for user output.
Definition: base_input_source.hpp:88
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::BaseInputSource::operator=
BaseInputSource & operator=(BaseInputSource const &)=default
genesis::utils::BaseInputSource::source_string
std::string source_string() const
Get a string representing the input source. This is intended for the reader classes,...
Definition: base_input_source.hpp:98
genesis::utils::BaseInputSource::is_trivial
bool is_trivial() const
Return whether reading from this source is trivial, such as reading from a file, or involves more com...
Definition: base_input_source.hpp:116
genesis::utils::BaseInputSource::~BaseInputSource
virtual ~BaseInputSource()
Definition: base_input_source.hpp:66
genesis::utils::BaseInputSource
Abstract base class for reading byte data from input sources.
Definition: base_input_source.hpp:50
genesis::utils::BaseInputSource::read
size_t read(char *buffer, size_t size)
Read size many bytes into the char buffer.
Definition: base_input_source.hpp:79