1 | // $Id$ |
---|
2 | |
---|
3 | #include <c++_tools/classifier/DataLookup2D.h> |
---|
4 | |
---|
5 | #include <vector> |
---|
6 | |
---|
7 | #include <cassert> |
---|
8 | #ifndef NDEBUG |
---|
9 | #include <algorithm> |
---|
10 | #endif |
---|
11 | |
---|
12 | |
---|
13 | namespace theplu { |
---|
14 | namespace classifier { |
---|
15 | |
---|
16 | |
---|
17 | DataLookup2D::DataLookup2D(const DataLookup2D& m, |
---|
18 | const std::vector<size_t>& row, |
---|
19 | const std::vector<size_t>& col) |
---|
20 | : owner_(false) |
---|
21 | { |
---|
22 | assert(row_index_.empty()); |
---|
23 | row_index_.reserve(row.size()); |
---|
24 | for (size_t i=0; i<row.size(); i++) { |
---|
25 | assert(row[i]<m.row_index_.size()); |
---|
26 | row_index_.push_back(m.row_index_[row[i]]); |
---|
27 | } |
---|
28 | assert(column_index_.empty()); |
---|
29 | column_index_.reserve(col.size()); |
---|
30 | for (size_t i=0; i<col.size(); i++) { |
---|
31 | assert(col[i]<m.column_index_.size()); |
---|
32 | column_index_.push_back(m.column_index_[col[i]]); |
---|
33 | } |
---|
34 | } |
---|
35 | |
---|
36 | |
---|
37 | |
---|
38 | DataLookup2D::DataLookup2D(const DataLookup2D& m, |
---|
39 | const std::vector<size_t>& index, |
---|
40 | const bool row) |
---|
41 | : owner_(false) |
---|
42 | { |
---|
43 | if (row){ |
---|
44 | assert(row_index_.empty()); |
---|
45 | row_index_.reserve(index.size()); |
---|
46 | for (size_t i=0; i<index.size(); i++) { |
---|
47 | assert(index[i]<m.row_index_.size()); |
---|
48 | row_index_.push_back(m.row_index_[index[i]]); |
---|
49 | } |
---|
50 | column_index_= m.column_index_; |
---|
51 | } |
---|
52 | else{ |
---|
53 | assert(column_index_.empty()); |
---|
54 | column_index_.reserve(index.size()); |
---|
55 | for (size_t i=0; i<index.size(); i++) { |
---|
56 | column_index_.push_back(m.column_index_[index[i]]); |
---|
57 | } |
---|
58 | row_index_= m.row_index_; |
---|
59 | } |
---|
60 | } |
---|
61 | |
---|
62 | |
---|
63 | DataLookup2D::DataLookup2D(const std::vector<size_t>& row, |
---|
64 | const std::vector<size_t>& col, |
---|
65 | const bool owner) |
---|
66 | : row_index_(row),column_index_(col), owner_(owner) |
---|
67 | { |
---|
68 | } |
---|
69 | |
---|
70 | |
---|
71 | |
---|
72 | DataLookup2D::DataLookup2D(const DataLookup2D& mv) |
---|
73 | : row_index_(mv.row_index_),column_index_(mv.column_index_), owner_(false) |
---|
74 | { |
---|
75 | } |
---|
76 | |
---|
77 | |
---|
78 | DataLookup2D::DataLookup2D(const size_t rows, const size_t columns, |
---|
79 | const bool owner) |
---|
80 | : row_index_(std::vector<size_t>(rows,0)), |
---|
81 | column_index_(std::vector<size_t>(columns,0)), |
---|
82 | owner_(owner) |
---|
83 | { |
---|
84 | } |
---|
85 | |
---|
86 | const DataLookup2D& DataLookup2D::operator=(const DataLookup2D& other) |
---|
87 | { |
---|
88 | // never copy yourself |
---|
89 | if (this!=&other){ |
---|
90 | row_index_ = other.row_index_; |
---|
91 | column_index_ = other.column_index_; |
---|
92 | owner_=false; |
---|
93 | } |
---|
94 | return *this; |
---|
95 | } |
---|
96 | |
---|
97 | }} // of namespace classifier and namespace theplu |
---|