astrotypes  0.0
FileReader.h
Go to the documentation of this file.
1 /*
2  * MIT License
3  *
4  * Copyright (c) 2018 PulsarSearchSoft
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #ifndef PSS_ASTROTYPES_SIGPROC_FILEREADER_H
25 #define PSS_ASTROTYPES_SIGPROC_FILEREADER_H
26 #include "Header.h"
28 #include "IStream.h"
29 #include <string>
30 #include <fstream>
31 
32 namespace pss {
33 namespace astrotypes {
34 namespace sigproc {
35 
40 template<typename HeaderType=Header>
41 class FileReader : public IStream<HeaderType>
42 {
43  typedef IStream<HeaderType> BaseT;
44 
45  public:
46  FileReader();
47 
51  FileReader(std::string const& file_name);
52  ~FileReader();
53 
57  void open(std::string const& file_name);
58 
62  template<typename DataType>
63  typename std::enable_if<has_dimensions<DataType, units::Time, units::Frequency>::value, FileReader>::type &
64  operator>>(DataType& data);
65 
69  template<typename Dimension>
71 
75  std::size_t number_of_data_points() const;
76 
77  protected:
78  void do_open(std::string const& file_name);
79 
80  private:
81  std::ifstream _stream;
82  std::string _file_name;
83 };
84 
85 } // namespace sigproc
86 } // namespace astrotypes
87 } // namespace pss
88 #include "detail/FileReader.cpp"
89 
90 #endif // PSS_ASTROTYPES_SIGPROC_FILEREADER_H
std::size_t number_of_data_points() const
the number of data points in the file (i.e number of data points of nbits)
Definition: FileReader.cpp:62
std::enable_if< has_dimensions< DataType, units::Time, units::Frequency >::value, FileReader >::type & operator>>(DataType &data)
read in to the provided data object
Read in a sigproc file.
Definition: FileReader.h:41
void open(std::string const &file_name)
set the filename to read
Definition: FileReader.cpp:46
DimensionSize< Dimension > dimension() const
return the expected dimension of the data in the file
Definition: FileReader.cpp:110
A compile time dimesion tagging of size_t.
Definition: DimensionSize.h:39
void do_open(std::string const &file_name)
Definition: FileReader.cpp:53