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

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

Addresses #436.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.5 KB
Line 
1#ifndef _theplu_yat_utility_vector_const_view_
2#define _theplu_yat_utility_vector_const_view_
3
4// $Id: VectorConstView.h 1486 2008-09-09 21:17:19Z 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 this program; if not, write to the Free Software
28  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
29  02111-1307, USA.
30*/
31
32#include "VectorBase.h"
33
34#include <gsl/gsl_vector.h>
35
36namespace theplu {
37namespace yat {
38namespace utility {
39
40  class Matrix;
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 VectorBase
67    */ 
68    VectorConstView(const VectorBase& other);
69
70    /**
71       \brief const view into a vector
72
73       Create a const view of VectorBase \a v, with starting index \a offset,
74       size \a n, and an optional \a stride.
75
76       \note If the object viewed by the view goes out of scope or is
77       deleted, the view becomes invalid and the result of further use
78       is undefined.
79
80       \throw GSL_error if a view cannot be set up.
81    */
82    VectorConstView(const VectorBase& v,size_t offset,size_t n,size_t stride=1);
83
84    /**
85       \brief Matrix row/column view constructor.
86       
87       Create a view into a row/column of a matrix.
88
89       \param m matrix to view into.
90       \param i index telling which row/column to view into
91       \param row if true (defult) created view is a row vector, i.e.,
92       viewing into row \a i, and, naturally, a column vector
93       otherwise.
94
95       \see matrix::column_const_view(size_t) and
96       matrix::row_const_view(size_t)
97
98       @note If the object viewed by the view goes out of scope or is
99       deleted, the view becomes invalid and the result of further
100       use is undefined.
101    */
102    VectorConstView(const Matrix& m, size_t i, bool row=true);
103
104    /**
105       The destructor.
106    */
107    ~VectorConstView(void);
108
109    /**
110       \return true
111    */
112    bool isview(void) const; 
113
114  private:
115    void delete_allocated_memory(void);
116
117    // Perhaps not needed - only used to create a gsl_vector (that is
118    // stored in base class). For data access use data in base class
119    // because this pointer may be NULL.
120    gsl_vector_const_view* const_view_;
121   
122  };
123
124}}} // of namespace utility, yat, and theplu
125
126#endif
Note: See TracBrowser for help on using the repository browser.