cisst-saw
Loading...
Searching...
No Matches
vctDynamicMatrixRefOwner.h
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3
4/*
5
6 Author(s): Ofri Sadowsky, Anton Deguet
7 Created on: 2004-07-01
8
9 (C) Copyright 2004-2007 Johns Hopkins University (JHU), All Rights
10 Reserved.
11
12--- begin cisst license - do not edit ---
13
14This software is provided "as is" under an open source license, with
15no warranty. The complete license can be found in license.txt and
16http://www.cisst.org/cisst/license.txt.
17
18--- end cisst license ---
19*/
20
21#pragma once
22#ifndef _vctDynamicMatrixRefOwner_h
23#define _vctDynamicMatrixRefOwner_h
24
29
33
38template<class _elementType>
40{
41public:
42 /* define most types from vctContainerTraits */
44 enum {DIMENSION = 2};
46
48
49 /* iterators are container specific */
54
55
57 SizesMember(0, 0),
58 StridesMember(1, 1),
59 Data(0)
60 {
61 this->UpdateCachedData();
62 }
63
64 vctDynamicMatrixRefOwner(size_type rows, size_type cols,
65 stride_type rowStride, stride_type colStride,
66 pointer data):
67 SizesMember(nsize_type(rows, cols)),
68 StridesMember(nstride_type(rowStride, colStride)),
69 Data(data)
70 {
71 this->UpdateCachedData();
72 }
73
74 void SetRef(size_type rows, size_type cols,
75 pointer dataPointer,
76 bool storageOrder) {
77 this->SetRef(rows, cols,
78 storageOrder == VCT_ROW_MAJOR ? cols : 1,
79 storageOrder == VCT_ROW_MAJOR ? 1 : rows,
80 dataPointer);
81 }
82
83 void SetRef(const nsize_type & sizes,
84 pointer dataPointer,
85 bool storageOrder) {
86 this->SetRef(sizes,
87 storageOrder == VCT_ROW_MAJOR ? sizes.Element(1) : 1,
88 storageOrder == VCT_ROW_MAJOR ? 1 : sizes.Element(0),
89 dataPointer);
90 }
91
92 void SetRef(size_type rows, size_type cols,
93 stride_type rowStride, stride_type colStride,
94 pointer data) {
95 this->SetRef(nsize_type(rows, cols), nstride_type(rowStride, colStride), data);
96 }
97
98 void SetRef(const nsize_type & sizes,
99 stride_type rowStride, stride_type colStride,
100 pointer data) {
101 this->SetRef(sizes, nstride_type(rowStride, colStride), data);
102 }
103
104 void SetRef(const nsize_type & sizes, const nstride_type & strides, pointer data) {
105 SizesMember.Assign(sizes);
106 StridesMember.Assign(strides);
107 Data = data;
108 this->UpdateCachedData();
109 }
110
111 size_type size(void) const {
112 return SizesMember.ProductOfElements();
113 }
114
115 const nsize_type & sizes(void) const {
116 return SizesMember;
117 }
118
119 size_type rows(void) const {
120 return SizesMember.Element(0);
121 }
122
123 size_type cols(void) const {
124 return SizesMember.Element(1);
125 }
126
127 const nstride_type & strides(void) const {
128 return StridesMember;
129 }
130
131 difference_type row_stride(void) const {
132 return StridesMember.Element(0);
133 }
134
135 difference_type col_stride(void) const {
136 return StridesMember.Element(1);
137 }
138
139 pointer Pointer(index_type rowIndex, index_type colIndex) {
140 return Data + rowIndex * row_stride() + colIndex * col_stride();
141 }
142
143 pointer Pointer(void) {
144 return Data;
145 }
146
147 const_pointer Pointer(index_type rowIndex, index_type colIndex) const {
148 return Data + rowIndex * row_stride() + colIndex * col_stride();
149 }
150
151 const_pointer Pointer(void) const {
152 return Data;
153 }
154
155 const_iterator begin(void) const {
157 }
158
159 const_iterator end(void) const {
161 + rows() * cols();
162 }
163
165 return iterator(Data, col_stride(), cols(), row_stride());
166 }
167
168 iterator end(void) {
169 return iterator(Data, col_stride(), cols(), row_stride())
170 + rows() * cols();
171 }
172
174 return const_reverse_iterator(Data + row_stride() * (rows() - 1) + col_stride() * (cols() - 1),
175 -col_stride(), cols(), -row_stride());
176 }
177
179 return const_reverse_iterator(Data - row_stride() + col_stride() * (cols() - 1),
180 -col_stride(), cols(), -row_stride());
181 }
182
184 return reverse_iterator(Data + row_stride() * (rows() - 1) + col_stride() * (cols() - 1),
185 -col_stride(), cols(), -row_stride());
186 }
187
189 return reverse_iterator(Data - row_stride() + col_stride() * (cols() - 1),
190 -col_stride(), cols(), -row_stride());
191 }
192
193 inline bool IsColMajor(void) const {
194 return (this->row_stride() <= this->col_stride());
195 }
196
197 inline bool IsRowMajor(void) const {
198 return (this->col_stride() <= this->row_stride());
199 }
200
201 inline bool IsCompact(void) const {
202 return IsCompactMember;
203 }
204
205 inline bool StorageOrder(void) const {
206 return this->IsRowMajor();
207 }
208
209 protected:
210 nsize_type SizesMember;
211 nstride_type StridesMember;
214
215 inline void UpdateCachedData(void) {
216 IsCompactMember = (((this->row_stride() == 1) && (this->col_stride() == static_cast<stride_type>(this->rows())))
217 || ((this->col_stride() == 1) && (this->row_stride() == static_cast<stride_type>(this->cols()))));
218 }
219
220private:
221 // copy constructor private to prevent any call
223
224};
225
226
227#endif // _vctDynamicMatrixRefOwner_h
228
vctDynamicMatrixRefOwner< value_type > ThisType
Definition vctDynamicMatrixRefOwner.h:47
@ DIMENSION
Definition vctDynamicMatrixRefOwner.h:44
void SetRef(const nsize_type &sizes, pointer dataPointer, bool storageOrder)
Definition vctDynamicMatrixRefOwner.h:83
vctVarStrideMatrixIterator< value_type > reverse_iterator
Definition vctDynamicMatrixRefOwner.h:53
size_type rows(void) const
Definition vctDynamicMatrixRefOwner.h:119
iterator end(void)
Definition vctDynamicMatrixRefOwner.h:168
size_type size(void) const
Definition vctDynamicMatrixRefOwner.h:111
const_pointer Pointer(void) const
Definition vctDynamicMatrixRefOwner.h:151
const_iterator begin(void) const
Definition vctDynamicMatrixRefOwner.h:155
bool IsColMajor(void) const
Definition vctDynamicMatrixRefOwner.h:193
bool IsRowMajor(void) const
Definition vctDynamicMatrixRefOwner.h:197
VCT_NARRAY_TRAITS_TYPEDEFS(DIMENSION)
value_type * Data
Definition vctDynamicMatrixRefOwner.h:213
reverse_iterator rend(void)
Definition vctDynamicMatrixRefOwner.h:188
vctVarStrideMatrixConstIterator< value_type > const_reverse_iterator
Definition vctDynamicMatrixRefOwner.h:51
const_iterator end(void) const
Definition vctDynamicMatrixRefOwner.h:159
nsize_type SizesMember
Definition vctDynamicMatrixRefOwner.h:210
const_pointer Pointer(index_type rowIndex, index_type colIndex) const
Definition vctDynamicMatrixRefOwner.h:147
const_reverse_iterator rbegin(void) const
Definition vctDynamicMatrixRefOwner.h:173
bool StorageOrder(void) const
Definition vctDynamicMatrixRefOwner.h:205
bool IsCompact(void) const
Definition vctDynamicMatrixRefOwner.h:201
vctDynamicMatrixRefOwner()
Definition vctDynamicMatrixRefOwner.h:56
vctVarStrideMatrixConstIterator< value_type > const_iterator
Definition vctDynamicMatrixRefOwner.h:50
bool IsCompactMember
Definition vctDynamicMatrixRefOwner.h:212
const nstride_type & strides(void) const
Definition vctDynamicMatrixRefOwner.h:127
vctDynamicMatrixRefOwner(size_type rows, size_type cols, stride_type rowStride, stride_type colStride, pointer data)
Definition vctDynamicMatrixRefOwner.h:64
difference_type row_stride(void) const
Definition vctDynamicMatrixRefOwner.h:131
nstride_type StridesMember
Definition vctDynamicMatrixRefOwner.h:211
void SetRef(const nsize_type &sizes, const nstride_type &strides, pointer data)
Definition vctDynamicMatrixRefOwner.h:104
VCT_CONTAINER_TRAITS_TYPEDEFS(_elementType)
void SetRef(size_type rows, size_type cols, stride_type rowStride, stride_type colStride, pointer data)
Definition vctDynamicMatrixRefOwner.h:92
size_type cols(void) const
Definition vctDynamicMatrixRefOwner.h:123
void SetRef(const nsize_type &sizes, stride_type rowStride, stride_type colStride, pointer data)
Definition vctDynamicMatrixRefOwner.h:98
vctVarStrideMatrixIterator< value_type > iterator
Definition vctDynamicMatrixRefOwner.h:52
difference_type col_stride(void) const
Definition vctDynamicMatrixRefOwner.h:135
const_reverse_iterator rend(void) const
Definition vctDynamicMatrixRefOwner.h:178
void SetRef(size_type rows, size_type cols, pointer dataPointer, bool storageOrder)
Definition vctDynamicMatrixRefOwner.h:74
pointer Pointer(index_type rowIndex, index_type colIndex)
Definition vctDynamicMatrixRefOwner.h:139
iterator begin(void)
Definition vctDynamicMatrixRefOwner.h:164
pointer Pointer(void)
Definition vctDynamicMatrixRefOwner.h:143
reverse_iterator rbegin(void)
Definition vctDynamicMatrixRefOwner.h:183
const nsize_type & sizes(void) const
Definition vctDynamicMatrixRefOwner.h:115
void UpdateCachedData(void)
Definition vctDynamicMatrixRefOwner.h:215
Definition vctVarStrideMatrixIterator.h:40
Definition vctVarStrideMatrixIterator.h:283
#define CMN_UNUSED(argument)
Definition cmnPortability.h:497
vctDynamicConstMatrixBase< _matrixOwnerType, _elementType > ThisType
Definition vctDynamicConstMatrixBase.h:86
Declaration of vctDynamicMatrixOwner.
Forward declarations and #define for cisstVector.
const bool VCT_ROW_MAJOR
Definition vctForwardDeclarations.h:41
Declaration of vctVarStrideMatrixConstIterator and vctVarStrideMatrixIterator.