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

Last change on this file since 1437 was 1437, checked in by Peter, 13 years ago

merge patch release 0.4.2 to trunk. Delta 0.4.2-0.4.1

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.6 KB
Line 
1// $Id: VectorConstView.cc 1437 2008-08-25 17:55:00Z peter $
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 2 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 this program; if not, write to the Free Software
23  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24  02111-1307, USA.
25*/
26
27#include "VectorConstView.h"
28#include "Matrix.h"
29
30namespace theplu {
31namespace yat {
32namespace utility {
33
34
35  VectorConstView::VectorConstView(const VectorConstView& other)
36    : VectorBase(), const_view_(NULL)
37  {
38    const_view_ = 
39      new gsl_vector_const_view(gsl_vector_const_subvector(other.gsl_vector_p(), 
40                                                           0, other.size()));
41    const_vec_ = &(const_view_->vector);
42  }
43
44
45  VectorConstView::VectorConstView(const VectorBase& other)
46    : VectorBase(), const_view_(NULL)
47  {
48    const_view_ = 
49      new gsl_vector_const_view(gsl_vector_const_subvector(other.gsl_vector_p(), 
50                                                           0, other.size()));
51    const_vec_ = &(const_view_->vector);
52  }
53
54
55  VectorConstView::VectorConstView(const VectorBase& v, size_t offset,size_t n,
56                                   size_t stride)
57    : VectorBase()
58  {
59    const_view_ = new gsl_vector_const_view(
60                   gsl_vector_const_subvector_with_stride(v.gsl_vector_p(), 
61                                                          offset, stride,n));
62    const_vec_ = &(const_view_->vector);
63  }
64
65
66  VectorConstView::VectorConstView(const Matrix& m, size_t i, bool row)
67    : VectorBase(), const_view_(NULL)
68  {
69    const_view_ = 
70      new gsl_vector_const_view(row ? 
71                                gsl_matrix_const_row(m.gsl_matrix_p(),i) :
72                                gsl_matrix_const_column(m.gsl_matrix_p(),i));
73    const_vec_ = &(const_view_->vector);
74  }
75
76
77  VectorConstView::~VectorConstView(void)
78  {
79    delete_allocated_memory();
80  }
81
82
83  bool VectorConstView::isview(void) const
84  {
85    return true;
86  }
87
88
89
90  void VectorConstView::delete_allocated_memory(void)
91  {
92    if (const_view_){
93      delete const_view_;
94      const_view_=NULL;
95    }
96    const_vec_ = NULL;
97  }
98
99
100}}} // of namespace utility, yat, and thep
Note: See TracBrowser for help on using the repository browser.