Program Listing for File containers.h¶
↰ Return to documentation for file (src/containers.h
)
#ifndef CONTAINERS_H_
#define CONTAINERS_H_
#include <vector>
#include "structures.h"
template<class _T>
/***
* @tparam _T Type of element to store in the vector.
*/
class LiteralIndexedVector: protected std::vector<_T> {
public:
explicit LiteralIndexedVector(VariableIndex size = 0) :
std::vector<_T>(size * 2) {
}
LiteralIndexedVector(VariableIndex size, const typename std::vector<_T>::value_type& __value)
: std::vector<_T>(size * 2, __value) {
}
inline _T &operator[](const LiteralID lit) {
return *(std::vector<_T>::begin() + lit.raw());
}
inline const _T &operator[](const LiteralID &lit) const {
return *(std::vector<_T>::begin() + lit.raw());
}
inline typename std::vector<_T>::iterator begin() {
return std::vector<_T>::begin() + 2;
}
void resize(VariableIndex _size) {
std::vector<_T>::resize(_size * 2);
}
void resize(VariableIndex _size, const typename std::vector<_T>::value_type& _value) {
std::vector<_T>::resize(_size * 2, _value);
}
void reserve(VariableIndex _size) {
std::vector<_T>::reserve(_size * 2);
}
LiteralID end_lit() {
return LiteralID(size() / 2, false);
}
// Methods reused from the imported class
using std::vector<_T>::end;
using std::vector<_T>::size;
using std::vector<_T>::clear;
using std::vector<_T>::push_back;
};
#endif /* CONTAINERS_H_ */