Vector.h
Go to the documentation of this file.
#ifndef _RHEO_VECTOR_H
#define _RHEO_VECTOR_H
/*Class:csr
NAME: @code{Vector} - STL @code{vector<T>} with reference counting
@clindex Vector
DESCRIPTION:
@noindent
The class implement a reference counting wrapper for
the STL @code{vector<T>} container class, with shallow copies.
See also:
@emph{The standard template library}, by Alexander Stephanov and Meng Lee.
@noindent
This class provides the full @code{vector<T>}
interface specification
an could be used instead of @code{vector<T>}.
NOTE:
@noindent
The write accessors
@example
T& operator[](size_type)
@end example
@noindent
as in @code{v[i]}
may checks the reference count for each access.
For a loop, a better usage is:
@example
Vector<T>::iterator i = v.begin();
Vector<T>::iterator last = v.end();
while (i != last) @{ ...@}
@end example
@noindent
and the reference count check step occurs only two time,
when accessing via @code{begin()} and @code{end()}.
@noindent
Thus, in order to encourage users to do it, we declare private
theses member functions. A synonym of @code{operator[]} is @code{at}.
AUTHOR:
Pierre Saramito
| Pierre.Saramito@imag.fr
LMC-IMAG, 38041 Grenoble cedex 9, France
DATE: 14 september 1997
End:
*/
/*
//<Vector:
template<class T>
class Vector : private smart_pointer<vector_rep<T> > {
public:
// typedefs:
typedef iterator;
typedef const_iterator;
typedef pointer;
typedef reference;
typedef const_reference;
typedef size_type;
typedef difference_type;
typedef value_type;
typedef reverse_iterator;
typedef const_reverse_iterator;
// allocation/deallocation:
explicit Vector (size_type n = 0, const T& value = T ());
Vector (const_iterator first, const_iterator last);
void reserve (size_type n);
void swap (Vector<T>& x) ;
// accessors:
iterator begin ();
const_iterator begin () const;
iterator end ();
const_iterator end () const;
reverse_iterator rbegin();
const_reverse_iterator rbegin() const;
reverse_iterator rend();
const_reverse_iterator rend() const;
size_type size () const;
size_type max_size () const;
size_type capacity () const;
bool empty () const;
void resize (size_type sz, T v = T ()); // non-standard ?
private:
const_reference operator[] (size_type n) const;
reference operator[] (size_type n);
public:
const_reference at (size_type n) const; // non-standard ?
reference at (size_type n);
reference front ();
const_reference front () const;
reference back ();
const_reference back () const;
// insert/erase:
void push_back (const T& x);
iterator insert (iterator position, const T& x = T ());
void insert (iterator position, size_type n, const T& x);
void insert (iterator position, const_iterator first, const_iterator last);
void pop_back ();
void erase (iterator position);
void erase (iterator first, iterator last);
};
//>Vector:
*/
#include "rheolef/compiler.h"
#include "rheolef/smart_pointer.h"
namespace rheolef {
template<class T>
struct vector_rep : public std::vector<T> {
// typedefs:
typedef std::vector<T> DATA;
typedef typename DATA::iterator iterator;
typedef typename DATA::const_iterator const_iterator;
typedef typename DATA::pointer pointer;
typedef typename DATA::reference reference;
typedef typename DATA::const_reference const_reference;
typedef typename DATA::size_type size_type;
typedef typename DATA::difference_type difference_type;
typedef T value_type;
typedef typename DATA::reverse_iterator reverse_iterator;
typedef typename DATA::const_reverse_iterator const_reverse_iterator;
// allocators/deallocators:
vector_rep (const vector_rep& x)
: std::vector<T>(x)
{}
explicit
vector_rep (size_type n = 0, const T& value = T ())
: std::vector<T>(n,value)
{}
#ifdef TODO
vector_rep (const_iterator first, const_iterator last)
: std::vector<T>(first,last)
{}
#endif // TODO
};
template<class T>
struct Vector : smart_pointer<vector_rep<T> >
{
typedef vector_rep<T> DATA;
public:
// typedefs:
typedef typename DATA::iterator iterator;
typedef typename DATA::const_iterator const_iterator;
typedef typename DATA::pointer pointer;
typedef typename DATA::reference reference;
typedef typename DATA::const_reference const_reference;
typedef typename DATA::size_type size_type;
typedef typename DATA::difference_type difference_type;
typedef T value_type;
typedef typename DATA::reverse_iterator reverse_iterator;
typedef typename DATA::const_reverse_iterator const_reverse_iterator;
// allocation/deallocation:
explicit
Vector (size_type n = 0, const T& value = T ())
: smart_pointer<DATA>(new_macro(DATA(n,value)))
{}
#ifdef TODO
Vector (const_iterator first, const_iterator last)
: smart_pointer<DATA>(new_macro(DATA(first,last)))
{}
#endif // TODO
void reserve (size_type n)
{
smart_pointer<vector_rep<T> >::data().reserve(n);
}
void swap (Vector<T>& x)
{
smart_pointer<vector_rep<T> >::data().swap(*x.p);
}
// accessors:
iterator begin ()
{
return smart_pointer<vector_rep<T> >::data().begin();
}
const_iterator begin () const
{
return smart_pointer<vector_rep<T> >::data().begin();
}
iterator end ()
{
return smart_pointer<vector_rep<T> >::data().end();
}
const_iterator end () const
{
return smart_pointer<vector_rep<T> >::data().end();
}
reverse_iterator rbegin()
{
return reverse_iterator(smart_pointer<vector_rep<T> >::data().end());
}
const_reverse_iterator rbegin() const
{
return const_reverse_iterator(smart_pointer<vector_rep<T> >::data().end());
}
reverse_iterator rend()
{
return reverse_iterator(smart_pointer<vector_rep<T> >::data().begin());
}
const_reverse_iterator rend() const
{
return const_reverse_iterator(smart_pointer<vector_rep<T> >::data().begin());
}
size_type size () const
{
return smart_pointer<vector_rep<T> >::data().size();
}
size_type max_size () const
{
return smart_pointer<vector_rep<T> >::data().max_size ();
}
size_type capacity () const
{
return smart_pointer<vector_rep<T> >::data().capacity ();
}
bool empty () const
{
return smart_pointer<vector_rep<T> >::data().empty();
}
// non-standatd ?
void resize (size_type sz, T v = T ())
{
if (sz > (smart_pointer<vector_rep<T> >::data().size ())) {
smart_pointer<vector_rep<T> >::data().insert (smart_pointer<vector_rep<T> >::data().end(), sz- (smart_pointer<vector_rep<T> >::data().size ()), v);
} else if (sz < (smart_pointer<vector_rep<T> >::data().size())) {
smart_pointer<vector_rep<T> >::data().erase (smart_pointer<vector_rep<T> >::data().begin()+sz, smart_pointer<vector_rep<T> >::data().end());
}
}
const_reference operator[] (size_type n) const
{
return smart_pointer<vector_rep<T> >::data().operator[] (n);
}
reference operator[] (size_type n)
{
return smart_pointer<vector_rep<T> >::data().operator[] (n);
}
public:
const_reference at (size_type n) const
{
return smart_pointer<vector_rep<T> >::data().operator[] (n);
}
reference at (size_type n)
{
return smart_pointer<vector_rep<T> >::data().operator[] (n);
}
reference front ()
{
return smart_pointer<vector_rep<T> >::data().front();
}
const_reference front () const
{
return smart_pointer<vector_rep<T> >::data().front();
}
reference back ()
{
return smart_pointer<vector_rep<T> >::data().back();
}
const_reference back () const
{
return smart_pointer<vector_rep<T> >::data().back();
}
// insert/erase:
void push_back (const T& x)
{
smart_pointer<vector_rep<T> >::data().push_back(x);
}
iterator insert (iterator position, const T& x = T ())
{
return smart_pointer<vector_rep<T> >::data().insert(position,x);
}
void insert (iterator position, size_type n, const T& x)
{
smart_pointer<vector_rep<T> >::data().insert(position,n,x);
}
#ifdef TODO
void insert (iterator position, const_iterator first, const_iterator last)
{
smart_pointer<vector_rep<T> >::data().insert(position,first,last);
}
#endif // TODO
void pop_back ()
{
smart_pointer<vector_rep<T> >::data().pop_back();
}
void erase (iterator position)
{
smart_pointer<vector_rep<T> >::data().erase(position);
}
void erase (iterator first, iterator last)
{
smart_pointer<vector_rep<T> >::data().erase(first,last);
}
};
template<class IteratorValue, class ConstIteratorValue>
struct VectorOfIterators : Vector<IteratorValue>
{
typedef Vector<IteratorValue> V;
typedef Vector<ConstIteratorValue> CONST_V;
typedef IteratorValue value_type;
typedef ConstIteratorValue const_value_type;
typedef typename V::iterator iterator;
typedef typename CONST_V::const_iterator const_iterator;
typedef typename V::pointer pointer;
typedef typename V::reference reference;
typedef typename CONST_V::const_reference const_reference;
typedef typename V::size_type size_type;
typedef typename V::difference_type difference_type;
typedef typename V::reverse_iterator reverse_iterator;
typedef typename CONST_V::const_reverse_iterator const_reverse_iterator;
explicit
VectorOfIterators (size_type n, const IteratorValue& value = IteratorValue ())
: V(n,value)
{}
#ifdef TODO
VectorOfIterators (const_iterator first, const_iterator last)
: V(first,last)
{}
#endif // TODO
iterator begin()
{
return Vector<IteratorValue>::data().begin();
}
const_iterator begin() const
{
return const_iterator (Vector<IteratorValue>::data().begin());
}
const_iterator end () const
{
return const_iterator (Vector<IteratorValue>::data().end());
}
iterator end ()
{
return Vector<IteratorValue>::data().end();
}
const_reverse_iterator rbegin() const
{
return const_reverse_iterator(Vector<IteratorValue>::data().end());
}
reverse_iterator rbegin()
{
return reverse_iterator(Vector<IteratorValue>::data().end());
}
const_reverse_iterator rend() const
{
return const_reverse_iterator(Vector<IteratorValue>::data().begin());
}
reverse_iterator rend()
{
return reverse_iterator(Vector<IteratorValue>::data().begin());
}
private:
const_reference operator[] (size_type n) const
{
return const_reference(Vector<IteratorValue>::data().operator[] (n));
}
reference operator[] (size_type n)
{
return reference(Vector<IteratorValue>::data().operator[] (n));
}
public:
const_reference at (size_type n) const
{
return const_reference(Vector<IteratorValue>::data().operator[] (n));
}
reference at (size_type n)
{
return Vector<IteratorValue>::data().operator[] (n);
}
const_reference front () const
{
return const_reference(Vector<IteratorValue>::data().front());
}
reference front ()
{
return Vector<IteratorValue>::data().front();
}
const_reference back () const
{
return const_reference(Vector<IteratorValue>::data().back());
}
reference back ()
{
return Vector<IteratorValue>::data().back();
}
};
}// namespace rheolef
#endif /* _RHEO_VECTOR_H */
size_type
field::size_type size_type
Definition: branch.cc:425
rheolef::smart_pointer_base::data
const T & data() const
Definition: smart_pointer.h:266
rheolef::smart_pointer
see the smart_pointer page for the full documentation
Definition: smart_pointer.h:351
rheolef::std
Definition: vec_expr_v2.h:402
rheolef::value
rheolef::std value
T
Expr1::float_type T
Definition: field_expr.h:261
mkgeo_ball.n
int n
Definition: mkgeo_ball.sh:150
rheolef::space_constant::vector
@ vector
Definition: space_constant.h:137
rheolef
This file is part of Rheolef.
Definition: compiler_eigen.h:37
rheolef::VectorOfIterators
Definition: Vector.h:342
rheolef::VectorOfIterators::const_value_type
ConstIteratorValue const_value_type
Definition: Vector.h:347
rheolef::VectorOfIterators::rend
const_reverse_iterator rend() const
Definition: Vector.h:394
rheolef::VectorOfIterators::front
const_reference front() const
Definition: Vector.h:420
rheolef::VectorOfIterators::pointer
V::pointer pointer
Definition: Vector.h:351
rheolef::VectorOfIterators::CONST_V
Vector< ConstIteratorValue > CONST_V
Definition: Vector.h:344
rheolef::VectorOfIterators::const_reference
CONST_V::const_reference const_reference
Definition: Vector.h:353
rheolef::VectorOfIterators::difference_type
V::difference_type difference_type
Definition: Vector.h:355
rheolef::VectorOfIterators::begin
const_iterator begin() const
Definition: Vector.h:374
rheolef::VectorOfIterators::value_type
IteratorValue value_type
Definition: Vector.h:346
rheolef::VectorOfIterators::iterator
V::iterator iterator
Definition: Vector.h:349
rheolef::VectorOfIterators::V
Vector< IteratorValue > V
Definition: Vector.h:343
rheolef::VectorOfIterators::VectorOfIterators
VectorOfIterators(size_type n, const IteratorValue &value=IteratorValue())
Definition: Vector.h:360
rheolef::VectorOfIterators::back
const_reference back() const
Definition: Vector.h:428
rheolef::VectorOfIterators::rend
reverse_iterator rend()
Definition: Vector.h:398
rheolef::VectorOfIterators::front
reference front()
Definition: Vector.h:424
rheolef::VectorOfIterators::at
const_reference at(size_type n) const
Definition: Vector.h:412
rheolef::VectorOfIterators::VectorOfIterators
VectorOfIterators(const_iterator first, const_iterator last)
Definition: Vector.h:365
rheolef::VectorOfIterators::const_reverse_iterator
CONST_V::const_reverse_iterator const_reverse_iterator
Definition: Vector.h:357
rheolef::VectorOfIterators::end
iterator end()
Definition: Vector.h:382
rheolef::VectorOfIterators::end
const_iterator end() const
Definition: Vector.h:378
rheolef::VectorOfIterators::rbegin
reverse_iterator rbegin()
Definition: Vector.h:390
rheolef::VectorOfIterators::begin
iterator begin()
Definition: Vector.h:370
rheolef::VectorOfIterators::at
reference at(size_type n)
Definition: Vector.h:416
rheolef::VectorOfIterators::const_iterator
CONST_V::const_iterator const_iterator
Definition: Vector.h:350
rheolef::VectorOfIterators::reference
V::reference reference
Definition: Vector.h:352
rheolef::VectorOfIterators::rbegin
const_reverse_iterator rbegin() const
Definition: Vector.h:386
rheolef::VectorOfIterators::reverse_iterator
V::reverse_iterator reverse_iterator
Definition: Vector.h:356
rheolef::VectorOfIterators::size_type
V::size_type size_type
Definition: Vector.h:354
rheolef::VectorOfIterators::back
reference back()
Definition: Vector.h:432
rheolef::Vector
Definition: Vector.h:176
rheolef::Vector::pop_back
void pop_back()
Definition: Vector.h:327
rheolef::Vector::rend
const_reverse_iterator rend() const
Definition: Vector.h:245
rheolef::Vector::front
const_reference front() const
Definition: Vector.h:295
rheolef::Vector::const_reverse_iterator
DATA::const_reverse_iterator const_reverse_iterator
Definition: Vector.h:192
rheolef::Vector::value_type
T value_type
Definition: Vector.h:190
rheolef::Vector::reverse_iterator
DATA::reverse_iterator reverse_iterator
Definition: Vector.h:191
rheolef::Vector::begin
const_iterator begin() const
Definition: Vector.h:221
rheolef::Vector::erase
void erase(iterator first, iterator last)
Definition: Vector.h:335
rheolef::Vector::insert
iterator insert(iterator position, const T &x=T())
Definition: Vector.h:313
rheolef::Vector::reserve
void reserve(size_type n)
Definition: Vector.h:207
rheolef::Vector::size
size_type size() const
Definition: Vector.h:249
rheolef::Vector::back
const_reference back() const
Definition: Vector.h:303
rheolef::Vector::insert
void insert(iterator position, const_iterator first, const_iterator last)
Definition: Vector.h:322
rheolef::Vector::empty
bool empty() const
Definition: Vector.h:261
rheolef::Vector::Vector
Vector(size_type n=0, const T &value=T())
Definition: Vector.h:197
rheolef::Vector::difference_type
DATA::difference_type difference_type
Definition: Vector.h:189
rheolef::Vector::rend
reverse_iterator rend()
Definition: Vector.h:241
rheolef::Vector::front
reference front()
Definition: Vector.h:291
rheolef::Vector::pointer
DATA::pointer pointer
Definition: Vector.h:185
rheolef::Vector::push_back
void push_back(const T &x)
Definition: Vector.h:309
rheolef::Vector::size_type
DATA::size_type size_type
Definition: Vector.h:188
rheolef::Vector::iterator
DATA::iterator iterator
Definition: Vector.h:183
rheolef::Vector::const_iterator
DATA::const_iterator const_iterator
Definition: Vector.h:184
rheolef::Vector::Vector
Vector(const_iterator first, const_iterator last)
Definition: Vector.h:202
rheolef::Vector::max_size
size_type max_size() const
Definition: Vector.h:253
rheolef::Vector::at
const_reference at(size_type n) const
Definition: Vector.h:283
rheolef::Vector::insert
void insert(iterator position, size_type n, const T &x)
Definition: Vector.h:317
rheolef::Vector::operator[]
const_reference operator[](size_type n) const
Definition: Vector.h:274
rheolef::Vector::const_reference
DATA::const_reference const_reference
Definition: Vector.h:187
rheolef::Vector::resize
void resize(size_type sz, T v=T())
Definition: Vector.h:266
rheolef::Vector::swap
void swap(Vector< T > &x)
Definition: Vector.h:211
rheolef::Vector::end
iterator end()
Definition: Vector.h:225
rheolef::Vector::end
const_iterator end() const
Definition: Vector.h:229
rheolef::Vector::rbegin
reverse_iterator rbegin()
Definition: Vector.h:233
rheolef::Vector::capacity
size_type capacity() const
Definition: Vector.h:257
rheolef::Vector::begin
iterator begin()
Definition: Vector.h:217
rheolef::Vector::at
reference at(size_type n)
Definition: Vector.h:287
rheolef::Vector::reference
DATA::reference reference
Definition: Vector.h:186
rheolef::Vector::rbegin
const_reverse_iterator rbegin() const
Definition: Vector.h:237
rheolef::Vector::DATA
vector_rep< T > DATA
Definition: Vector.h:177
rheolef::Vector::back
reference back()
Definition: Vector.h:299
rheolef::Vector::erase
void erase(iterator position)
Definition: Vector.h:331
rheolef::vector_rep
Definition: Vector.h:140
rheolef::vector_rep::vector_rep
vector_rep(size_type n=0, const T &value=T())
Definition: Vector.h:163
rheolef::vector_rep::const_reverse_iterator
DATA::const_reverse_iterator const_reverse_iterator
Definition: Vector.h:154
rheolef::vector_rep::value_type
T value_type
Definition: Vector.h:152
rheolef::vector_rep::reverse_iterator
DATA::reverse_iterator reverse_iterator
Definition: Vector.h:153
rheolef::vector_rep::vector_rep
vector_rep(const_iterator first, const_iterator last)
Definition: Vector.h:168
rheolef::vector_rep::difference_type
DATA::difference_type difference_type
Definition: Vector.h:151
rheolef::vector_rep::pointer
DATA::pointer pointer
Definition: Vector.h:147
rheolef::vector_rep::size_type
DATA::size_type size_type
Definition: Vector.h:150
rheolef::vector_rep::iterator
DATA::iterator iterator
Definition: Vector.h:145
rheolef::vector_rep::const_iterator
DATA::const_iterator const_iterator
Definition: Vector.h:146
rheolef::vector_rep::DATA
std::vector< T > DATA
Definition: Vector.h:143
rheolef::vector_rep::const_reference
DATA::const_reference const_reference
Definition: Vector.h:149
rheolef::vector_rep::vector_rep
vector_rep(const vector_rep &x)
Definition: Vector.h:158
rheolef::vector_rep::reference
DATA::reference reference
Definition: Vector.h:148