pocolog_cpp
MultiFileIndex.hpp
Go to the documentation of this file.
1 #ifndef MULTIFILEINDEX_H
2 #define MULTIFILEINDEX_H
3 #include <vector>
4 #include <string>
5 #include <stdint.h>
6 #include <stdexcept>
7 #include <typelib/registry.hh>
8 #include <boost/function.hpp>
9 
10 namespace pocolog_cpp
11 {
12 class LogFile;
13 class Stream;
14 class InputDataStream;
15 
17 {
18  struct IndexEntry
19  {
20  IndexEntry(): sampleNrInStream(0), stream(NULL) {};
21  uint64_t sampleNrInStream;
22  Stream *stream;
23  size_t globalStreamIdx;
24  } __attribute__((packed));
25 
26  std::vector<IndexEntry> index;
27  std::vector<LogFile *> logFiles;
28  std::vector<Stream *> streams;
29  std::map<Stream *, size_t> streamToGlobalIdx;
30  size_t globalSampleCount;
31  Typelib::Registry combinedRegistry;
32 // base::Time firstSampleTime;
33 // base::Time lastSampleTime;
34 public:
35  MultiFileIndex(const std::vector<std::string> &fileNames);
38 
39  const std::vector<Stream *> getAllStreams() const
40  {
41  return streams;
42  };
43 
44  size_t getSize() const
45  {
46  return globalSampleCount;
47  }
48 
49  size_t getGlobalStreamIdx(size_t globalSamplePos) const
50  {
51  if(globalSamplePos > globalSampleCount - 1)
52  throw std::runtime_error("Error, Sample out of index requested");
53 
54  return index[globalSamplePos].globalStreamIdx;
55  }
56 
57  size_t getGlobalStreamIdx(Stream *stream) const;
58 
59  Stream *getSampleStream(size_t globalSamplePos) const
60  {
61  if(globalSamplePos > globalSampleCount - 1)
62  throw std::runtime_error("Error, Sample out of index requested");
63 
64  return index[globalSamplePos].stream;
65  }
66 
67  size_t getPosInStream(size_t globalSamplePos) const
68  {
69  if(globalSamplePos > globalSampleCount - 1)
70  throw std::runtime_error("Error, Sample out of index requested");
71 
72  return index[globalSamplePos].sampleNrInStream;
73  }
74 
75  /***
76  * Registers a callback, that evaluates every given stream if it
77  * should be included in the MultiIndex
78  * */
79  void registerStreamCheck(boost::function<bool (Stream *stream)> test);
80 
81  Typelib::Registry &getCombinedRegistry()
82  {
83  return combinedRegistry;
84  };
85 
86  bool createIndex(const std::vector<LogFile *> &logfiles);
87  bool createIndex(const std::vector<std::string> &fileNames);
88 
89 private:
90  boost::function<bool (Stream *stream)> streamCheck;
91 };
92 }
93 #endif // MULTIFILEINDEX_H
Definition: MultiFileIndex.hpp:16
bool createIndex(const std::vector< LogFile * > &logfiles)
Definition: MultiFileIndex.cpp:28
size_t getPosInStream(size_t globalSamplePos) const
Definition: MultiFileIndex.hpp:67
~MultiFileIndex()
Definition: MultiFileIndex.cpp:21
MultiFileIndex()
Definition: MultiFileIndex.cpp:16
const std::vector< Stream * > getAllStreams() const
Definition: MultiFileIndex.hpp:39
Typelib::Registry & getCombinedRegistry()
Definition: MultiFileIndex.hpp:81
void registerStreamCheck(boost::function< bool(Stream *stream)> test)
Definition: MultiFileIndex.cpp:147
size_t globalStreamIdx
Definition: MultiFileIndex.hpp:151
uint64_t sampleNrInStream
Definition: MultiFileIndex.hpp:148
size_t getGlobalStreamIdx(size_t globalSamplePos) const
Definition: MultiFileIndex.hpp:49
size_t getSize() const
Definition: MultiFileIndex.hpp:44
Stream * stream
Definition: MultiFileIndex.hpp:150
Stream * getSampleStream(size_t globalSamplePos) const
Definition: MultiFileIndex.hpp:59
IndexEntry()
Definition: MultiFileIndex.hpp:148
Definition: Read.hpp:91