11#include "../interface/interface.hpp"
26template <
typename Type>
28 std::vector<Type> vec_m;
42 typedef typename std::vector<Type>::allocator_type
44 typedef typename std::vector<Type>::size_type
size_type;
45 typedef typename std::vector<Type>::difference_type
47 typedef typename std::vector<Type>::reference
49 typedef typename std::vector<Type>::const_reference
51 typedef typename std::vector<Type>::pointer
pointer;
52 typedef typename std::vector<Type>::const_pointer
54 typedef typename std::vector<Type>::iterator
iterator;
55 typedef typename std::vector<Type>::const_iterator
57 typedef typename std::vector<Type>::reverse_iterator
59 typedef typename std::vector<Type>::const_reverse_iterator
74 this->vec_m.resize(
size, value);
81 this->vec_m.resize(other.
size());
82 for (
size_t i = 0; i < this->vec_m.size(); i++) {
83 this->vec_m[i] = other[i];
109 Vector(
const std::vector<Type> &other) { this->vec_m = other; }
117 Vector(
const tmbutils::vector<Type> &other) {
118 this->vec_m.resize(other.size());
119 for (
size_t i = 0; i < this->vec_m.size(); i++) {
120 this->vec_m[i] = other[i];
129 Vector(std::initializer_list<Type> init) {
130 this->vec_m = std::vector<Type>(init);
144 if (pos >= this->
size()) {
145 throw std::invalid_argument(
"fims::Vector out of bounds");
147 return this->vec_m[pos];
155 if (n >= this->
size()) {
156 throw std::invalid_argument(
"fims::Vector out of bounds");
158 return this->vec_m[n];
165 inline Type &
at(
size_t n) {
return this->vec_m.at(n); }
171 inline const Type &
at(
size_t n)
const {
return this->vec_m.at(n); }
183 if (this->
size() == 1 && pos > 0) {
185 }
else if (this->
size() > 1 && pos >= this->
size()) {
186 throw std::invalid_argument(
187 "fims::Vector index out of bounds, check parameter sizes of input.");
189 return this->
at(pos);
268 inline bool empty() {
return this->vec_m.empty(); }
301 inline void clear() { this->vec_m.clear(); }
307 return this->vec_m.insert(pos, value);
315 return this->vec_m.insert(pos, count, value);
321 template <
class InputIt>
323 return this->vec_m.insert(pos, first, last);
331 return this->vec_m.insert(pos, ilist);
337 template <
class... Args>
339 return this->vec_m.emplace(pos, std::forward<Args>(args)...);
351 return this->vec_m.erase(first, last);
357 inline void push_back(
const Type &&value) { this->vec_m.push_back(value); }
362 template <
class... Args>
364 this->vec_m.emplace_back(std::forward<Args>(args)...);
375 inline void resize(
size_t s) { this->vec_m.resize(s); }
380 inline void swap(
Vector &other) { this->vec_m.swap(other.vec_m); }
391 inline operator std::vector<Type>() {
return this->vec_m; }
402 explicit operator tmbutils::vector<Type>()
const {
403 tmbutils::vector<Type> ret(this->vec_m.size());
404 for (
size_t i = 0; i < this->vec_m.size(); i++) {
405 ret[i] = this->vec_m[i];
413 tmbutils::vector<Type>
to_tmb()
const {
414 tmbutils::vector<Type> ret(this->vec_m.size());
415 for (
size_t i = 0; i < this->vec_m.size(); i++) {
416 ret[i] = this->vec_m[i];
428 explicit operator tmbutils::vector<Type>() {
429 tmbutils::vector<Type> ret(this->vec_m.size());
430 for (
size_t i = 0; i < this->vec_m.size(); i++) {
431 ret[i] = this->vec_m[i];
439 tmbutils::vector<Type>
to_tmb() {
440 tmbutils::vector<Type> ret(this->vec_m.size());
441 for (
size_t i = 0; i < this->vec_m.size(); i++) {
442 ret[i] = this->vec_m[i];
457 std::vector<Type>
to_std()
const {
return this->vec_m; }
468 std::vector<Type>
to_tmb()
const {
return this->vec_m; }
476 std::string
get_tag()
const {
return this->tag_m; }
481 void set_tag(
const std::string &tag) { this->tag_m = tag; }
492 return lhs.vec_m == rhs.vec_m;
504template <
typename Type>
506 out << std::fixed << std::setprecision(10);
513 for (
size_t i = 0; i < v.
size() - 1; i++) {
515 out <<
"-999" <<
",";
520 if (v[v.
size() - 1] != v[v.
size() - 1]) {
523 out << v[v.
size() - 1] <<
"]";
Definition fims_vector.hpp:27
std::vector< Type >::pointer pointer
Definition fims_vector.hpp:51
iterator emplace(const_iterator pos, Args &&...args)
Constructs element in-place.
Definition fims_vector.hpp:338
std::vector< Type >::const_iterator const_iterator
Definition fims_vector.hpp:56
size_type max_size() const
Returns the maximum possible number of elements.
Definition fims_vector.hpp:278
reverse_iterator rend()
Returns a reverse iterator to the element following the last element of the reversed vector....
Definition fims_vector.hpp:247
const Type & at(size_t n) const
Returns a constant reference to the element at specified location pos. Bounds checking is performed.
Definition fims_vector.hpp:171
const_reference front() const
Returns a constant reference to the first element in the container.
Definition fims_vector.hpp:201
std::vector< Type >::const_reverse_iterator const_reverse_iterator
Definition fims_vector.hpp:60
Vector(const Vector< Type > &other)
Copy constructor.
Definition fims_vector.hpp:80
void reserve(size_type cap)
Reserves storage.
Definition fims_vector.hpp:283
iterator begin()
Returns an iterator to the first element of the vector.
Definition fims_vector.hpp:228
std::vector< Type >::reference reference
Definition fims_vector.hpp:48
iterator end()
Returns an iterator to the element following the last element of the vector.
Definition fims_vector.hpp:234
void shrink_to_fit()
Reduces memory usage by freeing unused memory.
Definition fims_vector.hpp:294
Vector(std::initializer_list< Type > init)
Initialization constructor from std::initializer_list<Type> type.
Definition fims_vector.hpp:129
size_type capacity()
Returns the number of elements that can be held in currently allocated storage.
Definition fims_vector.hpp:289
void emplace_back(Args &&...args)
Constructs an element in-place at the end.
Definition fims_vector.hpp:363
reference front()
Returns a reference to the first element in the container.
Definition fims_vector.hpp:196
std::string get_tag() const
Gets the tag for the vector. A tag can represent anything and is not used internally by FIMS.
Definition fims_vector.hpp:476
std::vector< Type >::value_type value_type
Definition fims_vector.hpp:41
void swap(Vector &other)
Swaps the contents.
Definition fims_vector.hpp:380
Type & at(size_t n)
Returns a reference to the element at specified location pos. Bounds checking is performed.
Definition fims_vector.hpp:165
void push_back(const Type &&value)
Adds an element to the end.
Definition fims_vector.hpp:357
iterator insert(const_iterator pos, InputIt first, InputIt last)
Inserts elements from range [first, last) before pos.
Definition fims_vector.hpp:322
bool empty()
Checks whether the container is empty.
Definition fims_vector.hpp:268
iterator erase(iterator pos)
Removes the element at pos.
Definition fims_vector.hpp:345
Type & get_force_scalar(size_t pos)
If this vector is size 1 and pos is greater than zero, the first index is returned....
Definition fims_vector.hpp:182
std::vector< Type >::const_reference const_reference
Definition fims_vector.hpp:50
Vector(size_t size, const Type &value=Type())
Constructs a Vector of length "size" and sets the elements with the value from input "value".
Definition fims_vector.hpp:73
pointer data()
Returns a pointer to the underlying data array.
Definition fims_vector.hpp:216
reference back()
Returns a reference to the last element in the container.
Definition fims_vector.hpp:206
const Type & operator[](size_t n) const
Returns a constant reference to the element at specified location pos. No bounds checking is performe...
Definition fims_vector.hpp:154
const_reverse_iterator rend() const
Returns a constant reverse iterator to the element following the last element of the reversed vector....
Definition fims_vector.hpp:261
void pop_back()
Removes the last element.
Definition fims_vector.hpp:370
void resize(size_t s)
Changes the number of elements stored.
Definition fims_vector.hpp:375
std::vector< Type > to_std() const
Convert fims::Vector to std::vector.
Definition fims_vector.hpp:457
std::vector< Type > to_tmb() const
Convert fims::Vector to TMB vector type.
Definition fims_vector.hpp:468
iterator erase(iterator first, iterator last)
Removes the elements in the range [first, last).
Definition fims_vector.hpp:350
const_reverse_iterator rbegin() const
Returns a constant reverse iterator to the first element of the reversed vector. It corresponds to th...
Definition fims_vector.hpp:254
iterator insert(const_iterator pos, const Type &value)
Inserts value before pos.
Definition fims_vector.hpp:306
std::vector< Type >::allocator_type allocator_type
Definition fims_vector.hpp:43
iterator insert(const_iterator pos, std::initializer_list< Type > ilist)
Inserts elements from initializer list ilist before pos.
Definition fims_vector.hpp:330
reverse_iterator rbegin()
Returns a reverse iterator to the first element of the reversed vector. It corresponds to the last el...
Definition fims_vector.hpp:240
const_pointer data() const
Returns a constant pointer to the underlying data array.
Definition fims_vector.hpp:221
size_type size() const
Returns the number of elements.
Definition fims_vector.hpp:273
Vector()
Definition fims_vector.hpp:67
Type & operator[](size_t pos)
Returns a reference to the element at specified location pos. No bounds checking is performed.
Definition fims_vector.hpp:143
void set_tag(const std::string &tag)
Sets the tag for the vector. A tag can be set to any string value and is not used internally by FIMS.
Definition fims_vector.hpp:481
std::vector< Type >::difference_type difference_type
Definition fims_vector.hpp:46
Vector & operator=(const Vector &other)
Assignment operator for fims::Vector.
Definition fims_vector.hpp:96
std::vector< Type >::const_pointer const_pointer
Definition fims_vector.hpp:53
std::vector< Type >::iterator iterator
Definition fims_vector.hpp:54
Vector(const std::vector< Type > &other)
Initialization constructor from std::vector<Type> type.
Definition fims_vector.hpp:109
void clear()
Clears the contents.
Definition fims_vector.hpp:301
std::vector< Type >::size_type size_type
Definition fims_vector.hpp:44
const_reference back() const
Returns a constant reference to the last element in the container.
Definition fims_vector.hpp:211
friend bool operator==(const fims::Vector< T > &lhs, const fims::Vector< T > &rhs)
friend comparison operator. Allows the operator to see private members of fims::Vector<Type>.
Definition fims_vector.hpp:491
std::vector< Type >::reverse_iterator reverse_iterator
Definition fims_vector.hpp:58
iterator insert(const_iterator pos, size_type count, const Type &value)
Inserts count copies of the value before pos.
Definition fims_vector.hpp:313
std::ostream & operator<<(std::ostream &out, const fims::Vector< Type > &v)
Output for std::ostream& for a vector.
Definition fims_vector.hpp:505
bool operator==(const fims::Vector< T > &lhs, const fims::Vector< T > &rhs)
Comparison operator.
Definition fims_vector.hpp:491