A library for working with phylogenetic and population genetic data.
v0.27.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-2020 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@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 Output Target
43 // =================================================================================================
44 
49 {
50 public:
51 
52  // -------------------------------------------------------------
53  // Constructors and Rule of Five
54  // -------------------------------------------------------------
55 
56  BaseOutputTarget() = default;
57 
58  BaseOutputTarget( BaseOutputTarget const& ) = default;
59  BaseOutputTarget( BaseOutputTarget&& ) = default;
60 
61  BaseOutputTarget& operator= ( BaseOutputTarget const& ) = default;
63 
65  {}
66 
67  // -------------------------------------------------------------
68  // Members
69  // -------------------------------------------------------------
70 
79  template<typename T>
80  BaseOutputTarget& operator << ( T const& content )
81  {
82  out_stream_() << content;
83  return *this;
84  }
85 
89  std::ostream& ostream()
90  {
91  // Non-virtual interface.
92  return out_stream_();
93  }
94 
98  std::string target_name() const
99  {
100  // Non-virtual interface.
101  return target_name_();
102  }
103 
108  std::string target_string() const
109  {
110  // Non-virtual interface.
111  return target_string_();
112  }
113 
114  // -------------------------------------------------------------
115  // Internal Members
116  // -------------------------------------------------------------
117 
118 private:
119 
120  virtual std::ostream& out_stream_() = 0;
121 
122  virtual std::string target_name_() const = 0;
123  virtual std::string target_string_() const = 0;
124 
125 };
126 
127 } // namespace utils
128 } // namespace genesis
129 
130 #endif // include guard
genesis::utils::BaseOutputTarget::~BaseOutputTarget
virtual ~BaseOutputTarget()
Definition: base_output_target.hpp:64
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:98
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:48
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:80
genesis::utils::BaseOutputTarget::ostream
std::ostream & ostream()
Get the underlying output stream that is used for writing.
Definition: base_output_target.hpp:89
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. This is intended for the writer classes,...
Definition: base_output_target.hpp:108
genesis::utils::BaseOutputTarget::operator=
BaseOutputTarget & operator=(BaseOutputTarget const &)=default