cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
14 This software is provided "as is" under an open source license, with
15 no warranty. The complete license can be found in license.txt and
16 http://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 
31 
35 template<class _elementType>
37 {
38 public:
39  /* define most types from vctContainerTraits */
40  VCT_CONTAINER_TRAITS_TYPEDEFS(_elementType);
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  {
62  SetSize(size);
63  }
64 
66  Disown();
67  }
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 
94  iterator begin(void) {
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 
128  if (size == Size) return;
129  Disown();
130  Own(size, (size == 0) ? 0 : new value_type[size]);
131  }
132 
137  value_type * Release()
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 
165 protected:
167  value_type* Data;
168 
169 private:
170  // copy constructor private to prevent any call
171  vctDynamicVectorOwner(const ThisType & CMN_UNUSED(other)) {};
172 
173 };
174 
175 
176 #endif // _vctDynamicVectorOwner_h
177 
size_t index_type
Definition: vctContainerTraits.h:36
vctDynamicVectorOwner()
Definition: vctDynamicVectorOwner.h:54
Definition: vctDynamicVectorOwner.h:46
Definition: vctFixedStrideVectorIterator.h:224
iterator end(void)
Definition: vctDynamicVectorOwner.h:98
#define CMN_UNUSED(argument)
Definition: cmnPortability.h:479
const_pointer Pointer(index_type index=0) const
Definition: vctDynamicVectorOwner.h:82
const_iterator end(void) const
Definition: vctDynamicVectorOwner.h:90
value_type * Release()
Definition: vctDynamicVectorOwner.h:137
pointer Pointer(index_type index=0)
Definition: vctDynamicVectorOwner.h:78
size_t size_type
Definition: vctContainerTraits.h:35
void SetSize(size_type size)
Definition: vctDynamicVectorOwner.h:127
vctFixedStrideVectorIterator< value_type,-DEFAULT_STRIDE > reverse_iterator
Definition: vctDynamicVectorOwner.h:51
value_type * Data
Definition: vctDynamicVectorOwner.h:167
void Disown(void)
Definition: vctDynamicVectorOwner.h:158
vctFixedStrideVectorIterator< value_type, DEFAULT_STRIDE > iterator
Definition: vctDynamicVectorOwner.h:50
~vctDynamicVectorOwner()
Definition: vctDynamicVectorOwner.h:65
reverse_iterator rend(void)
Definition: vctDynamicVectorOwner.h:114
vctFixedStrideVectorConstIterator< value_type, DEFAULT_STRIDE > const_iterator
Definition: vctDynamicVectorOwner.h:48
Definition: vctFixedStrideVectorIterator.h:62
size_type size(void) const
Definition: vctDynamicVectorOwner.h:69
vctFixedStrideVectorConstIterator< value_type,-DEFAULT_STRIDE > const_reverse_iterator
Definition: vctDynamicVectorOwner.h:49
Declaration of vctFixedStrideVectorConstIterator and vctFixedStrideVectorIterator.
vctDynamicVectorOwner(size_type size)
Definition: vctDynamicVectorOwner.h:59
stride_type stride(void) const
Definition: vctDynamicVectorOwner.h:73
reverse_iterator rbegin(void)
Definition: vctDynamicVectorOwner.h:110
ptrdiff_t stride_type
Definition: vctContainerTraits.h:37
const_reverse_iterator rbegin(void) const
Definition: vctDynamicVectorOwner.h:102
vctDynamicVectorOwner< _elementType > ThisType
Definition: vctDynamicVectorOwner.h:43
value_type * Own(size_type size, value_type *data)
Definition: vctDynamicVectorOwner.h:148
Definition: vctDynamicVectorOwner.h:36
const_iterator begin(void) const
Definition: vctDynamicVectorOwner.h:86
iterator begin(void)
Definition: vctDynamicVectorOwner.h:94
VCT_CONTAINER_TRAITS_TYPEDEFS(_elementType)
size_type Size
Definition: vctDynamicVectorOwner.h:166
const_reverse_iterator rend(void) const
Definition: vctDynamicVectorOwner.h:106