A library for working with phylogenetic and population genetic data.
v0.32.0
base_output_target.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_UTILS_IO_BASE_OUTPUT_TARGET_H_
2 #define GENESIS_UTILS_IO_BASE_OUTPUT_TARGET_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2023 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 <lczech@carnegiescience.edu>
23  Department of Plant Biology, Carnegie Institution For Science
24  260 Panama Street, Stanford, CA 94305, USA
25 */
26 
35 
36 #include <ostream>
37 #include <string>
38 
39 namespace genesis {
40 namespace utils {
41 
42 // =================================================================================================
43 // Base Output Target
44 // =================================================================================================
45 
60 {
61 public:
62 
63  // -------------------------------------------------------------
64  // Constructors and Rule of Five
65  // -------------------------------------------------------------
66 
67  BaseOutputTarget() = default;
68 
69  BaseOutputTarget( BaseOutputTarget const& ) = default;
70  BaseOutputTarget( BaseOutputTarget&& ) = default;
71 
72  BaseOutputTarget& operator= ( BaseOutputTarget const& ) = default;
74 
76  {}
77 
78  // -------------------------------------------------------------
79  // Members
80  // -------------------------------------------------------------
81 
94  template<typename T>
95  BaseOutputTarget& operator << ( T const& content )
96  {
97  out_stream_() << content;
98  return *this;
99  }
100 
104  std::ostream& ostream()
105  {
106  // Non-virtual interface.
107  return out_stream_();
108  }
109 
117  std::ostream& flush()
118  {
119  return out_stream_().flush();
120  }
121 
128  std::string target_name() const
129  {
130  // Non-virtual interface.
131  return target_name_();
132  }
133 
140  std::string target_string() const
141  {
142  // Non-virtual interface.
143  return target_string_();
144  }
145 
146  // -------------------------------------------------------------
147  // Internal Members
148  // -------------------------------------------------------------
149 
150 private:
151 
152  // Non-virtual interface.
153  virtual std::ostream& out_stream_() = 0;
154  virtual std::string target_name_() const = 0;
155  virtual std::string target_string_() const = 0;
156 
157 };
158 
159 } // namespace utils
160 } // namespace genesis
161 
162 #endif // include guard
genesis::utils::BaseOutputTarget::~BaseOutputTarget
virtual ~BaseOutputTarget()
Definition: base_output_target.hpp:75
genesis::utils::BaseOutputTarget::target_name
std::string target_name() const
Get a name of the output target. This is intended for user output.
Definition: base_output_target.hpp:128
genesis::utils::BaseOutputTarget::BaseOutputTarget
BaseOutputTarget()=default
fs.hpp
Provides functions for accessing the file system.
genesis::utils::BaseOutputTarget
Abstract base class for writing data to an output target.
Definition: base_output_target.hpp:59
genesis::utils::BaseOutputTarget::operator<<
BaseOutputTarget & operator<<(T const &content)
Output stream operator template that simply forwards to the underlying ostream() object.
Definition: base_output_target.hpp:95
genesis::utils::BaseOutputTarget::ostream
std::ostream & ostream()
Get the underlying output stream that is used for writing.
Definition: base_output_target.hpp:104
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::BaseOutputTarget::target_string
std::string target_string() const
Get a string representing the output target.
Definition: base_output_target.hpp:140
genesis::utils::BaseOutputTarget::operator=
BaseOutputTarget & operator=(BaseOutputTarget const &)=default
genesis::utils::BaseOutputTarget::flush
std::ostream & flush()
Flush output stream buffer.
Definition: base_output_target.hpp:117