core
vnl
vnl_vector_ref.h
Go to the documentation of this file.
1
// This is core/vnl/vnl_vector_ref.h
2
#ifndef vnl_vector_ref_h_
3
#define vnl_vector_ref_h_
4
//:
5
// \file
6
// \brief vnl_vector using user-supplied storage
7
// \author Andrew W. Fitzgibbon, Oxford RRG
8
// \date 04 Aug 96
9
//
10
// \verbatim
11
// Modifications
12
// LSB (Manchester) 19/03/2001: Tidied up the documentation
13
// Peter Vanroose 27-Jun-2003 Removed .hxx as all methods are inlined
14
// \endverbatim
15
//-----------------------------------------------------------------------------
16
17
#include <
vnl/vnl_vector.h
>
18
#include "vnl/vnl_export.h"
19
20
//: vnl_vector using user-supplied storage
21
// vnl_vector for which the data space has
22
// been supplied externally.
23
template
<
class
T>
24
class
VNL_EXPORT
vnl_vector_ref
:
public
vnl_vector
<T>
25
{
26
public
:
27
using
Base
=
vnl_vector<T>
;
28
29
//: Constructor
30
// Do \e not call anything else than the default constructor of vnl_vector<T>
31
vnl_vector_ref
(
unsigned
n, T *space);
32
33
//: Copy constructor
34
// Do \e not call anything else than the default constructor of vnl_vector<T>
35
// (That is why the default copy constructor is \e not good.)
36
vnl_vector_ref
(
vnl_vector_ref<T>
const
&
v
);
37
38
//: Destructor
39
// Prevents base destructor from releasing memory we don't own
40
~
vnl_vector_ref
();
41
42
//: Reference to self to make non-const temporaries.
43
// This is intended for passing vnl_vector_fixed objects to
44
// functions that expect non-const vnl_vector references:
45
// \code
46
// void mutator( vnl_vector<double>& );
47
// ...
48
// vnl_vector_fixed<double,4> my_v;
49
// mutator( v ); // Both these fail because the temporary vnl_vector_ref
50
// mutator( v.as_ref() ); // cannot be bound to the non-const reference
51
// mutator( v.as_ref().non_const() ); // works
52
// \endcode
53
// \attention Use this only to pass the reference to a
54
// function. Otherwise, the underlying object will be destructed and
55
// you'll be left with undefined behaviour.
56
vnl_vector_ref
& non_const();
57
58
//: Copy and move constructor from vnl_vector<T> is disallowed:
59
vnl_vector_ref
(
vnl_vector<T>
const
&) =
delete
;
60
vnl_vector_ref
(
vnl_vector<T>
&& ) =
delete
;
61
};
62
63
//: Create a reference vector with part of an existing vector.
64
template
<
class
T>
65
inline
const
vnl_vector_ref<T>
vnl_vector_ref_extract
(
const
vnl_vector <T>
&
v
,
unsigned
start,
unsigned
len)
66
{
67
return
vnl_vector_ref<T>
(len, const_cast<T *>(
v
.data_block()+start));
68
}
69
70
//: Create a reference vector with part of an existing vector.
71
template
<
class
T>
72
inline
vnl_vector_ref<T>
vnl_vector_ref_extract
(
vnl_vector <T>
&
v
,
unsigned
start,
unsigned
len)
73
{
74
return
vnl_vector_ref<T>
(len,
v
.data_block()+start);
75
}
76
77
78
#endif // vnl_vector_ref_h_
vnl_vector_ref_extract
const vnl_vector_ref< T > vnl_vector_ref_extract(const vnl_vector< T > &v, unsigned start, unsigned len)
Create a reference vector with part of an existing vector.
Definition:
vnl_vector_ref.h:64
vnl_vector_ref
vnl_vector using user-supplied storage.
Definition:
vnl_fwd.h:17
v
#define v
Definition:
vnl_vector.h:42
vnl_vector.h
vnl_vector
Mathematical vector class, templated by type of element.
Definition:
vnl_fwd.h:16
Generated by
1.8.15