18 #ifndef vectoraccess_h 25 template <
class T,
class I>
35 {
return copy( ts ); }
37 inline size_type size()
const;
39 inline virtual bool setSize(size_type,T val=T());
41 inline virtual bool setCapacity(size_type sz,
bool withmargin);
43 inline virtual size_type getCapacity()
const;
44 inline void setAll(T);
45 inline void replace(T,T);
47 inline T& operator[](size_type);
48 inline const T& operator[](size_type)
const;
50 inline const T& first()
const;
52 inline const T& last()
const;
53 inline virtual bool validIdx(
od_int64)
const;
54 inline virtual size_type
indexOf(T,
bool forward=
true,
55 size_type start=-1)
const;
56 inline bool isPresent(
const T&)
const;
57 inline size_type count(
const T&)
const;
60 inline virtual void insert(size_type,
const T&);
61 inline bool push(
const T&);
64 inline virtual bool append(
const T*,size_type);
66 inline virtual bool addIfNew(
const T&);
74 bool must_preserve_order=
false);
78 inline virtual void move(size_type from,size_type
to);
79 inline virtual void getReOrdered(
const size_type*,
83 inline virtual void reverse();
85 inline virtual void erase();
86 inline virtual void removeSingle(size_type,
87 bool preserver_order=
true);
89 inline virtual void removeRange(size_type from,size_type to);
92 inline virtual T*
arr() {
return gtArr(); }
93 inline virtual const T*
arr()
const {
return gtArr(); }
94 inline std::vector<T>& vec();
95 inline const std::vector<T>& vec()
const;
106 inline virtual T* gtArr()
const;
148 operator bool()
const {
return (
bool) val_; }
179 template <
class T,
class I>
182 if ( a.
size() != b.
size() )
return false;
184 const I sz = a.
size();
185 for ( I idx=0; idx<sz; idx++ )
186 if ( !(a[idx] == b[idx]) )
return false;
191 template <
class T,
class I>
193 {
return !(a == b); }
197 template <
class T,
class I,
class J,
class S>
200 const J sz = from.
size();
202 for ( J idx=0; idx<sz; idx++ )
211 template <
class T,
class I,
class S>
214 if ( &to == &from )
return;
221 template <
class T,
class I>
224 T tmp;
const I sz = ts.
size();
225 for ( I d=sz/2; d>0; d=d/2 )
226 for ( I i=d; i<sz; i++ )
227 for ( I j=i-d; j>=0 && ts[j]>ts[j+d]; j-=d )
228 { tmp = ts[j]; ts[j] = ts[j+d]; ts[j+d] = tmp; }
233 template <
class T,
class I>
inline 237 template <
class T,
class I>
inline 239 { setSize( nr, typ ); }
241 template <
class T,
class I>
inline 245 template <
class T,
class I>
inline 250 template <
class T,
class I>
inline 253 template <
class T,
class I>
inline 255 {
return vec_.size(); }
257 template <
class T,
class I>
inline 259 {
return vec_.setSize( sz, val ); }
261 template <
class T,
class I>
inline 263 {
return vec_.getCapacity(); }
265 template <
class T,
class I>
inline 267 {
return vec_.setCapacity( sz, withmargin ); }
269 template <
class T,
class I>
inline 271 {
vec_.fillWith( val ); }
273 template <
class T,
class I>
inline 275 {
vec_.replace( val, newval ); }
278 template <
class T,
class I>
inline 280 {
return vec_.validIdx( (I)idx ); }
282 template <
class T,
class I>
inline 284 {
return vec_[idx]; }
286 template <
class T,
class I>
inline 288 {
return vec_[idx]; }
290 template <
class T,
class I>
inline 292 {
return vec_.first(); }
294 template <
class T,
class I>
inline 296 {
return vec_.first(); }
298 template <
class T,
class I>
inline 300 {
return vec_.last(); }
302 template <
class T,
class I>
inline 304 {
return vec_.last(); }
306 template <
class T,
class I>
inline 308 {
return vec_.pop_back(); }
310 template <
class T,
class I>
inline 312 {
return vec_.indexOf( typ, forward, start ); }
314 template <
class T,
class I>
inline 316 {
return vec_.isPresent(t); }
318 template <
class T,
class I>
inline 320 {
return vec_.count( typ ); }
322 template <
class T,
class I>
inline 324 {
vec_.push_back( typ );
return *
this; }
326 template <
class T,
class I>
inline 328 {
return vec_.push_back( typ ); }
330 template <
class T,
class I>
inline 332 {
vec_.erase( typ );
return *
this; }
334 template <
class T,
class I>
inline 336 {
return this == &ts ? *
this :
copy( ts.
arr(), ts.
size() ); }
338 template <
class T,
class I>
inline 342 template <
class T,
class I>
inline 344 {
vec_.remove( i1, i2 ); }
346 template <
class T,
class I>
inline 348 {
vec_.insert( idx, typ );}
350 template <
class T,
class I>
inline 352 {
return vec_.vec(); }
354 template <
class T,
class I>
inline 356 {
return vec_.vec(); }
358 template <
class T,
class I>
inline 360 {
return size()>0 ?
const_cast<T*
>(&(*this)[0]) : 0; }
363 template <
class T,
class I>
inline 369 T tmp =
vec_[(I)idx0];
375 template <
class T,
class I>
inline 381 T tmp =
vec_[idxfrom];
383 vec_.remove( idxfrom < idxto ? idxfrom : idxfrom+1 );
387 template <
class T,
class I>
inline 391 if ( !idxs || sz < 2 )
401 template <
class T,
class I>
inline 406 for ( I idx=0; idx<hsz; idx++ )
407 swap( idx, sz-1-idx );
411 template <
class T,
class I>
inline 418 for ( I idx=0; idx<sz; idx++ )
419 (*
this)[idx] = tarr[idx];
425 template <
class T,
class I>
inline 436 template <
class T,
class I>
inline 439 if ( !sz )
return true;
444 for ( I idx=0; idx<sz; idx++ )
451 template <
class T,
class I>
454 const I sz = ts.
size();
455 const T* ptr = ts.
arr();
456 for ( I idx=0; idx<sz; idx++, ptr++ )
461 template <
class T,
class I>
464 for ( I idx=0; idx<
size(); idx++ )
473 template <
class T,
class I>
477 const I sz = ts.
size();
478 for ( I idx=0; idx<sz; idx++ )
480 const T typ = ts[idx];
481 for ( I idy=0; idy<
size(); idy++ )
483 if (
vec_[idy] == typ )
490 template <
class T,
class I>
inline 494 { *
this += typ;
return true; }
499 template <
class T,
class I>
inline 506 const I lastidx =
size()-1;
507 if ( idx != lastidx )
509 vec_.remove( lastidx );
Needed because the std lib has a crazy specialisation vector<bool>.
Definition: typeset.h:142
virtual void insert(size_type, const T &)
Definition: typeset.h:347
bool operator!=(const TypeSetBase< T, I > &a, const TypeSetBase< T, I > &b)
Definition: typeset.h:192
virtual void swap(int64_t, int64_t)
Definition: typeset.h:364
BoolTypeSetType(bool v=false)
Definition: typeset.h:146
Large Value Vector.
Definition: typeset.h:163
TypeSetBase< T, I > & operator-=(const T &)
Definition: typeset.h:331
T to(const F &fr)
Definition: convert.h:33
char val_
Definition: typeset.h:153
TypeSet()
Definition: typeset.h:128
virtual void createUnion(const TypeSetBase< T, I > &)
Definition: typeset.h:452
bool operator==(const TypeSetBase< T, I > &a, const TypeSetBase< T, I > &b)
Definition: typeset.h:180
std::vector< T > & vec()
Definition: typeset.h:351
#define od_int64
Definition: plftypes.h:36
virtual ~TypeSetBase()
Definition: typeset.h:251
TypeSetBase< T, I > & add(const T &)
Definition: typeset.h:323
virtual void createIntersection(const TypeSetBase< T, I > &)
Only keeps common items.
Definition: typeset.h:462
T object_type
Definition: typeset.h:31
TypeSet(int nr, T typ)
Definition: typeset.h:130
virtual bool setCapacity(size_type sz, bool withmargin)
Definition: typeset.h:266
virtual size_type getCapacity() const
Definition: typeset.h:262
ObjectSet< T >::size_type indexOf(const ObjectSet< T > &os, const S &val)
Locate object in set.
Definition: objectset.h:169
virtual void createDifference(const TypeSetBase< T, I > &, bool must_preserve_order=false)
Removes all items present in other set.
Definition: typeset.h:474
Base class for TypeSet, usually not used as such.
Definition: typeset.h:26
Simple vector-based container simplifying index-based work.
Definition: vectoraccess.h:38
virtual T * arr()
3rd party access
Definition: typeset.h:92
bool append(TypeSetBase< T, I > &to, const TypeSetBase< S, J > &from)
append allowing a different type to be merged into set
Definition: typeset.h:198
virtual T * gtArr() const
Definition: typeset.h:359
I size_type
Definition: typeset.h:30
Set of (small) copyable elements.
Definition: commontypes.h:30
virtual void reverse()
Definition: typeset.h:402
virtual bool addIfNew(const T &)
Definition: typeset.h:491
void sort(TypeSetBase< T, I > &ts)
Sort TypeSetBase. Must have operator > defined for elements.
Definition: typeset.h:222
LargeValVec(const TypeSet< T > &t)
Definition: typeset.h:173
virtual const T * arr() const
Definition: typeset.h:93
virtual void move(size_type from, size_type to)
Definition: typeset.h:376
TypeSetBase< T, I > & operator+=(const T &t)
Definition: typeset.h:63
LargeValVec(int64_t nr, T typ)
Definition: typeset.h:169
T & last()
Definition: typeset.h:299
T pop()
Definition: typeset.h:307
VectorAccess< T, I > vec_
Definition: typeset.h:104
void removeRange(ODSET &inst, size_type start, size_type stop)
Removes a range from the set.
Definition: odset.h:57
size_type count(const T &) const
Definition: typeset.h:319
virtual bool append(const T *, size_type)
Definition: typeset.h:437
bool push(const T &)
Definition: typeset.h:327
bool isPresent(const T &) const
Definition: typeset.h:315
TypeSet< BoolTypeSetType > BoolTypeSet
Definition: typeset.h:157
size_type size() const
Definition: typeset.h:254
virtual int64_t nrItems() const
Definition: typeset.h:38
virtual void erase()
Definition: typeset.h:339
virtual void getReOrdered(const size_type *, TypeSetBase< T, I > &)
Fills as per the given array of indexes.
Definition: typeset.h:388
OpendTect.
Definition: commontypes.h:29
TypeSet(const TypeSet< T > &t)
Definition: typeset.h:134
virtual bool setSize(size_type, T val=T())
Definition: typeset.h:258
LargeValVec(const T *t, int64_t nr)
Definition: typeset.h:171
void copy(TypeSetBase< T, I > &to, const TypeSetBase< S, I > &from)
Definition: typeset.h:212
void setAll(T)
Definition: typeset.h:270
virtual void removeSingle(size_type, bool preserver_order=true)
Definition: typeset.h:500
#define mClass(module)
Definition: commondefs.h:164
bool operator=(bool v)
Definition: typeset.h:149
virtual TypeSetBase< T, I > & copy(const T *, size_type)
Definition: typeset.h:412
virtual size_type indexOf(T, bool forward=true, size_type start=-1) const
Definition: typeset.h:311
virtual bool validIdx(int64_t) const
Definition: typeset.h:279
T & first()
Definition: typeset.h:291
TypeSetBase()
Definition: typeset.h:234
TypeSet(const T *t, int nr)
Definition: typeset.h:132
virtual void removeRange(size_type from, size_type to)
Definition: typeset.h:343
T & operator[](size_type)
Definition: typeset.h:283
void replace(T, T)
Definition: typeset.h:274
LargeValVec()
Definition: typeset.h:167