A toolkit for working with phylogenetic data.
v0.24.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-2018 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 
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 
76  size_t read( char* buffer, size_t size )
77  {
78  // Non-virtual interface.
79  return read_( buffer, size );
80  }
81 
85  std::string source_name() const
86  {
87  // Non-virtual interface.
88  return source_name_();
89  }
90 
95  std::string source_string() const
96  {
97  // Non-virtual interface.
98  return source_string_();
99  }
100 
101  // -------------------------------------------------------------
102  // Internal Members
103  // -------------------------------------------------------------
104 
105 private:
106 
107  virtual size_t read_( char* buffer, size_t size ) = 0;
108 
109  virtual std::string source_name_() const = 0;
110  virtual std::string source_string_() const = 0;
111 
112 };
113 
114 } // namespace utils
115 } // namespace genesis
116 
117 #endif // include guard
BaseInputSource & operator=(BaseInputSource const &)=default
Container namespace for all symbols of genesis in order to keep them separate when used as a library...
size_t read(char *buffer, size_t size)
Read size many bytes into the char buffer.
std::string source_string() const
Get a string representing the input source. This is intended for the reader classes, which for example might want to examine the input file name.
Provides functions for accessing the file system.
Abstract base class for reading byte data from input sources.
std::string source_name() const
Get a name of the input source. This is intended for user output.