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

Last change on this file since 1487 was 1487, checked in by Jari Häkkinen, 12 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: 2.5 KB
Line 
1// $Id: VectorConstView.cc 1487 2008-09-10 08:41:36Z jari $
2
3/*
4  Copyright (C) 2003 Daniel Dalevi, Peter Johansson
5  Copyright (C) 2004 Jari Häkkinen, Peter Johansson
6  Copyright (C) 2005, 2006, 2007 Jari Häkkinen, Peter Johansson, Markus Ringnér
7  Copyright (C) 2008 Peter Johansson
8
9  This file is part of the yat library, http://dev.thep.lu.se/trac/yat
10
11  The yat library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 3 of the
14  License, or (at your option) any later version.
15
16  The yat library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20
21  You should have received a copy of the GNU General Public License
22  along with yat. If not, see <http://www.gnu.org/licenses/>.
23*/
24
25#include "VectorConstView.h"
26#include "Matrix.h"
27
28namespace theplu {
29namespace yat {
30namespace utility {
31
32
33  VectorConstView::VectorConstView(const VectorConstView& other)
34    : VectorBase(), const_view_(NULL)
35  {
36    const_view_ = 
37      new gsl_vector_const_view(gsl_vector_const_subvector(other.gsl_vector_p(), 
38                                                           0, other.size()));
39    const_vec_ = &(const_view_->vector);
40  }
41
42
43  VectorConstView::VectorConstView(const VectorBase& other)
44    : VectorBase(), const_view_(NULL)
45  {
46    const_view_ = 
47      new gsl_vector_const_view(gsl_vector_const_subvector(other.gsl_vector_p(), 
48                                                           0, other.size()));
49    const_vec_ = &(const_view_->vector);
50  }
51
52
53  VectorConstView::VectorConstView(const VectorBase& v, size_t offset,size_t n,
54                                   size_t stride)
55    : VectorBase()
56  {
57    const_view_ = new gsl_vector_const_view(
58                   gsl_vector_const_subvector_with_stride(v.gsl_vector_p(), 
59                                                          offset, stride,n));
60    const_vec_ = &(const_view_->vector);
61  }
62
63
64  VectorConstView::VectorConstView(const Matrix& m, size_t i, bool row)
65    : VectorBase(), const_view_(NULL)
66  {
67    const_view_ = 
68      new gsl_vector_const_view(row ? 
69                                gsl_matrix_const_row(m.gsl_matrix_p(),i) :
70                                gsl_matrix_const_column(m.gsl_matrix_p(),i));
71    const_vec_ = &(const_view_->vector);
72  }
73
74
75  VectorConstView::~VectorConstView(void)
76  {
77    delete_allocated_memory();
78  }
79
80
81  bool VectorConstView::isview(void) const
82  {
83    return true;
84  }
85
86
87
88  void VectorConstView::delete_allocated_memory(void)
89  {
90    if (const_view_){
91      delete const_view_;
92      const_view_=NULL;
93    }
94    const_vec_ = NULL;
95  }
96
97
98}}} // of namespace utility, yat, and thep
Note: See TracBrowser for help on using the repository browser.