pocolog_cpp
Stream.hpp
Go to the documentation of this file.
1 #ifndef STREAM_H
2 #define STREAM_H
3 #include <fstream>
4 #include "Format.hpp"
5 #include "StreamDescription.hpp"
6 #include "Index.hpp"
7 #include "FileStream.hpp"
8 
9 namespace pocolog_cpp
10 {
11 
12 class Stream
13 {
14 
15 protected:
18 
21 
22  bool loadSampleHeader(std::streampos pos, pocolog_cpp::SampleHeaderData& header);
23 
24 public:
25  virtual ~Stream();
26 
27  bool isValid() const
28  {
29  return desc.getType() != UnknownStreamType;
30  }
31 
32  std::string getName() const
33  {
34  return desc.getName();
35  }
36 
37  std::string getTypeName() const
38  {
39  return desc.getTypeName();
40  }
41 
43  {
44  return desc.getType();
45  }
46 
47  const base::Time &getFistSampleTime() const
48  {
49  return index.getFirstSampleTime();
50  }
51 
52  const base::Time &getLastSampleTime() const
53  {
54  return index.getLastSampleTime();
55  }
56 
57  size_t getIndex() const
58  {
59  return desc.getIndex();
60  }
61 
62  Index& getFileIndex() const
63  {
64  return index;
65  }
66 
67  size_t getSize() const
68  {
69  return index.getNumSamples();
70  }
71 
72  bool getSampleData(std::vector<uint8_t> &result, size_t sampleNr);
73 
74  template<typename T>
75  bool readSample(T &sample, size_t sampleNr)
76  {
78  fileStream.read((char *) &sample, sizeof(T));
79 
80  return fileStream.good();
81  }
82 
83 };
84 
85 }
86 #endif // STREAM_H
Definition: Index.hpp:15
std::streampos getSamplePos(size_t sampleNr)
Definition: Index.cpp:113
Index & getFileIndex() const
Definition: Stream.hpp:62
bool loadSampleHeader(std::streampos pos, pocolog_cpp::SampleHeaderData &header)
Definition: Stream.cpp:17
bool isValid() const
Definition: Stream.hpp:27
FileStream fileStream
Definition: Stream.hpp:19
StreamType getType() const
Definition: StreamDescription.hpp:36
bool getSampleData(std::vector< uint8_t > &result, size_t sampleNr)
Definition: Stream.cpp:25
Definition: Format.hpp:131
StreamType
Definition: Format.hpp:157
const StreamDescription & desc
Definition: Stream.hpp:16
const base::Time & getLastSampleTime() const
Definition: Index.hpp:64
size_t getSize() const
Definition: Stream.hpp:67
size_t getIndex() const
Definition: Stream.hpp:57
std::streampos seekg(std::streampos pos)
Definition: FileStream.cpp:154
Definition: Format.hpp:159
StreamType getStreamType() const
Definition: Stream.hpp:42
const base::Time & getFirstSampleTime() const
Definition: Index.hpp:59
const std::string & getName() const
Definition: StreamDescription.hpp:41
bool good() const
Definition: FileStream.cpp:144
virtual ~Stream()
Definition: Read.hpp:130
const base::Time & getLastSampleTime() const
Definition: Stream.hpp:52
size_t getIndex() const
Definition: StreamDescription.hpp:31
const base::Time & getFistSampleTime() const
Definition: Stream.hpp:47
Stream(std::istream &input, StreamType type=UnknownStreamType, size_t index=Input::nstream)
Definition: Read.hpp:106
void read(char *buffer, size_t size)
Definition: FileStream.cpp:113
std::string getTypeName() const
Definition: Stream.hpp:37
Index & index
Definition: Stream.hpp:17
bool readSample(T &sample, size_t sampleNr)
Definition: Stream.hpp:75
Definition: StreamDescription.hpp:13
Definition: FileStream.hpp:22
size_t getNumSamples() const
Definition: Index.hpp:69
std::string getName() const
Definition: Stream.hpp:32
const std::string & getTypeName() const
Definition: StreamDescription.hpp:46