source: trunk/yat/utility/VectorConstView.h

Last change on this file was 4207, checked in by Peter, 3 months ago

update copyright statements

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
  • Property svndigest:ignore set to 1026
File size: 4.2 KB
Line 
1#ifndef _theplu_yat_utility_vector_const_view_
2#define _theplu_yat_utility_vector_const_view_
3
4// $Id: VectorConstView.h 4207 2022-08-26 04:36:28Z peter $
5
6/*
7  Copyright (C) 2003 Daniel Dalevi, Peter Johansson
8  Copyright (C) 2004 Jari Häkkinen, Peter Johansson
9  Copyright (C) 2005 Jari Häkkinen, Peter Johansson, Markus Ringnér
10  Copyright (C) 2006 Jari Häkkinen, Markus Ringnér
11  Copyright (C) 2007 Jari Häkkinen, Peter Johansson, Markus Ringnér
12  Copyright (C) 2008 Jari Häkkinen, Peter Johansson
13  Copyright (C) 2009, 2012, 2017, 2021, 2022 Peter Johansson
14
15  This file is part of the yat library, http://dev.thep.lu.se/trac/yat
16
17  The yat library is free software; you can redistribute it and/or
18  modify it under the terms of the GNU General Public License as
19  published by the Free Software Foundation; either version 3 of the
20  License, or (at your option) any later version.
21
22  The yat library is distributed in the hope that it will be useful,
23  but WITHOUT ANY WARRANTY; without even the implied warranty of
24  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25  General Public License for more details.
26
27  You should have received a copy of the GNU General Public License
28  along with yat. If not, see <http://www.gnu.org/licenses/>.
29*/
30
31#include "VectorBase.h"
32
33#include <gsl/gsl_vector.h>
34
35namespace theplu {
36namespace yat {
37namespace utility {
38
39  class MatrixBase;
40  class VectorView;
41
42  /**
43     @brief Read-only view.
44
45     Wrapper to gsl_vector_const_view
46
47     With this class you can create a view into const
48     objects - either a vector or matrix. By design all functionality
49     in this class is const to guarantee that the viewed object is not
50     modified.
51
52     \note that view vectors do not own the underlying data,
53     and a view is not valid if the vector/matrix owing the data is
54     deallocated.
55  */
56  class VectorConstView : public VectorBase
57  {
58  public:
59    /**
60       \brief The copy constructor.
61    */
62    // needed to override compiler generated copy constructor
63    VectorConstView(const VectorConstView& other);
64
65    /**
66       \brief Copy a VectorView
67
68       Conversion from VectorView to VectorConstView. Implicit
69       conversion is allowed.
70
71       \since New in yat 0.15
72    */
73    VectorConstView(const VectorView& other);
74
75    /**
76       \brief Copy a VectorBase
77    */
78    explicit VectorConstView(const VectorBase& other);
79
80    /**
81       \brief const view into a vector
82
83       Create a const view of VectorBase \a v, with starting index \a offset,
84       size \a n, and an optional \a stride.
85
86       \note If the object viewed by the view goes out of scope or is
87       deleted, the view becomes invalid and the result of further use
88       is undefined.
89
90       \throw GSL_error if a view cannot be set up.
91    */
92    VectorConstView(const VectorBase& v,size_t offset,size_t n,size_t stride=1);
93
94    /**
95       \brief Matrix row/column view constructor.
96
97       Create a view into a row/column of a matrix.
98
99       \param m matrix to view into.
100       \param i index telling which row/column to view into
101       \param row if true (defult) created view is a row vector, i.e.,
102       viewing into row \a i, and, naturally, a column vector
103       otherwise.
104
105       \see matrix::column_const_view(size_t) and
106       matrix::row_const_view(size_t)
107
108       @note If the object viewed by the view goes out of scope or is
109       deleted, the view becomes invalid and the result of further
110       use is undefined.
111    */
112    VectorConstView(const MatrixBase& m, size_t i, bool row=true);
113
114    /**
115       Create a view into \c v
116
117       \since New in yat 0.20
118     */
119    explicit VectorConstView(const gsl_vector* v);
120
121    /**
122       Create a view with size \c size and stride \c stride such that
123       view(0) = v[0] and view(1) = v[stride].
124
125       \since New in yat 0.20
126     */
127    VectorConstView(const double* v, size_t size, size_t stride=1);
128
129    /**
130       The destructor.
131    */
132    ~VectorConstView(void);
133
134    /**
135       \return true
136    */
137    bool isview(void) const;
138
139  private:
140    void copy(const VectorBase& other);
141    void delete_allocated_memory(void);
142
143    // Perhaps not needed - only used to create a gsl_vector (that is
144    // stored in base class). For data access use data in base class
145    // because this pointer may be NULL.
146    gsl_vector_const_view* const_view_;
147
148    // assignment not allowed
149    VectorConstView& operator=(const VectorConstView&);
150  };
151
152}}} // of namespace utility, yat, and theplu
153
154#endif
Note: See TracBrowser for help on using the repository browser.