1027 |
02 Feb 08 |
peter |
1 |
#ifndef _theplu_yat_utility_vector_const_view_ |
1027 |
02 Feb 08 |
peter |
2 |
#define _theplu_yat_utility_vector_const_view_ |
616 |
31 Aug 06 |
jari |
3 |
|
22 |
05 Aug 03 |
peter |
// $Id$ |
22 |
05 Aug 03 |
peter |
5 |
|
570 |
05 Apr 06 |
jari |
6 |
/* |
570 |
05 Apr 06 |
jari |
Copyright (C) 2003 Daniel Dalevi, Peter Johansson |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2004 Jari Häkkinen, Peter Johansson |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2005 Jari Häkkinen, Peter Johansson, Markus Ringnér |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2006 Jari Häkkinen |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2007 Jari Häkkinen, Peter Johansson, Markus Ringnér |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2008 Jari Häkkinen, Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2009, 2017, 2021, 2022 Peter Johansson |
570 |
05 Apr 06 |
jari |
14 |
|
1437 |
25 Aug 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/trac/yat |
570 |
05 Apr 06 |
jari |
16 |
|
675 |
10 Oct 06 |
jari |
The yat library is free software; you can redistribute it and/or |
675 |
10 Oct 06 |
jari |
modify it under the terms of the GNU General Public License as |
1486 |
09 Sep 08 |
jari |
published by the Free Software Foundation; either version 3 of the |
675 |
10 Oct 06 |
jari |
License, or (at your option) any later version. |
570 |
05 Apr 06 |
jari |
21 |
|
675 |
10 Oct 06 |
jari |
The yat library is distributed in the hope that it will be useful, |
675 |
10 Oct 06 |
jari |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
675 |
10 Oct 06 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
570 |
05 Apr 06 |
jari |
General Public License for more details. |
570 |
05 Apr 06 |
jari |
26 |
|
570 |
05 Apr 06 |
jari |
You should have received a copy of the GNU General Public License |
1487 |
10 Sep 08 |
jari |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
570 |
05 Apr 06 |
jari |
29 |
*/ |
570 |
05 Apr 06 |
jari |
30 |
|
1015 |
01 Feb 08 |
peter |
31 |
#include "VectorBase.h" |
420 |
02 Dec 05 |
jari |
32 |
|
12 |
19 Jun 03 |
daniel |
33 |
#include <gsl/gsl_vector.h> |
12 |
19 Jun 03 |
daniel |
34 |
|
42 |
26 Feb 04 |
jari |
35 |
namespace theplu { |
680 |
11 Oct 06 |
jari |
36 |
namespace yat { |
616 |
31 Aug 06 |
jari |
37 |
namespace utility { |
420 |
02 Dec 05 |
jari |
38 |
|
4119 |
07 Nov 21 |
peter |
39 |
class MatrixBase; |
3595 |
21 Jan 17 |
peter |
40 |
class VectorView; |
420 |
02 Dec 05 |
jari |
41 |
|
686 |
16 Oct 06 |
jari |
42 |
/** |
2687 |
27 Feb 12 |
peter |
@brief Read-only view. |
686 |
16 Oct 06 |
jari |
44 |
|
2687 |
27 Feb 12 |
peter |
Wrapper to gsl_vector_const_view |
767 |
22 Feb 07 |
peter |
46 |
|
1028 |
03 Feb 08 |
peter |
With this class you can create a view into const |
1028 |
03 Feb 08 |
peter |
objects - either a vector or matrix. By design all functionality |
1028 |
03 Feb 08 |
peter |
in this class is const to guarantee that the viewed object is not |
2687 |
27 Feb 12 |
peter |
modified. |
686 |
16 Oct 06 |
jari |
51 |
|
1125 |
22 Feb 08 |
peter |
\note that view vectors do not own the underlying data, |
1028 |
03 Feb 08 |
peter |
and a view is not valid if the vector/matrix owing the data is |
1028 |
03 Feb 08 |
peter |
deallocated. |
686 |
16 Oct 06 |
jari |
55 |
*/ |
1027 |
02 Feb 08 |
peter |
56 |
class VectorConstView : public VectorBase |
42 |
26 Feb 04 |
jari |
57 |
{ |
42 |
26 Feb 04 |
jari |
58 |
public: |
754 |
17 Feb 07 |
jari |
59 |
/** |
754 |
17 Feb 07 |
jari |
\brief The copy constructor. |
1028 |
03 Feb 08 |
peter |
61 |
*/ |
1028 |
03 Feb 08 |
peter |
// needed to override compiler generated copy constructor |
1028 |
03 Feb 08 |
peter |
63 |
VectorConstView(const VectorConstView& other); |
1028 |
03 Feb 08 |
peter |
64 |
|
1028 |
03 Feb 08 |
peter |
65 |
/** |
3595 |
21 Jan 17 |
peter |
\brief Copy a VectorView |
3595 |
21 Jan 17 |
peter |
67 |
|
3595 |
21 Jan 17 |
peter |
Conversion from VectorView to VectorConstView. Implicit |
3595 |
21 Jan 17 |
peter |
conversion is allowed. |
3595 |
21 Jan 17 |
peter |
70 |
|
4200 |
19 Aug 22 |
peter |
\since New in yat 0.15 |
3595 |
21 Jan 17 |
peter |
72 |
*/ |
3595 |
21 Jan 17 |
peter |
73 |
VectorConstView(const VectorView& other); |
3595 |
21 Jan 17 |
peter |
74 |
|
3595 |
21 Jan 17 |
peter |
75 |
/** |
1028 |
03 Feb 08 |
peter |
\brief Copy a VectorBase |
2687 |
27 Feb 12 |
peter |
77 |
*/ |
1651 |
15 Dec 08 |
peter |
78 |
explicit VectorConstView(const VectorBase& other); |
12 |
19 Jun 03 |
daniel |
79 |
|
754 |
17 Feb 07 |
jari |
80 |
/** |
1028 |
03 Feb 08 |
peter |
\brief const view into a vector |
754 |
17 Feb 07 |
jari |
82 |
|
1028 |
03 Feb 08 |
peter |
Create a const view of VectorBase \a v, with starting index \a offset, |
754 |
17 Feb 07 |
jari |
size \a n, and an optional \a stride. |
754 |
17 Feb 07 |
jari |
85 |
|
754 |
17 Feb 07 |
jari |
\note If the object viewed by the view goes out of scope or is |
754 |
17 Feb 07 |
jari |
deleted, the view becomes invalid and the result of further use |
754 |
17 Feb 07 |
jari |
is undefined. |
754 |
17 Feb 07 |
jari |
89 |
|
754 |
17 Feb 07 |
jari |
\throw GSL_error if a view cannot be set up. |
754 |
17 Feb 07 |
jari |
91 |
*/ |
1027 |
02 Feb 08 |
peter |
92 |
VectorConstView(const VectorBase& v,size_t offset,size_t n,size_t stride=1); |
257 |
04 Mar 05 |
jari |
93 |
|
1028 |
03 Feb 08 |
peter |
94 |
/** |
1028 |
03 Feb 08 |
peter |
\brief Matrix row/column view constructor. |
1028 |
03 Feb 08 |
peter |
96 |
|
2687 |
27 Feb 12 |
peter |
Create a view into a row/column of a matrix. |
2687 |
27 Feb 12 |
peter |
98 |
|
1028 |
03 Feb 08 |
peter |
\param m matrix to view into. |
1028 |
03 Feb 08 |
peter |
\param i index telling which row/column to view into |
1028 |
03 Feb 08 |
peter |
\param row if true (defult) created view is a row vector, i.e., |
1028 |
03 Feb 08 |
peter |
viewing into row \a i, and, naturally, a column vector |
1028 |
03 Feb 08 |
peter |
otherwise. |
1028 |
03 Feb 08 |
peter |
104 |
|
1028 |
03 Feb 08 |
peter |
\see matrix::column_const_view(size_t) and |
1028 |
03 Feb 08 |
peter |
matrix::row_const_view(size_t) |
1028 |
03 Feb 08 |
peter |
107 |
|
1028 |
03 Feb 08 |
peter |
@note If the object viewed by the view goes out of scope or is |
1028 |
03 Feb 08 |
peter |
deleted, the view becomes invalid and the result of further |
1028 |
03 Feb 08 |
peter |
use is undefined. |
1028 |
03 Feb 08 |
peter |
111 |
*/ |
4119 |
07 Nov 21 |
peter |
112 |
VectorConstView(const MatrixBase& m, size_t i, bool row=true); |
420 |
02 Dec 05 |
jari |
113 |
|
1028 |
03 Feb 08 |
peter |
114 |
/** |
4141 |
01 Feb 22 |
peter |
Create a view into \c v |
4141 |
01 Feb 22 |
peter |
116 |
|
4141 |
01 Feb 22 |
peter |
\since New in yat 0.20 |
4141 |
01 Feb 22 |
peter |
118 |
*/ |
4141 |
01 Feb 22 |
peter |
119 |
explicit VectorConstView(const gsl_vector* v); |
4141 |
01 Feb 22 |
peter |
120 |
|
4141 |
01 Feb 22 |
peter |
121 |
/** |
4141 |
01 Feb 22 |
peter |
Create a view with size \c size and stride \c stride such that |
4141 |
01 Feb 22 |
peter |
view(0) = v[0] and view(1) = v[stride]. |
4141 |
01 Feb 22 |
peter |
124 |
|
4141 |
01 Feb 22 |
peter |
\since New in yat 0.20 |
4141 |
01 Feb 22 |
peter |
126 |
*/ |
4141 |
01 Feb 22 |
peter |
127 |
VectorConstView(const double* v, size_t size, size_t stride=1); |
4141 |
01 Feb 22 |
peter |
128 |
|
4141 |
01 Feb 22 |
peter |
129 |
/** |
1028 |
03 Feb 08 |
peter |
The destructor. |
1028 |
03 Feb 08 |
peter |
131 |
*/ |
1027 |
02 Feb 08 |
peter |
132 |
~VectorConstView(void); |
12 |
19 Jun 03 |
daniel |
133 |
|
754 |
17 Feb 07 |
jari |
134 |
/** |
1008 |
01 Feb 08 |
peter |
\return true |
1008 |
01 Feb 08 |
peter |
136 |
*/ |
2687 |
27 Feb 12 |
peter |
137 |
bool isview(void) const; |
1008 |
01 Feb 08 |
peter |
138 |
|
420 |
02 Dec 05 |
jari |
139 |
private: |
1710 |
13 Jan 09 |
peter |
140 |
void copy(const VectorBase& other); |
1008 |
01 Feb 08 |
peter |
141 |
void delete_allocated_memory(void); |
12 |
19 Jun 03 |
daniel |
142 |
|
1028 |
03 Feb 08 |
peter |
// Perhaps not needed - only used to create a gsl_vector (that is |
1028 |
03 Feb 08 |
peter |
// stored in base class). For data access use data in base class |
1028 |
03 Feb 08 |
peter |
// because this pointer may be NULL. |
1008 |
01 Feb 08 |
peter |
146 |
gsl_vector_const_view* const_view_; |
2687 |
27 Feb 12 |
peter |
147 |
|
1615 |
05 Nov 08 |
peter |
// assignment not allowed |
1615 |
05 Nov 08 |
peter |
149 |
VectorConstView& operator=(const VectorConstView&); |
420 |
02 Dec 05 |
jari |
150 |
}; |
12 |
19 Jun 03 |
daniel |
151 |
|
686 |
16 Oct 06 |
jari |
152 |
}}} // of namespace utility, yat, and theplu |
12 |
19 Jun 03 |
daniel |
153 |
|
420 |
02 Dec 05 |
jari |
154 |
#endif |