source: trunk/yat/utility/VectorConstView.h @ 1487

Last change on this file since 1487 was 1487, checked in by Jari Häkkinen, 15 years ago

Addresses #436. GPL license copy reference should also be updated.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
1#ifndef _theplu_yat_utility_vector_const_view_
2#define _theplu_yat_utility_vector_const_view_
3
4// $Id: VectorConstView.h 1487 2008-09-10 08:41:36Z jari $
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 Peter Johansson
13
14  This file is part of the yat library, http://dev.thep.lu.se/trac/yat
15
16  The yat library is free software; you can redistribute it and/or
17  modify it under the terms of the GNU General Public License as
18  published by the Free Software Foundation; either version 3 of the
19  License, or (at your option) any later version.
20
21  The yat library is distributed in the hope that it will be useful,
22  but WITHOUT ANY WARRANTY; without even the implied warranty of
23  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24  General Public License for more details.
25
26  You should have received a copy of the GNU General Public License
27  along with yat. If not, see <http://www.gnu.org/licenses/>.
28*/
29
30#include "VectorBase.h"
31
32#include <gsl/gsl_vector.h>
33
34namespace theplu {
35namespace yat {
36namespace utility {
37
38  class Matrix;
39
40  /**
41     @brief Read-only view.
42
43     Wrapper to gsl_vector_const_view
44
45     With this class you can create a view into const
46     objects - either a vector or matrix. By design all functionality
47     in this class is const to guarantee that the viewed object is not
48     modified.
49
50     \note that view vectors do not own the underlying data,
51     and a view is not valid if the vector/matrix owing the data is
52     deallocated.
53  */
54  class VectorConstView : public VectorBase
55  {
56  public:
57    /**
58       \brief The copy constructor.
59    */
60    // needed to override compiler generated copy constructor
61    VectorConstView(const VectorConstView& other);
62
63    /**
64       \brief Copy a VectorBase
65    */ 
66    VectorConstView(const VectorBase& other);
67
68    /**
69       \brief const view into a vector
70
71       Create a const view of VectorBase \a v, with starting index \a offset,
72       size \a n, and an optional \a stride.
73
74       \note If the object viewed by the view goes out of scope or is
75       deleted, the view becomes invalid and the result of further use
76       is undefined.
77
78       \throw GSL_error if a view cannot be set up.
79    */
80    VectorConstView(const VectorBase& v,size_t offset,size_t n,size_t stride=1);
81
82    /**
83       \brief Matrix row/column view constructor.
84       
85       Create a view into a row/column of a matrix.
86
87       \param m matrix to view into.
88       \param i index telling which row/column to view into
89       \param row if true (defult) created view is a row vector, i.e.,
90       viewing into row \a i, and, naturally, a column vector
91       otherwise.
92
93       \see matrix::column_const_view(size_t) and
94       matrix::row_const_view(size_t)
95
96       @note If the object viewed by the view goes out of scope or is
97       deleted, the view becomes invalid and the result of further
98       use is undefined.
99    */
100    VectorConstView(const Matrix& m, size_t i, bool row=true);
101
102    /**
103       The destructor.
104    */
105    ~VectorConstView(void);
106
107    /**
108       \return true
109    */
110    bool isview(void) const; 
111
112  private:
113    void delete_allocated_memory(void);
114
115    // Perhaps not needed - only used to create a gsl_vector (that is
116    // stored in base class). For data access use data in base class
117    // because this pointer may be NULL.
118    gsl_vector_const_view* const_view_;
119   
120  };
121
122}}} // of namespace utility, yat, and theplu
123
124#endif
Note: See TracBrowser for help on using the repository browser.