source: trunk/yat/classifier/DataLookup2D.cc @ 1169

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

refs #343 moving data to inherited classes and using SmartPtr?.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date ID
File size: 2.6 KB
Line 
1// $Id$
2
3/*
4  Copyright (C) 2005 Markus Ringnér, Peter Johansson
5  Copyright (C) 2006 Jari Häkkinen, Markus Ringnér, Peter Johansson
6
7  This file is part of the yat library, http://trac.thep.lu.se/yat
8
9  The yat library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version.
13
14  The yat library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22  02111-1307, USA.
23*/
24
25#include "DataLookup2D.h"
26
27#include <vector>
28
29#include <cassert>
30#ifndef NDEBUG
31#include <algorithm>
32#endif
33
34namespace theplu {
35namespace yat {
36namespace classifier {
37
38
39  DataLookup2D::DataLookup2D(const bool own)
40  {
41  }
42
43
44  DataLookup2D::DataLookup2D(const DataLookup2D& m,
45                             const utility::Index& row, 
46                             const utility::Index& col)
47  {
48    row_index_ = utility::Index(m.row_index_, row);
49    column_index_ = utility::Index(m.column_index_, col);
50  }
51   
52
53
54  DataLookup2D::DataLookup2D(const DataLookup2D& m,
55                             const utility::Index& index, 
56                             const bool row)
57  {
58    if (row){
59      row_index_ = utility::Index(m.row_index_, index);
60      column_index_= m.column_index_;
61    }
62    else{
63      column_index_ = utility::Index(m.column_index_, index);
64      row_index_= m.row_index_;
65    }
66  }   
67
68
69  DataLookup2D::DataLookup2D(const utility::Index& row, 
70                             const utility::Index& col,
71                             const bool own)
72    : row_index_(row),column_index_(col)
73  {
74  }
75
76
77
78  DataLookup2D::DataLookup2D(const DataLookup2D& mv)
79    : row_index_(mv.row_index_),column_index_(mv.column_index_) 
80  {
81  }
82
83
84  DataLookup2D::DataLookup2D(const size_t rows, const size_t columns)
85    : row_index_(std::vector<size_t>(rows,0)), 
86      column_index_(std::vector<size_t>(columns,0))
87  {
88  } 
89
90
91  size_t DataLookup2D::columns(void) const
92  {
93    return column_index_.size();
94  }
95
96
97  double DataLookup2D::data(size_t i, size_t j) const
98  {
99    return (*this)(i,j);
100  }
101
102
103  size_t DataLookup2D::rows(void) const
104  {
105    return row_index_.size();
106  }
107
108
109  const DataLookup2D& DataLookup2D::operator=(const DataLookup2D& other)
110  {
111    // never copy yourself
112    if (this!=&other){
113      row_index_ = other.row_index_;
114      column_index_ = other.column_index_;
115    }
116    return *this;
117  }
118
119}}} // of namespace classifier, yat, and theplu
Note: See TracBrowser for help on using the repository browser.