libmonaa  0.5.2
word_container.hh
1 #pragma once
2 
3 #include "lazy_deque.hh"
4 #include <vector>
5 
13 template <class Container> class WordContainer {
14 protected:
16  Container vec;
17 
18 public:
27  WordContainer<Container>(FILE *file, bool isBinary = false)
28  : vec(file, isBinary) {}
36  typename Container::value_type operator[](const std::size_t n) {
37  return vec[n];
38  }
46  typename Container::value_type at(const std::size_t n) { return vec.at(n); }
54  std::size_t size() const { return vec.size(); }
61  void setFront(std::size_t n) { return vec.setFront(n); }
68  bool fetch(std::size_t n) { return vec.fetch(n); }
69 };
70 
76 
82 template <class T> class Vector : public std::vector<T> {
83 private:
84 public:
85  Vector(FILE *, bool) {}
86  void setFront(std::size_t) {}
87  bool fetch(std::size_t n) { return n < this->size(); }
88 };
89 
90 template <class T> class WordVector : public WordContainer<Vector<T>> {
91 public:
92  WordVector(FILE *file, bool isBinary = false)
93  : WordContainer<Vector<T>>(file, isBinary) {
94  const auto getOneElem = isBinary ? getOneBinary : getOne;
95  T elem;
96  while (getOneElem(file, elem) != EOF) {
97  this->vec.push_back(elem);
98  }
99  }
100 };
Definition: word_container.hh:82
Container class for the input timed word.
Definition: word_container.hh:13
bool fetch(std::size_t n)
Fetch the timed words by n-th position.
Definition: word_container.hh:68
Container::value_type operator[](const std::size_t n)
Access an element of the container.
Definition: word_container.hh:36
Container vec
The actual container of the timed word.
Definition: word_container.hh:16
Container::value_type at(const std::size_t n)
Access an element of the container.
Definition: word_container.hh:46
std::size_t size() const
Returns the length of the timed word.
Definition: word_container.hh:54
void setFront(std::size_t n)
Discard the elements before n-th position.
Definition: word_container.hh:61
Word container with runtime allocation and free.
Word container without any runtime memory alloc / free.
Definition: word_container.hh:90