STIR  6.2.0
InputStreamWithRecords.h
Go to the documentation of this file.
1 //
2 //
11 /*
12  Copyright (C) 2003- 2011, Hammersmith Imanet Ltd
13  This file is part of STIR.
14 
15  SPDX-License-Identifier: Apache-2.0
16 
17  See STIR/LICENSE.txt for details
18 */
19 
20 #ifndef __stir_IO_InputStreamWithRecords_H__
21 #define __stir_IO_InputStreamWithRecords_H__
22 
23 #include "stir/shared_ptr.h"
24 #include "stir/Succeeded.h"
25 
26 #include <iostream>
27 #include <string>
28 #include <vector>
29 
30 START_NAMESPACE_STIR
31 
33 
58 template <class RecordT, class OptionsT>
60 {
61 public:
62  typedef std::vector<std::streampos>::size_type SavedPosition;
64 
66  inline InputStreamWithRecords(const shared_ptr<std::istream>& stream_ptr,
67  const std::size_t size_of_record_signature,
68  const std::size_t max_size_of_record,
69  const OptionsT& options);
70 
72 
75  inline InputStreamWithRecords(const std::string& filename,
76  const std::size_t size_of_record_signature,
77  const std::size_t max_size_of_record,
78  const OptionsT& options,
79  const std::streampos start_of_data = 0);
80 
81  virtual ~InputStreamWithRecords() {}
82 
83  inline virtual Succeeded get_next_record(RecordT& record) const;
84 
86  inline Succeeded reset();
87 
89 
92  inline SavedPosition save_get_position();
93 
95  inline Succeeded set_get_position(const SavedPosition&);
96 
98 
102  inline std::vector<std::streampos> get_saved_get_positions() const;
104 
109  inline void set_saved_get_positions(const std::vector<std::streampos>&);
110 
111  inline std::istream& get_stream() { return *this->stream_ptr; }
112 
113 private:
114  shared_ptr<std::istream> stream_ptr;
115  const std::string filename;
116 
117  std::streampos starting_stream_position;
118  std::vector<std::streampos> saved_get_positions;
119 
120  const std::size_t size_of_record_signature;
121  const std::size_t max_size_of_record;
122 
123  const OptionsT options;
124 };
125 
126 END_NAMESPACE_STIR
127 
129 
130 #endif
Declaration of class stir::Succeeded.
Implementation of class stir::InputStreamWithRecords.
A helper class to read data from a (presumably binary) stream.
Definition: InputStreamWithRecords.h:59
Import of std::shared_ptr, std::dynamic_pointer_cast and std::static_pointer_cast (or corresponding b...
a class containing an enumeration type that can be used by functions to signal successful operation o...
Definition: Succeeded.h:43