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

Last change on this file since 1710 was 1710, checked in by Peter, 12 years ago

avoid repeating code

  • 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 1710 2009-01-13 16:35:23Z 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, 2009 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 "VectorView.h"
27#include "Matrix.h"
28
29namespace theplu {
30namespace yat {
31namespace utility {
32
33
34  VectorConstView::VectorConstView(const VectorConstView& other)
35    : VectorBase(), const_view_(NULL)
36  {
37    copy(other);
38  }
39
40
41  VectorConstView::VectorConstView(const VectorBase& other)
42    : VectorBase(), const_view_(NULL)
43  {
44    copy(other);
45  }
46
47
48  VectorConstView::VectorConstView(const VectorBase& v, size_t offset,size_t n,
49                                   size_t stride)
50    : VectorBase()
51  {
52    const_view_ = new gsl_vector_const_view(
53                   gsl_vector_const_subvector_with_stride(v.gsl_vector_p(), 
54                                                          offset, stride,n));
55    const_vec_ = &(const_view_->vector);
56  }
57
58
59  VectorConstView::VectorConstView(const Matrix& m, size_t i, bool row)
60    : VectorBase(), const_view_(NULL)
61  {
62    const_view_ = 
63      new gsl_vector_const_view(row ? 
64                                gsl_matrix_const_row(m.gsl_matrix_p(),i) :
65                                gsl_matrix_const_column(m.gsl_matrix_p(),i));
66    const_vec_ = &(const_view_->vector);
67  }
68
69
70  VectorConstView::~VectorConstView(void)
71  {
72    delete_allocated_memory();
73  }
74
75
76  void VectorConstView::copy(const VectorBase& other)
77  {
78    const_view_ = 
79      new gsl_vector_const_view(gsl_vector_const_subvector(other.gsl_vector_p(), 
80                                                           0, other.size()));
81    const_vec_ = &(const_view_->vector);
82  }
83
84
85  void VectorConstView::delete_allocated_memory(void)
86  {
87    delete const_view_;
88    const_view_=NULL;
89    const_vec_ = NULL;
90  }
91
92
93  bool VectorConstView::isview(void) const
94  {
95    return true;
96  }
97
98}}} // of namespace utility, yat, and thep
Note: See TracBrowser for help on using the repository browser.