libpniio
data_reader.hpp
Go to the documentation of this file.
1 //
2 // (c) Copyright 2011 DESY, Eugen Wintersberger <eugen.wintersberger@desy.de>
3 //
4 // This file is part of libpniio.
5 //
6 // libpniio is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // libpniio is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with libpniio. If not, see <http://www.gnu.org/licenses/>.
18 // ===========================================================================
19 //
20 // Created on: Apr 23, 2012
21 // Author: Eugen Wintersberger <eugen.wintersberger@desy.de>
22 //
23 //
24 #pragma once
25 
26 #include <memory>
27 #include <iostream>
28 #include <fstream>
29 #include <pni/core/types.hpp>
30 
31 
32 namespace pni{
33 namespace io{
34 
46  {
47  private:
49  pni::core::string _fname;
51  bool _is_binary;
52  //the stream is accessed via a unique pointer this allows moveing
53  //the stream around while benefiting from all advantages of a smart
54  //pointer
56  mutable std::unique_ptr<std::ifstream> _istream;
57 
72  std::unique_ptr<std::ifstream>
73  _open_stream(const pni::core::string &fname) const;
74  protected:
84  std::ifstream &_get_stream() const { return *_istream; }
85 
86  //-----------------------------------------------------------------
93  void _set_binary() { _is_binary = true; }
94 
95  //=======================Constructors===============================
97  data_reader();
98 
99  //-----------------------------------------------------------------
109  explicit data_reader(const pni::core::string &fname,bool binary=false);
110 
111  //-----------------------------------------------------------------
114 
115  //-----------------------------------------------------------------
117  data_reader(const data_reader &r) = delete;
118 
119  //=======================assignment operator=======================
121  data_reader &operator=(const data_reader &r) = delete;
122 
123  //-----------------------------------------------------------------
126 
127 
128 
129  public:
130  //===============constructor and destructors===================
132  virtual ~data_reader();
133 
134  //====================member methods===========================
140  pni::core::string filename() const;
141 
142  //-------------------------------------------------------------
148  void filename(const pni::core::string &fname);
149 
150  //-------------------------------------------------------------
152  virtual void close();
153 
154  //-------------------------------------------------------------
161  virtual void open();
162 
163  };
164 
165 //end of namespace
166 }
167 }
base class for data readers
Definition: data_reader.hpp:45
data_reader & operator=(const data_reader &r)=delete
copy assigment is deleted
pni::core::string filename() const
get filename
Definition: data_reader.cpp:102
std::unique_ptr< std::ifstream > _open_stream(const pni::core::string &fname) const
open the stream
Definition: data_reader.cpp:37
pni::core::string _fname
name of the file
Definition: data_reader.hpp:49
virtual void close()
close the file
Definition: data_reader.cpp:114
std::ifstream & _get_stream() const
get stream
Definition: data_reader.hpp:84
Definition: cbf_reader.hpp:41
virtual void open()
open file
Definition: data_reader.cpp:121
void _set_binary()
set binary mode
Definition: data_reader.hpp:93
std::unique_ptr< std::ifstream > _istream
stream from which to read data
Definition: data_reader.hpp:56
bool _is_binary
flag determining how files will be opened
Definition: data_reader.hpp:51
virtual ~data_reader()
destructor
Definition: data_reader.cpp:83
data_reader()
default constructor
Definition: data_reader.cpp:54