source: trunk/yat/utility/vector.h @ 1068

Last change on this file since 1068 was 1068, checked in by Peter, 13 years ago

some documentation and vector::operator=(const VectorBase?&)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
1#ifndef _theplu_yat_utility_vector_
2#define _theplu_yat_utility_vector_
3
4// $Id: vector.h 1068 2008-02-11 19:29:36Z 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 The assignment operator.
119
120       \note Invalidates views of vector.
121
122       \return A const reference to the resulting vector.
123    */
124    const vector& operator=(const vector&);
125
126    /**
127       \brief The assignment operator.
128
129       \note Invalidates views of vector.
130
131       \return A const reference to the resulting vector.
132    */
133    const vector& operator=(const VectorBase&);
134
135  private:
136    const vector& assign(const VectorBase& other);
137
138    /**
139       \brief Create a new copy of the internal GSL vector.
140
141       Necessary memory for the new GSL vector is allocated and the
142       caller is responsible for freeing the allocated memory.
143
144       \return A pointer to a copy of the internal GSL vector.
145
146       \throw GSL_error if memory cannot be allocated for the new
147       copy, or if dimensions mis-match.
148    */
149    gsl_vector* create_gsl_vector_copy(const VectorBase&) const;
150
151    void delete_allocated_memory(void);
152  };
153
154  /**
155     \brief Swap vector elements by copying.
156
157     The two vectors must have the same length.
158
159     \throw GSL_error if vector lengths differs.
160  */
161  void swap(vector&, vector&);
162
163}}} // of namespace utility, yat, and theplu
164
165#endif
Note: See TracBrowser for help on using the repository browser.