cisst-saw
Loading...
Searching...
No Matches
vctDynamicVectorOwner.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 _vctDynamicVectorOwner_h
23#define _vctDynamicVectorOwner_h
24
29
31
35template<class _elementType>
37{
38public:
39 /* define most types from vctContainerTraits */
41
44
45 /* iterators are container specific */
46 enum { DEFAULT_STRIDE = 1 };
47#ifndef SWIG
52#endif // SWIG
53
55 : Size(0)
56 , Data(0)
57 {}
58
60 Size(0)
61 {
63 }
64
68
69 size_type size(void) const {
70 return Size;
71 }
72
73 stride_type stride(void) const
74 {
75 return DEFAULT_STRIDE;
76 }
77
78 pointer Pointer(index_type index = 0) {
79 return Data + index;
80 }
81
82 const_pointer Pointer(index_type index = 0) const {
83 return Data + index;
84 }
85
86 const_iterator begin(void) const {
87 return const_iterator(Data);
88 }
89
90 const_iterator end(void) const {
91 return const_iterator(Data + Size);
92 }
93
95 return iterator(Data);
96 }
97
98 iterator end(void) {
99 return iterator(Data + Size);
100 }
101
103 return const_reverse_iterator(Data + Size - 1);
104 }
105
107 return const_reverse_iterator(Data - 1);
108 }
109
111 return reverse_iterator(Data + Size-1);
112 }
113
115 return reverse_iterator(Data - 1);
116 }
117
127 void SetSize(size_type size) {
128 if (size == Size) return;
129 Disown();
130 Own(size, (size == 0) ? 0 : new value_type[size]);
131 }
132
138 {
139 value_type * oldData = Data;
140 Data = 0;
141 Size = 0;
142 return oldData;
143 }
144
148 value_type * Own(size_type size, value_type * data) {
149 value_type * oldData = Data;
150 Size = size;
151 Data = data;
152 return oldData;
153 }
154
158 void Disown(void) {
159 delete[] Data;
160 Size = 0;
161 Data = 0;
162 }
163
164
165protected:
166 size_type Size;
168
169private:
170 // copy constructor private to prevent any call
171 vctDynamicVectorOwner(const ThisType & CMN_UNUSED(other)) {};
172
173};
174
175
176#endif // _vctDynamicVectorOwner_h
177
reverse_iterator rend(void)
Definition vctDynamicVectorOwner.h:114
vctFixedStrideVectorIterator< value_type, DEFAULT_STRIDE > iterator
Definition vctDynamicVectorOwner.h:50
iterator begin(void)
Definition vctDynamicVectorOwner.h:94
const_iterator end(void) const
Definition vctDynamicVectorOwner.h:90
void Disown(void)
Definition vctDynamicVectorOwner.h:158
size_type size(void) const
Definition vctDynamicVectorOwner.h:69
~vctDynamicVectorOwner()
Definition vctDynamicVectorOwner.h:65
value_type * Release()
Definition vctDynamicVectorOwner.h:137
vctFixedStrideVectorConstIterator< value_type, DEFAULT_STRIDE > const_iterator
Definition vctDynamicVectorOwner.h:48
void SetSize(size_type size)
Definition vctDynamicVectorOwner.h:127
size_type Size
Definition vctDynamicVectorOwner.h:166
reverse_iterator rbegin(void)
Definition vctDynamicVectorOwner.h:110
pointer Pointer(index_type index=0)
Definition vctDynamicVectorOwner.h:78
value_type * Own(size_type size, value_type *data)
Definition vctDynamicVectorOwner.h:148
vctFixedStrideVectorIterator< value_type, -DEFAULT_STRIDE > reverse_iterator
Definition vctDynamicVectorOwner.h:51
iterator end(void)
Definition vctDynamicVectorOwner.h:98
vctDynamicVectorOwner(size_type size)
Definition vctDynamicVectorOwner.h:59
vctDynamicVectorOwner()
Definition vctDynamicVectorOwner.h:54
const_iterator begin(void) const
Definition vctDynamicVectorOwner.h:86
value_type * Data
Definition vctDynamicVectorOwner.h:167
VCT_CONTAINER_TRAITS_TYPEDEFS(_elementType)
const_pointer Pointer(index_type index=0) const
Definition vctDynamicVectorOwner.h:82
vctFixedStrideVectorConstIterator< value_type, -DEFAULT_STRIDE > const_reverse_iterator
Definition vctDynamicVectorOwner.h:49
@ DEFAULT_STRIDE
Definition vctDynamicVectorOwner.h:46
const_reverse_iterator rend(void) const
Definition vctDynamicVectorOwner.h:106
vctDynamicVectorOwner< _elementType > ThisType
Definition vctDynamicVectorOwner.h:43
stride_type stride(void) const
Definition vctDynamicVectorOwner.h:73
const_reverse_iterator rbegin(void) const
Definition vctDynamicVectorOwner.h:102
Definition vctFixedStrideVectorIterator.h:62
Definition vctFixedStrideVectorIterator.h:220
#define CMN_UNUSED(argument)
Definition cmnPortability.h:497
Declaration of vctFixedStrideVectorConstIterator and vctFixedStrideVectorIterator.