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