Changeset 1710


Ignore:
Timestamp:
Jan 13, 2009, 5:35:23 PM (12 years ago)
Author:
Peter
Message:

avoid repeating code

Location:
trunk/yat/utility
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/utility/VectorConstView.cc

    r1487 r1710  
    55  Copyright (C) 2004 Jari Häkkinen, Peter Johansson
    66  Copyright (C) 2005, 2006, 2007 Jari Häkkinen, Peter Johansson, Markus Ringnér
    7   Copyright (C) 2008 Peter Johansson
     7  Copyright (C) 2008, 2009 Peter Johansson
    88
    99  This file is part of the yat library, http://dev.thep.lu.se/trac/yat
     
    2424
    2525#include "VectorConstView.h"
     26#include "VectorView.h"
    2627#include "Matrix.h"
    2728
     
    3435    : VectorBase(), const_view_(NULL)
    3536  {
    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);
     37    copy(other);
    4038  }
    4139
     
    4442    : VectorBase(), const_view_(NULL)
    4543  {
    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);
     44    copy(other);
    5045  }
    5146
     
    7974
    8075
     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
    8193  bool VectorConstView::isview(void) const
    8294  {
     
    8496  }
    8597
    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 
    9898}}} // of namespace utility, yat, and thep
  • trunk/yat/utility/VectorConstView.h

    r1651 r1710  
    1010  Copyright (C) 2006 Jari Häkkinen, Markus Ringnér
    1111  Copyright (C) 2007 Jari Häkkinen, Peter Johansson, Markus Ringnér
    12   Copyright (C) 2008 Peter Johansson
     12  Copyright (C) 2008, 2009 Peter Johansson
    1313
    1414  This file is part of the yat library, http://dev.thep.lu.se/trac/yat
     
    3737
    3838  class Matrix;
     39  class VectorView;
    3940
    4041  /**
     
    111112
    112113  private:
     114    void copy(const VectorBase& other);
    113115    void delete_allocated_memory(void);
    114116
Note: See TracChangeset for help on using the changeset viewer.