source: trunk/yat/classifier/DataLookup1D.h @ 1062

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

redesigning Iterator class to hold a 2D container rather than 1D as before. refs #267

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date ID
File size: 3.9 KB
Line 
1#ifndef _theplu_yat_classifier_dataLookup1D_
2#define _theplu_yat_classifier_dataLookup1D_
3
4// $Id$
5
6/*
7  Copyright (C) 2005 Peter Johansson
8  Copyright (C) 2006 Jari Häkkinen, Markus Ringnér, Peter Johansson
9  Copyright (C) 2007 Jari Häkkinen, Peter Johansson
10
11  This file is part of the yat library, http://trac.thep.lu.se/yat
12
13  The yat library is free software; you can redistribute it and/or
14  modify it under the terms of the GNU General Public License as
15  published by the Free Software Foundation; either version 2 of the
16  License, or (at your option) any later version.
17
18  The yat library is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  General Public License for more details.
22
23  You should have received a copy of the GNU General Public License
24  along with this program; if not, write to the Free Software
25  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26  02111-1307, USA.
27*/
28
29#include "DataLookup2D.h"
30#include "yat/utility/Iterator.h"
31#include "yat/utility/StrideIterator.h"
32
33#include <iostream>
34#include <vector>
35
36namespace theplu {
37namespace yat {
38namespace utility {
39  class VectorBase;
40}
41namespace classifier { 
42
43  ///
44  /// @brief Class for general vector view.
45  ///
46  class DataLookup1D
47  {
48 
49  public:
50    /// 'Read Only' iterator
51    typedef utility::StrideIterator<utility::Iterator<const DataLookup2D, 
52                                                      const double> >
53    const_iterator;
54
55    ///
56    /// Constructor.
57    ///
58    /// @param row_vector if true DataLookup1D is looking into a
59    /// row of DataLookup2D, otherwise looking into a
60    /// column. @param index which row/column to look into.
61    ///
62    DataLookup1D(const DataLookup2D&, const size_t index, 
63                 const bool row_vector);
64
65    ///
66    /// Copy constructor
67    ///
68    DataLookup1D(const DataLookup1D&);
69
70    ///
71    /// Construct DataLookup1D that owns its underlying matrix. Object
72    /// has size @ size and all its element is equal to @a value.
73    ///
74    DataLookup1D(const size_t size, const double value=0); 
75
76    /**
77       @brief Create general view from utility::VectorBase
78   
79       Constructor creates a proper MatrixLookup that object can view
80       into. Object is owner of this underlying MatrixLookup. Object fulfills
81       \f$ x(i) = vec(index(i)) \f$
82    */
83    DataLookup1D(const utility::VectorBase& vec, 
84                 const std::vector<size_t>& index); 
85
86    /**
87       @brief Create general view from utility::VectorBase
88   
89       Constructor creates a proper MatrixLookup that object can view
90       into. Object is owner of this underlying MatrixLookup. Object fulfills
91       \f$ x(i) = vec(i) \f$
92    */
93    DataLookup1D(const utility::VectorBase& vec); 
94
95    ///
96    /// @brief Destructor deletes underlying DataLookup2D if object is owner
97    ///
98    virtual ~DataLookup1D();
99
100    /**
101       \return 'Read Only' iterator to first element.
102     */
103    const_iterator begin() const;
104
105    /**
106       \return 'Read Only' iterator to end of DataLookup1D.
107     */
108    const_iterator end() const;
109
110    ///
111    /// @return number of elements
112    ///
113    size_t size(void) const;
114
115    ///
116    /// @brief access operator
117    ///
118    double operator()(const size_t i) const;
119
120    ///
121    /// @brief access operator
122    ///
123    double operator[](const size_t i) const;
124
125    ///
126    /// scalar product
127    ///
128    double operator*(const DataLookup1D&) const;
129
130  private:
131    const DataLookup1D& operator=(const DataLookup1D&);
132
133    const bool column_vector_;
134    const size_t index_;
135    const DataLookup2D* matrix_;
136    const bool owner_;
137   
138  };
139
140  ///
141  /// @brief The output operator for DataLookup1D.
142  ///
143  /**
144   * Elements are separated by the character from the omanip fill.
145   * The following example will write the elements separated by tab.
146   *
147   @verbatim
148   char prev=s.fill('\t');
149   s << v;
150   s.fill(prev);
151   @endverbatim
152  */
153  std::ostream& operator<<(std::ostream& s, const DataLookup1D& v);
154 
155}}} // of namespace classifier, yat, and theplu
156
157#endif
Note: See TracBrowser for help on using the repository browser.