source: trunk/c++_tools/classifier/DataLookup1D.h @ 624

Last change on this file since 624 was 624, checked in by Peter, 15 years ago

fixes #109 and #110

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date ID
File size: 2.0 KB
Line 
1// $Id$
2
3#ifndef _theplu_classifier_dataLookup1D_
4#define _theplu_classifier_dataLookup1D_
5
6#include <c++_tools/classifier/DataLookup2D.h>
7
8#include <cassert>
9#include <iostream>
10#include <vector>
11
12namespace theplu {
13namespace classifier { 
14
15  ///
16  /// Class for general vector view
17  ///
18
19  class DataLookup1D
20  {
21 
22  public:
23
24    ///
25    /// Constructor.
26    ///
27    /// @parameter row_vector if true (default) DataLookup1D is
28    /// looking into a row of DataLookup2D, otherwise looking into
29    /// a column. @parameter index which row/column to look into.
30    ///
31    DataLookup1D(const DataLookup2D&, const size_t index, 
32                 const bool row_vector);
33
34    ///
35    /// Copy constructor
36    ///
37    DataLookup1D(const DataLookup1D&);
38
39    ///
40    /// Construct DataLookup1D that owns its underlying matrix. Object
41    /// has size @ size and all its element is equal to @a value.
42    ///
43    DataLookup1D(const size_t size, const double value=0); 
44
45    ///
46    ///
47    ///
48    virtual ~DataLookup1D();
49
50    ///
51    ///
52    ///
53    inline size_t size(void) const
54      { return column_vector_ ? matrix_->rows() : matrix_->columns(); }
55
56    ///
57    ///
58    ///
59    inline double operator()(const size_t i) const 
60    { 
61      assert(i<size()); 
62      return column_vector_ ? (*matrix_)(i,index_) : (*matrix_)(index_,i); 
63    }
64
65    ///
66    ///
67    ///
68    inline double operator[](const size_t i) const 
69    { 
70      return this->operator()(i);
71    }
72
73
74    ///
75    /// scalar product
76    ///
77    double operator*(const DataLookup1D&) const;
78
79  private:
80    const DataLookup1D& operator=(const DataLookup1D&);
81
82    const bool column_vector_;
83    const size_t index_;
84    const DataLookup2D* matrix_;
85    const bool owner_;
86   
87  };
88
89  ///
90  /// @brief The output operator for DataLookup1D.
91  ///
92  /**
93   * Elements are separated by the character from the omanip fill.
94   * The following example will write the elements separated by tab.
95   *
96   @verbatim
97   char prev=s.fill('\t');
98   s << v;
99   s.fill(prev);
100   @endverbatim
101  */
102  std::ostream& operator<<(std::ostream& s, const DataLookup1D& v);
103 
104}} // of namespace classifier and namespace theplu
105
106#endif
Note: See TracBrowser for help on using the repository browser.