pocolog_cpp
Index.hpp
Go to the documentation of this file.
1 #ifndef INDEX_H
2 #define INDEX_H
3 #include <stddef.h>
4 #include <string>
5 #include <vector>
6 #include <stdint.h>
7 #include <fstream>
8 #include <base/Time.hpp>
9 #include "StreamDescription.hpp"
10 #include "FileStream.hpp"
11 
12 namespace pocolog_cpp
13 {
14 
15 class Index
16 {
17  struct IndexInfo {
18  int64_t samplePosInLogFile;
19  int64_t sampleTime;
20  } __attribute__((packed));
21 
22  struct IndexPrologue {
23  size_t numSamples;
24  int16_t streamIdx;
25  int32_t nameCrc;
26  int64_t firstSampleTime;
27  int64_t lastSampleTime;
28  int64_t dataPos;
29  int64_t streamDescPos;
30  } __attribute__ ((packed));
31 
32  void loadIndex(size_t sampleNr);
33 
34 public:
35  Index(std::string indexFileName, size_t streamIdx);
36 
37  Index(const StreamDescription &desc, off_t posOfStreamDesc);
38 
39  bool matches(const StreamDescription &desc) const;
40 
47  off_t writeIndexToFile(std::fstream &indexFile, off_t prologPos, off_t indexDataPos);
48 
52  static off_t getPrologueSize();
53 
54  void addSample(off_t filePosition, const base::Time &sampleTime);
55 
56  std::streampos getSamplePos(size_t sampleNr);
57  base::Time getSampleTime(size_t sampleNr);
58 
59  const base::Time &getFirstSampleTime() const
60  {
61  return firstSampleTime;// base::Time::fromMicroseconds(prologue.firstSampleTime);
62  }
63 
64  const base::Time &getLastSampleTime() const
65  {
66  return lastSampleTime; //base::Time::fromMicroseconds(prologue.lastSampleTime);
67  }
68 
69  size_t getNumSamples() const
70  {
71  return prologue.numSamples;
72  }
73 
74  std::streampos getDescriptionPos() const
75  {
76  return prologue.streamDescPos;
77  };
78 
79  std::string getName()
80  {
81  return name;
82  }
83 
84  ~Index();
85 private:
86  std::string name;
87  bool firstAdd;
88  size_t curSampleNr;
89  IndexInfo curIndexInfo;
90  FileStream indexFile;
91  std::vector<IndexInfo> buildBuffer;
92  IndexPrologue prologue;
93  base::Time firstSampleTime;
94  base::Time lastSampleTime;
95 };
96 }
97 #endif // INDEX_H
Definition: Index.hpp:15
int64_t firstSampleTime
Definition: Index.hpp:133
int64_t lastSampleTime
Definition: Index.hpp:134
const base::Time & getFirstSampleTime() const
Definition: Index.hpp:59
std::streampos getSamplePos(size_t sampleNr)
Definition: Index.cpp:113
std::string getName()
Definition: Index.hpp:79
void addSample(off_t filePosition, const base::Time &sampleTime)
Definition: Index.cpp:42
Index(std::string indexFileName, size_t streamIdx)
Definition: Index.cpp:12
struct pocolog_cpp::SampleHeader __attribute__
~Index()
Definition: Index.cpp:129
int64_t dataPos
Definition: Index.hpp:135
off_t writeIndexToFile(std::fstream &indexFile, off_t prologPos, off_t indexDataPos)
Definition: Index.cpp:64
int32_t nameCrc
Definition: Index.hpp:132
base::Time getSampleTime(size_t sampleNr)
Definition: Index.cpp:122
int16_t streamIdx
Definition: Index.hpp:131
size_t getNumSamples() const
Definition: Index.hpp:69
int64_t samplePosInLogFile
Definition: Index.hpp:130
int64_t sampleTime
Definition: Index.hpp:131
static off_t getPrologueSize()
Definition: Index.cpp:59
size_t numSamples
Definition: Index.hpp:130
Definition: FileStream.hpp:7
Definition: StreamDescription.hpp:13
std::streampos getDescriptionPos() const
Definition: Index.hpp:74
const base::Time & getLastSampleTime() const
Definition: Index.hpp:64
Definition: FileStream.hpp:22
bool matches(const StreamDescription &desc) const
Definition: Index.cpp:35
int64_t streamDescPos
Definition: Index.hpp:136