yat  0.16pre
Vector.h
1 #ifndef _theplu_yat_utility_vector_
2 #define _theplu_yat_utility_vector_
3 
4 // $Id: Vector.h 3691 2017-09-14 07:13:22Z peter $
5 
6 /*
7  Copyright (C) 2003 Daniel Dalevi, Peter Johansson
8  Copyright (C) 2004 Jari Häkkinen, Peter Johansson
9  Copyright (C) 2005 Jari Häkkinen, Peter Johansson, Markus Ringnér
10  Copyright (C) 2006 Jari Häkkinen, Markus Ringnér
11  Copyright (C) 2007 Jari Häkkinen, Peter Johansson, Markus Ringnér
12  Copyright (C) 2008 Jari Häkkinen, Peter Johansson
13  Copyright (C) 2009, 2012, 2017 Peter Johansson
14 
15  This file is part of the yat library, http://dev.thep.lu.se/yat
16 
17  The yat library is free software; you can redistribute it and/or
18  modify it under the terms of the GNU General Public License as
19  published by the Free Software Foundation; either version 3 of the
20  License, or (at your option) any later version.
21 
22  The yat library is distributed in the hope that it will be useful,
23  but WITHOUT ANY WARRANTY; without even the implied warranty of
24  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25  General Public License for more details.
26 
27  You should have received a copy of the GNU General Public License
28  along with yat. If not, see <http://www.gnu.org/licenses/>.
29 */
30 
31 #include "config_public.h"
32 
33 #include "VectorMutable.h"
34 #include "Exception.h"
35 
36 #include <cstddef> // size_t
37 #include <iosfwd>
38 #include <stdexcept>
39 
40 #include <gsl/gsl_vector.h>
41 
42 namespace theplu {
43 namespace yat {
44 namespace utility {
45 
59  class Vector : public VectorMutable
60  {
61  public:
65  Vector(void);
66 
73  explicit Vector(size_t n, double init_value=0);
74 
81  Vector(const Vector& other);
82 
86  template<class T>
88  : VectorMutable(detail::create_gsl_vector_copy(other.gsl_vector_p()))
89  {
90  }
91 
92 #ifdef YAT_HAVE_RVALUE
93 
98  Vector(Vector&& other) noexcept;
99 
105  template<class T>
106  Vector(VectorExpression<T>&& other)
107  : VectorMutable(other.gsl_vector_p())
108  {
109  other.gsl_vector_p(NULL);
110  }
111 #endif
112 
119  explicit Vector(const VectorBase& other);
120 
133  explicit Vector(std::istream &, char sep='\0')
134  throw(utility::IO_error, std::exception);
135 
139  ~Vector(void);
140 
144  bool isview(void) const;
145 
156  void resize(size_t, double init_value=0);
157 
167  const Vector& operator=(const Vector&);
168 
174  template<class T>
176  {
177  // access rhs before deleting vec_
178  gsl_vector* tmp = detail::create_gsl_vector_copy(rhs.gsl_vector_p());
179  delete_allocated_memory();
180  const_vec_ = vec_ = tmp;
181  return *this;
182  }
183 
184 #ifdef YAT_HAVE_RVALUE
185 
194  Vector& operator=(Vector&&);
195 
201  template<class T>
203  {
204  gsl_vector* tmp = rhs.gsl_vector_p();
205  delete_allocated_memory();
206  const_vec_ = vec_ = tmp;
207  rhs.gsl_vector_p(NULL);
208  return *this;
209  }
210 
211 #endif
212 
222  const Vector& operator=(const VectorBase&);
223 
224  private:
225  const Vector& assign(const VectorBase& other);
226  const Vector& assign(const gsl_vector* rhs);
227 
239  gsl_vector* create_gsl_vector_copy(const VectorBase&) const;
240 
241 
242  void delete_allocated_memory(void);
243  };
244 
254  void swap(Vector&, Vector&);
255 
256 }}} // of namespace utility, yat, and theplu
257 
258 #endif
void resize(size_t, double init_value=0)
Resize Vector.
The Department of Theoretical Physics namespace as we define it.
const Vector & operator=(const Vector &)
The assignment operator.
const gsl_vector * const_vec_
pointer to underlying GSL vector
Definition: VectorBase.h:168
VectorMutable(void)
default constructor
const gsl_vector * gsl_vector_p(void) const
return a GSL vector pointer
Definition: VectorExpression.h:112
This is the yat interface to GSL vector.
Definition: Vector.h:59
This is the yat interface to GSL vector.
Definition: VectorBase.h:55
Vector(const VectorExpression< T > &other)
Constructor from a vector expression.
Definition: Vector.h:87
gsl_vector * vec_
Definition: VectorMutable.h:269
An expression that can be converted to a Vector.
Definition: VectorExpression.h:67
void swap(Vector &, Vector &)
Swap Vector elements by copying.
This is the mutable interface to GSL vector.
Definition: VectorMutable.h:56
Class to report errors associated with IO operations.
Definition: Exception.h:109
Vector & operator=(const VectorExpression< T > &rhs)
assignment from vector expression
Definition: Vector.h:175
Vector(void)
The default constructor.
bool isview(void) const

Generated on Wed Jan 30 2019 02:34:18 for yat by  doxygen 1.8.11