A library for working with phylogenetic and population genetic data.
v0.27.0
strict_fstream.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_UTILS_IO_STRICT_FSTREAM_H_
2 #define GENESIS_UTILS_IO_STRICT_FSTREAM_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 
27 /*
28  The code in this file as well as the according source file lib/utils/io/strict_fstream.cpp are
29  adapted from the excellent zstr library (C++ header-only ZLib wrapper" classes) by Matei David,
30  see https://github.com/mateidavid/zstr
31 
32  We adapted the original code by renaming all classes and variables to our standards,
33  moving much of the implementation into a source file, and refining some functionality.
34 
35  For this and the according source file, we need to include the following original license:
36 
37  The MIT License (MIT)
38 
39  Copyright (c) 2015 Matei David, Ontario Institute for Cancer Research
40 
41  Permission is hereby granted, free of charge, to any person obtaining a copy
42  of this software and associated documentation files (the "Software"), to deal
43  in the Software without restriction, including without limitation the rights
44  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
45  copies of the Software, and to permit persons to whom the Software is
46  furnished to do so, subject to the following conditions:
47 
48  The above copyright notice and this permission notice shall be included in all
49  copies or substantial portions of the Software.
50 
51  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
52  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
53  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
54  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
55  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
56  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
57  SOFTWARE.
58  */
59 
67 #include <fstream>
68 #include <string>
69 
70 namespace genesis {
71 namespace utils {
72 
73 // ================================================================================================
74 // Strict Input File Stream
75 // ================================================================================================
76 
97  : public std::ifstream
98 {
99 public:
100 
101  StrictIFStream() = default;
102 
103  StrictIFStream( std::string const& filename, std::ios_base::openmode mode = std::ios_base::in )
104  {
105  open(filename, mode);
106  }
107 
108  void open( std::string const& filename, std::ios_base::openmode mode = std::ios_base::in) ;
109 };
110 
111 // ================================================================================================
112 // Strict Output File Stream
113 // ================================================================================================
114 
134  : public std::ofstream
135 {
136 public:
137 
138  StrictOFStream() = default;
139 
140  StrictOFStream( std::string const& filename, std::ios_base::openmode mode = std::ios_base::out )
141  {
142  open(filename, mode);
143  }
144 
145  void open( std::string const& filename, std::ios_base::openmode mode = std::ios_base::out );
146 };
147 
148 // ================================================================================================
149 // Strict File Stream
150 // ================================================================================================
151 
172  : public std::fstream
173 {
174 public:
175 
176  StrictFStream() = default;
177 
178  StrictFStream( std::string const& filename, std::ios_base::openmode mode = std::ios_base::in )
179  {
180  open(filename, mode);
181  }
182 
183  void open( std::string const& filename, std::ios_base::openmode mode = std::ios_base::in );
184 };
185 
186 } // namespace utils
187 } // namespace genesis
188 
189 #endif // include guard
genesis::utils::StrictOFStream::StrictOFStream
StrictOFStream(std::string const &filename, std::ios_base::openmode mode=std::ios_base::out)
Definition: strict_fstream.hpp:140
genesis::utils::StrictFStream::open
void open(std::string const &filename, std::ios_base::openmode mode=std::ios_base::in)
Definition: strict_fstream.cpp:229
genesis::utils::StrictOFStream::StrictOFStream
StrictOFStream()=default
genesis::utils::StrictIFStream
Stream that defines a strict wrapper around std::ifstream.
Definition: strict_fstream.hpp:96
genesis::utils::StrictOFStream
Stream that defines a strict wrapper around std::ofstream.
Definition: strict_fstream.hpp:133
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::StrictIFStream::open
void open(std::string const &filename, std::ios_base::openmode mode=std::ios_base::in)
Definition: strict_fstream.cpp:210
genesis::utils::StrictOFStream::open
void open(std::string const &filename, std::ios_base::openmode mode=std::ios_base::out)
Definition: strict_fstream.cpp:220
genesis::utils::StrictIFStream::StrictIFStream
StrictIFStream()=default
genesis::utils::StrictIFStream::StrictIFStream
StrictIFStream(std::string const &filename, std::ios_base::openmode mode=std::ios_base::in)
Definition: strict_fstream.hpp:103
genesis::utils::StrictFStream::StrictFStream
StrictFStream()=default
genesis::utils::StrictFStream::StrictFStream
StrictFStream(std::string const &filename, std::ios_base::openmode mode=std::ios_base::in)
Definition: strict_fstream.hpp:178
genesis::utils::StrictFStream
Stream that defines a strict wrapper around std::fstream.
Definition: strict_fstream.hpp:171