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

Last change on this file since 1028 was 1028, checked in by Peter, 15 years ago

documentation for VectorConstView? and changing name of view functions in matrix

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.6 KB
Line 
1#ifndef _theplu_yat_utility_vector_const_view_
2#define _theplu_yat_utility_vector_const_view_
3
4// $Id: VectorConstView.h 1028 2008-02-03 01:53:29Z 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, Markus Ringnér, Peter Johansson
10  Copyright (C) 2006 Jari Häkkinen, Markus Ringnér
11  Copyright (C) 2007 Jari Häkkinen, Peter Johansson
12  Copyright (C) 2008 Peter Johansson
13
14  This file is part of the yat library, http://trac.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 2 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#include "Exception.h"
34
35#include <iostream>
36#include <vector>
37#include <utility>
38
39#include <gsl/gsl_vector.h>
40#include <gsl/gsl_sort_vector.h>
41
42namespace theplu {
43namespace yat {
44namespace utility {
45
46  class matrix;
47  class vector;
48
49  /**
50     @brief Read-only view.
51
52     Wrapper to gsl_vector_const_view
53
54     With this class you can create a view into const
55     objects - either a vector or matrix. By design all functionality
56     in this class is const to guarantee that the viewed object is not
57     modified.
58
59     \Note that view vectors do not own the underlying data,
60     and a view is not valid if the vector/matrix owing the data is
61     deallocated.
62  */
63  class VectorConstView : public VectorBase
64  {
65  public:
66    /**
67       \brief The copy constructor.
68    */
69    // needed to override compiler generated copy constructor
70    VectorConstView(const VectorConstView& other);
71
72    /**
73       \brief Copy a VectorBase
74    */ 
75    VectorConstView(const VectorBase& other);
76
77    /**
78       \brief const view into a vector
79
80       Create a const view of VectorBase \a v, with starting index \a offset,
81       size \a n, and an optional \a stride.
82
83       \note If the object viewed by the view goes out of scope or is
84       deleted, the view becomes invalid and the result of further use
85       is undefined.
86
87       \throw GSL_error if a view cannot be set up.
88    */
89    VectorConstView(const VectorBase& v,size_t offset,size_t n,size_t stride=1);
90
91    /**
92       \brief Matrix row/column view constructor.
93       
94       Create a view into a row/column of a matrix.
95
96       \param m matrix to view into.
97       \param i index telling which row/column to view into
98       \param row if true (defult) created view is a row vector, i.e.,
99       viewing into row \a i, and, naturally, a column vector
100       otherwise.
101
102       \see matrix::column_const_view(size_t) and
103       matrix::row_const_view(size_t)
104
105       @note If the object viewed by the view goes out of scope or is
106       deleted, the view becomes invalid and the result of further
107       use is undefined.
108    */
109    VectorConstView(const matrix& m, size_t i, bool row=true);
110
111    /**
112       The destructor.
113    */
114    ~VectorConstView(void);
115
116    /**
117       \return true
118    */
119    bool isview(void) const; 
120
121  private:
122    void delete_allocated_memory(void);
123
124    // Perhaps not needed - only used to create a gsl_vector (that is
125    // stored in base class). For data access use data in base class
126    // because this pointer may be NULL.
127    gsl_vector_const_view* const_view_;
128   
129  };
130
131}}} // of namespace utility, yat, and theplu
132
133#endif
Note: See TracBrowser for help on using the repository browser.