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

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

some docs refs #256

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