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

Last change on this file since 1275 was 1275, checked in by Jari Häkkinen, 13 years ago

Updating copyright statements.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.5 KB
Line 
1#ifndef _theplu_yat_utility_vector_
2#define _theplu_yat_utility_vector_
3
4// $Id: Vector.h 1275 2008-04-11 06:10:12Z jari $
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
14  This file is part of the yat library, http://trac.thep.lu.se/yat
15
16  The yat library is free software; you can redistribute it and/or
17  modify it under the terms of the GNU General Public License as
18  published by the Free Software Foundation; either version 2 of the
19  License, or (at your option) any later version.
20
21  The yat library is distributed in the hope that it will be useful,
22  but WITHOUT ANY WARRANTY; without even the implied warranty of
23  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24  General Public License for more details.
25
26  You should have received a copy of the GNU General Public License
27  along with this program; if not, write to the Free Software
28  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
29  02111-1307, USA.
30*/
31
32#include "VectorMutable.h"
33#include "Exception.h"
34
35#include <iostream>
36#include <vector>
37#include <utility>
38
39#include <gsl/gsl_vector.h>
40#include <gsl/gsl_sort_vector.h>
41
42namespace theplu {
43namespace yat {
44namespace utility {
45
46  class matrix;
47
48  /**
49     @brief This is the yat interface to GSL vector.
50
51     \par File streams:
52     Reading and writing vectors to file streams are of course
53     supported. These are implemented without using GSL functionality,
54     and thus binary read and write to streams are not supported.
55
56     \par Vector views: GSL vector views are supported in classes
57     VectorView and VectorConstView
58
59  */
60
61  class Vector : public VectorMutable
62  {
63  public:
64    /**
65       \brief The default constructor.
66    */
67    Vector(void);
68
69    /**
70       \brief Allocates memory space for \a n elements, and sets all
71       elements to \a init_value.
72       
73       \throw GSL_error if memory allocation fails.
74    */
75    Vector(size_t n, double init_value=0);
76
77    /**
78       \brief The copy constructor.
79
80       \throw A GSL_error is indirectly thrown if memory allocation
81       fails.
82    */
83    Vector(const Vector& other);
84
85    /**
86       \brief Copy a VectorBase.
87
88       \throw A GSL_error is indirectly thrown if memory allocation
89       fails.
90    */
91    Vector(const VectorBase& other);
92
93    /**
94       \brief The istream constructor.
95
96       Either elements should be separated with white space characters
97       (default), or elements should be separated by the delimiter \a
98       sep. When delimiter \a sep is used empty elements are stored as
99       NaN's (except that empty lines are ignored). The end of input
100       to the Vector is at end of file marker.
101
102       \throw GSL_error if memory allocation fails, IO_error if
103       unexpected input is found in the input stream.
104    */
105    explicit Vector(std::istream &, char sep='\0')
106      throw(utility::IO_error, std::exception);
107
108    ///
109    /// The destructor.
110    ///
111    ~Vector(void);
112
113    /**
114       \return false
115    */
116    bool isview(void) const; 
117
118    /**
119      \brief Resize Vector
120
121      All elements are set to \a init_value.
122
123      \note Underlying GSL vector is destroyed and a view into this
124      Vector becomes invalid.
125
126      \throw GSL_error if memory allocation fails.
127    */
128    void resize(size_t, double init_value=0);
129
130    /**
131       \brief The assignment operator.
132
133       \note Invalidates views of Vector.
134
135       \return A const reference to the resulting Vector.
136
137       \throw GSL_error if assignment fails.
138    */
139    const Vector& operator=(const Vector&);
140
141    /**
142       \brief The assignment operator.
143
144       \note Invalidates views of Vector.
145
146       \return A const reference to the resulting Vector.
147
148       \throw GSL_error if assignment fails.
149    */
150    const Vector& operator=(const VectorBase&);
151
152  private:
153    const Vector& assign(const VectorBase& other);
154
155    /**
156       \brief Create a new copy of the internal GSL vector.
157
158       Necessary memory for the new GSL vector is allocated and the
159       caller is responsible for freeing the allocated memory.
160
161       \return A pointer to a copy of the internal GSL vector.
162
163       \throw GSL_error if memory cannot be allocated for the new
164       copy, or if dimensions mis-match.
165    */
166    gsl_vector* create_gsl_vector_copy(const VectorBase&) const;
167
168    void delete_allocated_memory(void);
169  };
170
171  /**
172     \brief Swap Vector elements by copying.
173
174     The two Vectors must have the same length.
175
176     \throw GSL_error if Vector lengths differs.
177  */
178  void swap(Vector&, Vector&);
179
180}}} // of namespace utility, yat, and theplu
181
182#endif
Note: See TracBrowser for help on using the repository browser.