SHORE API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
sff.hpp
Go to the documentation of this file.
1 
2 /*
3  * Copyright 2008,2009,2010,2011,2012 Stephan Ossowski, Korbinian Schneeberger,
4  * Felix Ott, Joerg Hagmann, Alf Scotland, Sebastian Bender
5  *
6  * This file is part of SHORE.
7  *
8  * SHORE 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  * SHORE 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 SHORE. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
25 
26 #ifndef IO_SFF_HPP__
27 #define IO_SFF_HPP__
28 
29 #include <iostream>
30 #include <string>
31 
34 #include "shore/stream/streams.hpp"
36 
37 namespace shore {
38 
39 template<typename T>
40 std::istream& read_bigendian(std::istream& in,T& value)
41 {
42  char buf;
43  value=0;
44  for(int n=(sizeof(T)-1)<<3;n>=0;n-=8)
45  {
46  in.get(buf);
47  value+=static_cast<T>(static_cast<uint8_t>(buf))<<n;
48  }
49  return in;
50 }
51 
54 {
55  private:
56 
57  shore::istreams m_is;
58  std::streampos m_streampos;
59 
60  sff_read::commonhead m_header;
61 
62  size_t m_nreads;
63 
64  public:
65 
67 
68  static void read_commonhead(std::istream& in,shore::sff_read::commonhead*const ch);
69  static void read_readhead(std::istream& in,shore::sff_read::readhead*const rh);
70  static size_t read_readdata(std::istream& in,const shore::sff_read::commonhead& ch,
71  const shore::sff_read::readhead& rh,
72  shore::sff_read::readdata*const rd);
73 
74  static void print_commonhead(std::ostream& out,const shore::sff_read::commonhead& ch);
75  static void print_readhead(std::ostream& out,const shore::sff_read::readhead& rh);
76  static void print_readdata(std::ostream& out,const shore::sff_read::readdata& rd);
77 
78  basic_sff_reader(const std::string& fn);
79  basic_sff_reader(std::istream*const in);
80 
81  bool next(sff_read & buf);
82 
83  const std::string & get_name() const;
84 };
85 
87  sff_read,sff_read::compare_type> sff_reader;
88 
91 
95 :public shore::pipe_facade<sff_flatten_pipe,sff_read,read>,
96  public buffer_chain<read>
97 {
98  private:
99 
100  friend class shore::pipeline_core_access;
101 
102  void next();
103  void append(const shore::sff_read &r);
104  void flush();
105 };
106 
107 } // namespace
108 
109 #endif // IO_SFF_HPP__
110