/usr/include/deal.II/base/vector_slice.h is in libdeal.ii-dev 6.3.1-1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | //---------------------------------------------------------------------------
// $Id: vector_slice.h 14038 2006-10-23 02:46:34Z bangerth $
// Version: $Name$
//
// Copyright (C) 2004, 2005, 2006 by the deal.II authors
//
// This file is subject to QPL and may not be distributed
// without copyright and license information. Please refer
// to the file deal.II/doc/license.html for the text and
// further information on this license.
//
//---------------------------------------------------------------------------
#ifndef __deal2__vector_slice_h
#define __deal2__vector_slice_h
#include <base/config.h>
#include <base/exceptions.h>
DEAL_II_NAMESPACE_OPEN
/**
* Filter a range out of any object having a random access <tt>operator[]
* (unsigned int)</tt> and a function <tt>size() const</tt>.
*
* The use of this object is straightforward. It reduplicates the
* random access operator of the <tt>VECTOR</tt> and adds an offset to
* every index.
*
* Some precautions have to be taken if it is used for a constant
* vector: the VectorSlice object has to be constant, too. The
* appropriate initalization sequence is like this:
*
* @code
* void f(const std::vector<int>& v)
* {
* const VectorSlice<const std::vector<int> > slice(v,...);
* ...
* }
* @endcode
*
* @ingroup data
* @author Guido Kanschat, 2004
*/
template <class VECTOR>
class VectorSlice
{
public:
/**
* Construct a vector slice
* containing the whole
* vector. Comes handy, if you
* did not want to have a slice
* at all, but the function you
* call wants it: just put in the
* vector itself as argument and
* let this constructor make a
* slice for you.
*/
VectorSlice(VECTOR& v);
/**
* The real constructor for a
* vector slice, allowing you to
* specify the start index and
* the length of the slice.
*/
VectorSlice(VECTOR& v,
unsigned int start,
unsigned int length);
/**
* Return the length of the slice
* using the same interface as
* <tt>std::vector</tt>.
*/
unsigned int size() const;
/**
* Access an element of the slice
* using the same interface as
* <tt>std::vector</tt>.
*/
typename VECTOR::reference operator[] (unsigned int i);
/**
* Access an element of a
* constant slice using the same
* interface as
* <tt>std::vector</tt>.
*/
typename VECTOR::const_reference operator[] (unsigned int i) const;
/**
* STL conforming iterator function.
*/
typename VECTOR::iterator begin();
/**
* STL conforming iterator function.
*/
typename VECTOR::const_iterator begin() const;
/**
* STL conforming iterator function.
*/
typename VECTOR::iterator end();
/**
* STL conforming iterator function.
*/
typename VECTOR::const_iterator end() const;
private:
/**
* The vector we extract from.
*/
VECTOR& v;
/**
* The start index of the slice.
*/
const unsigned int start;
/**
* The length of the slice.
*/
const unsigned int length;
};
/**
* Helper function for creating temporary objects without typing
* template arguments.
*
* @relates VectorSlice
* @author Guido Kanschat, 2004
*/
template <class VECTOR>
inline
const VectorSlice<const VECTOR>
make_slice (VECTOR& v)
{
const VectorSlice<const VECTOR> r(v);
return r;
}
/**
* Helper function for creating temporary objects without typing
* template arguments.
*
* @relates VectorSlice
* @author Guido Kanschat, 2004
*/
template <class VECTOR>
inline
const VectorSlice<const VECTOR>
make_slice (VECTOR& v, unsigned int start, unsigned int length)
{
const VectorSlice<const VECTOR> r(v, start, length);
return r;
}
//---------------------------------------------------------------------------
template <class VECTOR>
inline
VectorSlice<VECTOR>::VectorSlice(VECTOR& v)
: v(v), start(0), length(v.size())
{}
template <class VECTOR>
inline
VectorSlice<VECTOR>::VectorSlice(VECTOR& v,
unsigned int start,
unsigned int length)
: v(v), start(start), length(length)
{
Assert((start+length<=v.size()),
ExcIndexRange(length, 0, v.size()-start+1));
}
template <class VECTOR>
inline
unsigned int
VectorSlice<VECTOR>::size() const
{
return length;
}
template <class VECTOR>
inline
typename VECTOR::reference
VectorSlice<VECTOR>::operator[](unsigned int i)
{
Assert ((i<length), ExcIndexRange(i, 0, length));
return v[start+i];
}
template <class VECTOR>
inline
typename VECTOR::const_reference
VectorSlice<VECTOR>::operator[](unsigned int i) const
{
Assert ((i<length), ExcIndexRange(i, 0, length));
return v[start+i];
}
template <class VECTOR>
inline
typename VECTOR::const_iterator
VectorSlice<VECTOR>::begin() const
{
return v.begin()+start;
}
template <class VECTOR>
inline
typename VECTOR::iterator
VectorSlice<VECTOR>::begin()
{
return v.begin()+start;
}
template <class VECTOR>
inline
typename VECTOR::const_iterator
VectorSlice<VECTOR>::end() const
{
return v.begin()+start+length;
}
template <class VECTOR>
inline
typename VECTOR::iterator
VectorSlice<VECTOR>::end()
{
return v.begin()+start+length;
}
DEAL_II_NAMESPACE_CLOSE
#endif
|