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

Last change on this file since 1027 was 1027, checked in by Peter, 14 years ago

going back to previous design in which view and const_view are in different classes. Having them in same didnt work as expected. There is a problem converting vector::iterator to vector::const_iterator. I'll open a separate ticket for this issue.

  • 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 1027 2008-02-02 21:29:29Z 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 Jari Häkkinen, Markus Ringnér, Peter Johansson
7  Copyright (C) 2007 Jari Häkkinen, Peter Johansson
8
9  This file is part of the yat library, http://trac.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#include "utility.h"
30#include "yat/random/random.h"
31
32#include <algorithm>
33#include <cassert>
34#include <cmath>
35#include <iostream>
36#include <sstream>
37#include <utility>
38#include <vector>
39
40namespace theplu {
41namespace yat {
42namespace utility {
43
44
45  VectorConstView::VectorConstView(const VectorConstView& other)
46    : VectorBase(other.gsl_vector_p()), const_view_(NULL)
47  {
48  }
49
50
51  VectorConstView::VectorConstView(const VectorBase& other)
52    : VectorBase(other.gsl_vector_p()), const_view_(NULL)
53  {
54  }
55
56
57  VectorConstView::VectorConstView(const VectorBase& v, size_t offset,size_t n,
58                                   size_t stride)
59    : VectorBase()
60  {
61    const_view_ = new gsl_vector_const_view(
62                   gsl_vector_const_subvector_with_stride(v.gsl_vector_p(), 
63                                                          offset, stride,n));
64    const_vec_ = &(const_view_->vector);
65  }
66
67
68  VectorConstView::VectorConstView(const matrix& m, size_t i, bool row)
69    : VectorBase(), const_view_(NULL)
70  {
71    const_view_ = 
72      new gsl_vector_const_view(row ? 
73                                gsl_matrix_const_row(m.gsl_matrix_p(),i) :
74                                gsl_matrix_const_column(m.gsl_matrix_p(),i));
75    const_vec_ = &(const_view_->vector);
76  }
77
78
79  VectorConstView::~VectorConstView(void)
80  {
81    delete_allocated_memory();
82  }
83
84
85  bool VectorConstView::isview(void) const
86  {
87    return true;
88  }
89
90
91
92  void VectorConstView::delete_allocated_memory(void)
93  {
94    if (const_view_){
95      delete const_view_;
96      const_view_=NULL;
97    }
98    const_vec_ = NULL;
99  }
100
101
102}}} // of namespace utility, yat, and thep
Note: See TracBrowser for help on using the repository browser.