37 template <
class T,
class I>
51 inline std::vector<T>&
vec() {
return v_; }
52 inline const std::vector<T>&
vec()
const {
return v_; }
54 inline T& operator[](I idx);
55 inline const T& operator[](I idx)
const;
56 inline T&
first() {
return v_.front(); }
57 inline const T&
first()
const {
return v_.front(); }
58 inline T&
last() {
return v_.back(); }
59 inline const T&
last()
const {
return v_.back(); }
60 inline I
size()
const {
return (I)v_.size(); }
61 inline bool setCapacity(I sz,
bool withmargin);
65 inline bool setSize(I sz,T val);
67 inline bool validIdx(I idx)
const {
return idx>=0 && idx<size(); }
68 inline I
indexOf(
const T&,
bool forward,I start=-1)
const;
69 inline I count(
const T&)
const;
70 inline bool isPresent(
const T&)
const;
72 inline VectorAccess& operator =(
const VectorAccess& v2 )
73 { v_ = v2.
v_;
return *
this; }
74 inline bool push_back(
const T& t );
76 inline void insert( I pos,
const T& val )
77 { v_.insert(v_.begin() + pos,val); }
82 for ( I idx=size()-1; idx!=-1; idx-- )
83 {
if ( v_[idx] == t ) {
remove(idx);
return; } }
85 inline void remove( I idx )
88 v_.erase( v_.begin() + idx );
90 inline void remove( I i1, I i2 )
92 if ( i1 == i2 ) {
remove( i1 );
return; }
93 if ( i1 > i2 ) std::swap( i1, i2 );
95 if ( i1 >= sz )
return;
97 if ( i2 >= sz-1 ) i2 = sz-1;
98 v_.erase( v_.begin()+i1, v_.begin()+i2+1 );
101 { std::swap( v_[i], v_[j] ); }
104 { std::fill( v_.begin(), v_.end(), val ); }
105 inline void replace(
const T& val,
const T& newval )
107 std::replace( v_.begin(), v_.end(), val, newval );
112 if ( t == aft || size() < 2 )
return;
113 I tidx = -1; I aftidx = -1;
114 for ( I idx=size()-1; idx!=-1; idx-- )
117 { tidx = idx;
if ( aftidx != -1 )
break; }
118 if ( v_[idx] == aft )
119 { aftidx = idx;
if ( tidx != -1 )
break; }
121 if ( tidx == -1 || aftidx == -1 || tidx == aftidx )
return;
123 for ( I idx=tidx; idx<aftidx; idx++ )
126 for ( I idx=tidx; idx>aftidx+1; idx-- )
132 if ( size() < 2 )
return;
134 for ( I idx=size()-1; idx!=-1; idx-- )
135 if ( v_[idx] == t ) { tidx = idx;
break; }
136 for ( I idx=tidx; idx>0; idx-- )
147 #define mExportVectorAccess(mod,tp,itp) \ 148 template mExpClass(mod) std::allocator<tp>;\ 149 template mExpClass(mod) std::_Vector_val<tp,std::allocator<tp> >;\ 150 template mExpClass(mod) std::vector<tp>;\ 151 template mExpClass(mod) VectorAccess<tp,itp>;\ 154 template<
class T,
class I>
inline 157 if ( sz<=v_.capacity() )
172 try { v_.reserve(sz); }
173 catch ( std::bad_alloc )
175 catch ( std::length_error )
182 template<
class T,
class I>
inline 187 catch ( std::bad_alloc )
194 template<
class T,
class I>
inline 197 const T lastelem = v_.back();
203 template<
class T,
class I>
inline 206 try { v_.resize(sz,val); }
207 catch ( std::bad_alloc )
215 #define mImplOperator \ 216 try { return v_.at(idx); } \ 217 catch ( std::out_of_range ) \ 218 { DBG::forceCrash(true); } \ 219 return v_[(typename std::vector<T>::size_type)idx] 223 #define mImplOperator \ 224 return v_[(typename std::vector<T>::size_type)idx] 229 template<
class T,
class I>
inline 236 template<
class T,
class I>
inline 245 template<
class T,
class I>
inline 250 typename std::vector<T>::const_iterator begin = v_.begin();
251 const typename std::vector<T>::const_iterator end = v_.end();
255 const typename std::vector<T>::const_iterator res =
260 return mCast(I,res-v_.begin());
263 typename std::vector<T>::const_reverse_iterator begin = v_.rbegin();
264 const typename std::vector<T>::const_reverse_iterator end = v_.rend();
267 const I nrskipped = size()-1-start;
271 const typename std::vector<T>::const_reverse_iterator res =
276 return mCast(I,end-res)-1;
280 template<
class T,
class I>
inline 283 return mCast(I,std::count(v_.begin(),v_.end(),t));
287 template<
class T,
class I>
inline 290 const typename std::vector<T>::const_iterator end = v_.end();
291 return std::find( v_.begin(), end, t )!=end;
T & last()
Definition: vectoraccess.h:58
bool push_back(const T &t)
Definition: vectoraccess.h:183
const T & last() const
Definition: vectoraccess.h:59
T & first()
Definition: vectoraccess.h:56
I indexOf(const T &, bool forward, I start=-1) const
Definition: vectoraccess.h:246
#define mCast(tp, v)
Definition: commondefs.h:124
const std::vector< T > & vec() const
Definition: vectoraccess.h:52
bool setSize(I sz, T val)
Definition: vectoraccess.h:204
void erase()
Definition: vectoraccess.h:78
void insert(I pos, const T &val)
Definition: vectoraccess.h:76
ObjectSet< T >::size_type indexOf(const ObjectSet< T > &os, const S &val)
Locate object in set.
Definition: objectset.h:169
I count(const T &) const
Definition: vectoraccess.h:281
Simple vector-based container simplifying index-based work.
Definition: vectoraccess.h:38
VectorAccess(I n)
Definition: vectoraccess.h:46
T & operator[](I idx)
Definition: vectoraccess.h:230
void moveToStart(const T &t)
Definition: vectoraccess.h:130
std::vector< T > & vec()
Definition: vectoraccess.h:51
I getCapacity() const
Definition: vectoraccess.h:63
std::vector< T > v_
Definition: vectoraccess.h:142
void replace(const T &val, const T &newval)
Definition: vectoraccess.h:105
void erase(const T &t)
Definition: vectoraccess.h:80
VectorAccess(I n, const T &t)
Definition: vectoraccess.h:47
bool validIdx(I idx) const
Definition: vectoraccess.h:67
const T * find(const ObjectSet< T > &os, const S &val)
Get const object in set.
Definition: objectset.h:183
bool setCapacity(I sz, bool withmargin)
Definition: vectoraccess.h:155
void moveAfter(const T &t, const T &aft)
Definition: vectoraccess.h:110
T object_type
Definition: vectoraccess.h:43
#define mImplOperator
Definition: vectoraccess.h:223
void fillWith(const T &val)
Definition: vectoraccess.h:103
VectorAccess(const VectorAccess &v2)
Definition: vectoraccess.h:49
I size_type
Definition: vectoraccess.h:42
void swap(I i, I j)
Definition: vectoraccess.h:100
VectorAccess()
Definition: vectoraccess.h:45
#define mClass(module)
Definition: commondefs.h:164
const T & first() const
Definition: vectoraccess.h:57
I size() const
Definition: vectoraccess.h:60
T pop_back()
Definition: vectoraccess.h:195
bool isPresent(const T &) const
Definition: vectoraccess.h:288