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);
208 if (this->
size() == 1 && pos > 0) {
210 }
else if (this->
size() > 1 && pos >= this->
size()) {
211 size_t remain = pos % this->
size();
213 return this->
at(remain);
215 return this->
at(pos);
294 inline bool empty() {
return this->vec_m.empty(); }
327 inline void clear() { this->vec_m.clear(); }
333 return this->vec_m.insert(pos, value);
341 return this->vec_m.insert(pos, count, value);
347 template <
class InputIt>
349 return this->vec_m.insert(pos, first, last);
357 return this->vec_m.insert(pos, ilist);
363 template <
class... Args>
365 return this->vec_m.emplace(pos, std::forward<Args>(args)...);
377 return this->vec_m.erase(first, last);
383 inline void push_back(
const Type &&value) { this->vec_m.push_back(value); }
388 template <
class... Args>
390 this->vec_m.emplace_back(std::forward<Args>(args)...);
401 inline void resize(
size_t s) { this->vec_m.resize(s); }
406 inline void swap(
Vector &other) { this->vec_m.swap(other.vec_m); }
417 inline operator std::vector<Type>() {
return this->vec_m; }
428 explicit operator tmbutils::vector<Type>()
const {
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()
const {
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];
454 explicit operator tmbutils::vector<Type>() {
455 tmbutils::vector<Type> ret(this->vec_m.size());
456 for (
size_t i = 0; i < this->vec_m.size(); i++) {
457 ret[i] = this->vec_m[i];
465 tmbutils::vector<Type>
to_tmb() {
466 tmbutils::vector<Type> ret(this->vec_m.size());
467 for (
size_t i = 0; i < this->vec_m.size(); i++) {
468 ret[i] = this->vec_m[i];
483 std::vector<Type>
to_std()
const {
return this->vec_m; }
494 std::vector<Type>
to_tmb()
const {
return this->vec_m; }
502 std::string
get_tag()
const {
return this->tag_m; }
507 void set_tag(
const std::string &tag) { this->tag_m = tag; }
518 return lhs.vec_m == rhs.vec_m;
530template <
typename Type>
532 out << std::fixed << std::setprecision(10);
539 for (
size_t i = 0; i < v.
size() - 1; i++) {
541 out <<
"-999" <<
",";
546 if (v[v.
size() - 1] != v[v.
size() - 1]) {
549 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:364
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:304
reverse_iterator rend()
Returns a reverse iterator to the element following the last element of the reversed vector....
Definition fims_vector.hpp:273
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:227
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:309
iterator begin()
Returns an iterator to the first element of the vector.
Definition fims_vector.hpp:254
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:260
void shrink_to_fit()
Reduces memory usage by freeing unused memory.
Definition fims_vector.hpp:320
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:315
void emplace_back(Args &&...args)
Constructs an element in-place at the end.
Definition fims_vector.hpp:389
reference front()
Returns a reference to the first element in the container.
Definition fims_vector.hpp:222
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:502
std::vector< Type >::value_type value_type
Definition fims_vector.hpp:41
void swap(Vector &other)
Swaps the contents.
Definition fims_vector.hpp:406
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:383
iterator insert(const_iterator pos, InputIt first, InputIt last)
Inserts elements from range [first, last) before pos.
Definition fims_vector.hpp:348
bool empty()
Checks whether the container is empty.
Definition fims_vector.hpp:294
iterator erase(iterator pos)
Removes the element at pos.
Definition fims_vector.hpp:371
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:242
reference back()
Returns a reference to the last element in the container.
Definition fims_vector.hpp:232
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:287
void pop_back()
Removes the last element.
Definition fims_vector.hpp:396
void resize(size_t s)
Changes the number of elements stored.
Definition fims_vector.hpp:401
std::vector< Type > to_std() const
Convert fims::Vector to std::vector.
Definition fims_vector.hpp:483
Type & get_force_scalar_wrap(size_t pos)
If this vector is size 1 and pos is greater than zero, the first index is returned....
Definition fims_vector.hpp:207
std::vector< Type > to_tmb() const
Convert fims::Vector to TMB vector type.
Definition fims_vector.hpp:494
iterator erase(iterator first, iterator last)
Removes the elements in the range [first, last).
Definition fims_vector.hpp:376
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:280
iterator insert(const_iterator pos, const Type &value)
Inserts value before pos.
Definition fims_vector.hpp:332
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:356
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:266
const_pointer data() const
Returns a constant pointer to the underlying data array.
Definition fims_vector.hpp:247
size_type size() const
Returns the number of elements.
Definition fims_vector.hpp:299
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:507
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:327
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:237
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:517
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:339
std::ostream & operator<<(std::ostream &out, const fims::Vector< Type > &v)
Output for std::ostream& for a vector.
Definition fims_vector.hpp:531
bool operator==(const fims::Vector< T > &lhs, const fims::Vector< T > &rhs)
Comparison operator.
Definition fims_vector.hpp:517