source: trunk/yat/utility/Vector.h @ 3101

Last change on this file since 3101 was 3101, checked in by Peter, 8 years ago

remove forward declaration not needed (class matrix was renamed almost half a decade ago)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.8 KB
Line 
1#ifndef _theplu_yat_utility_vector_
2#define _theplu_yat_utility_vector_
3
4// $Id: Vector.h 3101 2013-11-01 08:54:57Z 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 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 "VectorMutable.h"
32#include "Exception.h"
33
34#include <cstddef> // size_t
35#include <iosfwd>
36#include <stdexcept>
37
38#include <gsl/gsl_vector.h>
39
40namespace theplu {
41namespace yat {
42namespace utility {
43
44  /**
45     @brief This is the yat interface to GSL vector.
46
47     \par File streams:
48     Reading and writing vectors to file streams are of course
49     supported. These are implemented without using GSL functionality,
50     and thus binary read and write to streams are not supported.
51
52     \par Vector views: GSL vector views are supported in classes
53     VectorView and VectorConstView
54
55  */
56
57  class Vector : public VectorMutable
58  {
59  public:
60    /**
61       \brief The default constructor.
62    */
63    Vector(void);
64
65    /**
66       \brief Allocates memory space for \a n elements, and sets all
67       elements to \a init_value.
68
69       \throw GSL_error if memory allocation fails.
70    */
71    explicit Vector(size_t n, double init_value=0);
72
73    /**
74       \brief The copy constructor.
75
76       \throw A GSL_error is indirectly thrown if memory allocation
77       fails.
78    */
79    Vector(const Vector& other);
80
81    /**
82       \brief Copy a VectorBase.
83
84       \throw A GSL_error is indirectly thrown if memory allocation
85       fails.
86    */
87    explicit Vector(const VectorBase& other);
88
89    /**
90       \brief The istream constructor.
91
92       Either elements should be separated with white space characters
93       (default), or elements should be separated by the delimiter \a
94       sep. When delimiter \a sep is used empty elements are stored as
95       NaN's (except that empty lines are ignored). The end of input
96       to the Vector is at end of file marker.
97
98       \throw GSL_error if memory allocation fails, IO_error if
99       unexpected input is found in the input stream.
100    */
101    explicit Vector(std::istream &, char sep='\0')
102      throw(utility::IO_error, std::exception);
103
104    ///
105    /// The destructor.
106    ///
107    ~Vector(void);
108
109    /**
110       \return false
111    */
112    bool isview(void) const;
113
114    /**
115      \brief Resize Vector
116
117      All elements are set to \a init_value.
118
119      \note Underlying GSL vector is destroyed and a view or an
120      iterator into this Vector becomes invalid.
121
122      \throw GSL_error if memory allocation fails.
123    */
124    void resize(size_t, double init_value=0);
125
126    /**
127       \brief The assignment operator.
128
129       \note Invalidates views and iterators of Vector.
130
131       \return A const reference to the resulting Vector.
132
133       \throw GSL_error if assignment fails.
134    */
135    const Vector& operator=(const Vector&);
136
137    /**
138       \brief The assignment operator.
139
140       \note Invalidates views and iterators of Vector.
141
142       \return A const reference to the resulting Vector.
143
144       \throw GSL_error if assignment fails.
145    */
146    const Vector& operator=(const VectorBase&);
147
148  private:
149    const Vector& assign(const VectorBase& other);
150
151    /**
152       \brief Create a new copy of the internal GSL vector.
153
154       Necessary memory for the new GSL vector is allocated and the
155       caller is responsible for freeing the allocated memory.
156
157       \return A pointer to a copy of the internal GSL vector.
158
159       \throw GSL_error if memory cannot be allocated for the new
160       copy, or if dimensions mis-match.
161    */
162    gsl_vector* create_gsl_vector_copy(const VectorBase&) const;
163
164    /**
165       \brief Create a new gsl vector
166
167       Necessary memory for the new GSL vector is allocated and the
168       caller is responsible for freeing the allocated memory.
169
170       \return A pointer to created GSL vector.
171
172       \throw GSL_error if memory cannot be allocated for the new
173       GSL vector.
174    */
175    gsl_vector* create_gsl_vector(size_t n) const;
176
177    void delete_allocated_memory(void);
178  };
179
180  /**
181     \brief Swap Vector elements by copying.
182
183     The two Vectors must have the same length.
184
185     \throw GSL_error if Vector lengths differs.
186
187     \relates Vector
188  */
189  void swap(Vector&, Vector&);
190
191}}} // of namespace utility, yat, and theplu
192
193#endif
Note: See TracBrowser for help on using the repository browser.