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 bool own) |
---|
18 | : ref_count_(NULL) |
---|
19 | { |
---|
20 | if (own) |
---|
21 | ref_count_ = new u_int(1); |
---|
22 | } |
---|
23 | |
---|
24 | |
---|
25 | DataLookup2D::DataLookup2D(const DataLookup2D& m, |
---|
26 | const std::vector<size_t>& row, |
---|
27 | const std::vector<size_t>& col) |
---|
28 | : ref_count_(NULL) |
---|
29 | { |
---|
30 | assert(row_index_.empty()); |
---|
31 | row_index_.reserve(row.size()); |
---|
32 | for (size_t i=0; i<row.size(); i++) { |
---|
33 | assert(row[i]<m.row_index_.size()); |
---|
34 | row_index_.push_back(m.row_index_[row[i]]); |
---|
35 | } |
---|
36 | assert(column_index_.empty()); |
---|
37 | column_index_.reserve(col.size()); |
---|
38 | for (size_t i=0; i<col.size(); i++) { |
---|
39 | assert(col[i]<m.column_index_.size()); |
---|
40 | column_index_.push_back(m.column_index_[col[i]]); |
---|
41 | } |
---|
42 | } |
---|
43 | |
---|
44 | |
---|
45 | |
---|
46 | DataLookup2D::DataLookup2D(const DataLookup2D& m, |
---|
47 | const std::vector<size_t>& index, |
---|
48 | const bool row) |
---|
49 | : ref_count_(NULL) |
---|
50 | { |
---|
51 | if (row){ |
---|
52 | assert(row_index_.empty()); |
---|
53 | row_index_.reserve(index.size()); |
---|
54 | for (size_t i=0; i<index.size(); i++) { |
---|
55 | assert(index[i]<m.row_index_.size()); |
---|
56 | row_index_.push_back(m.row_index_[index[i]]); |
---|
57 | } |
---|
58 | column_index_= m.column_index_; |
---|
59 | } |
---|
60 | else{ |
---|
61 | assert(column_index_.empty()); |
---|
62 | column_index_.reserve(index.size()); |
---|
63 | for (size_t i=0; i<index.size(); i++) { |
---|
64 | column_index_.push_back(m.column_index_[index[i]]); |
---|
65 | } |
---|
66 | row_index_= m.row_index_; |
---|
67 | } |
---|
68 | } |
---|
69 | |
---|
70 | |
---|
71 | DataLookup2D::DataLookup2D(const std::vector<size_t>& row, |
---|
72 | const std::vector<size_t>& col) |
---|
73 | : row_index_(row),column_index_(col), ref_count_(NULL) |
---|
74 | { |
---|
75 | } |
---|
76 | |
---|
77 | |
---|
78 | |
---|
79 | DataLookup2D::DataLookup2D(const DataLookup2D& mv) |
---|
80 | : row_index_(mv.row_index_),column_index_(mv.column_index_), |
---|
81 | ref_count_(NULL) |
---|
82 | { |
---|
83 | } |
---|
84 | |
---|
85 | |
---|
86 | DataLookup2D::DataLookup2D(const size_t rows, const size_t columns) |
---|
87 | : row_index_(std::vector<size_t>(rows,0)), |
---|
88 | column_index_(std::vector<size_t>(columns,0)), ref_count_(NULL) |
---|
89 | |
---|
90 | { |
---|
91 | } |
---|
92 | |
---|
93 | const DataLookup2D& DataLookup2D::operator=(const DataLookup2D& other) |
---|
94 | { |
---|
95 | // never copy yourself |
---|
96 | if (this!=&other){ |
---|
97 | row_index_ = other.row_index_; |
---|
98 | column_index_ = other.column_index_; |
---|
99 | } |
---|
100 | return *this; |
---|
101 | } |
---|
102 | |
---|
103 | }} // of namespace classifier and namespace theplu |
---|