cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vctFixedSizeVectorRef.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  Author(s): Ofri Sadowsky, Anton Deguet
6  Created on: 2003-09-30
7 
8  (C) Copyright 2003-2015 Johns Hopkins University (JHU), All Rights Reserved.
9 
10 --- begin cisst license - do not edit ---
11 
12 This software is provided "as is" under an open source license, with
13 no warranty. The complete license can be found in license.txt and
14 http://www.cisst.org/cisst/license.txt.
15 
16 --- end cisst license ---
17 */
18 
19 #pragma once
20 #ifndef _vctFixedSizeVectorRef_h
21 #define _vctFixedSizeVectorRef_h
22 
29 
30 
45 template <class _elementType, vct::size_type _size, vct::stride_type _stride>
47  _size, _stride, _elementType,
48  typename vctFixedSizeVectorTraits<_elementType, _size, _stride>::pointer >
49 {
50  public:
51  VCT_CONTAINER_TRAITS_TYPEDEFS(_elementType);
55  typedef typename BaseType::CopyType CopyType;
56 
57 
60 
61 
63  vctFixedSizeVectorRef(pointer p) {
64  SetRef(p);
65  }
66 
68  SetRef(other);
69  }
70 
75  template <size_type __size, class __dataPtrType>
77  size_type startPosition = 0)
78  {
79  SetRef(otherVector, startPosition);
80  }
81 
85  template<class __vectorOwnerType>
87  size_type startPosition = 0)
88  {
89  SetRef(otherVector, startPosition);
90  }
91 
92 
94  void SetRef(pointer p) {
95  this->Data = p;
96  }
97 
98  void SetRef(const ThisType & other) {
99  this->SetRef(other.Data);
100  }
101 
108  template <size_type __size, class __dataPtrType>
110  size_type startPosition = 0)
111  {
112  if (startPosition + this->size() > otherVector.size()) {
113  cmnThrow(std::out_of_range("vctFixedSizeVectorRef SetRef out of range"));
114  }
115  SetRef(otherVector.Pointer(startPosition));
116  }
117 
124  template<class __vectorOwnerType>
126  size_type startPosition = 0)
127  {
128  if (this->stride() != otherVector.stride()) {
129  cmnThrow(std::runtime_error("vctFixedSizeVectorRef SetRef with incompatible stride"));
130  }
131  if (startPosition + this->size() > otherVector.size()) {
132  cmnThrow(std::out_of_range("vctFixedSizeVectorRef SetRef out of range"));
133  }
134  SetRef(otherVector.Pointer(startPosition));
135  }
136 
137 
144  inline ThisType & operator = (const ThisType & other) {
145  return reinterpret_cast<ThisType &>(this->Assign(other));
146  }
147 
148  template <stride_type __stride>
150  return reinterpret_cast<ThisType &>(this->Assign(other));
151  }
152 
153  template <stride_type __stride, class __elementType, class __dataPtrType>
155  return reinterpret_cast<ThisType &>(this->Assign(other));
156  }
157 
158  template <class __vectorOwnerType>
160  return reinterpret_cast<ThisType &>(this->Assign(other));
161  }
163 
165  inline ThisType & operator = (const value_type & value) {
166  this->SetAll(value);
167  return *this;
168  }
169 };
170 
171 #endif // _vctFixedSizeVectorRef_h
ThisType & operator=(const ThisType &other)
Definition: vctFixedSizeVectorRef.h:144
VCT_CONTAINER_TRAITS_TYPEDEFS(_elementType)
An implementation of the ``abstract'' vctFixedSizeVectorBase.
Definition: vctFixedSizeVectorRef.h:46
void SetRef(vctFixedSizeVectorBase< __size, _stride, _elementType, __dataPtrType > &otherVector, size_type startPosition=0)
Definition: vctFixedSizeVectorRef.h:109
vctFixedSizeVectorRef(const ThisType &other)
Definition: vctFixedSizeVectorRef.h:67
An implementation of the ``abstract'' vctFixedSizeConstVectorBase.
Definition: vctFixedSizeConstVectorRef.h:50
size_t size_type
Definition: vctContainerTraits.h:35
ThisType & Assign(const vctFixedSizeConstVectorBase< _size, __stride, __elementType, __dataPtrType > &other)
Definition: vctFixedSizeVectorBase.h:274
vctFixedSizeVectorRef()
Definition: vctFixedSizeVectorRef.h:59
Implementation of a fixed-size vector using template metaprogramming.
Definition: vctFixedSizeVector.h:52
vctFixedSizeVectorRef(pointer p)
Definition: vctFixedSizeVectorRef.h:63
vctFixedSizeVectorRef< value_type, _size, _stride > ThisType
Definition: vctFixedSizeVectorRef.h:53
size_type size(void) const
Definition: vctDynamicConstVectorBase.h:164
void SetRef(pointer p)
Definition: vctFixedSizeVectorRef.h:94
vctFixedSizeVectorBase< _size, _stride, value_type, pointer > BaseType
Definition: vctFixedSizeVectorRef.h:54
Define common container related types based on the properties of a fixed size container.
Definition: vctFixedSizeVectorTraits.h:45
vctFixedSizeVectorTraits< _elementType, _size, _stride >::pointer Data
Definition: vctFixedSizeConstVectorBase.h:164
Declaration of vctFixedSizeConstVectorRef.
difference_type stride() const
Definition: vctDynamicConstVectorBase.h:169
BaseType::CopyType CopyType
Definition: vctFixedSizeVectorRef.h:55
#define cmnThrow(a)
Definition: MinimalCmn.h:4
pointer Pointer(index_type index=0)
Definition: vctDynamicVectorBase.h:155
A template for a fixed length vector with fixed spacing in memory.
Definition: vctFixedSizeVectorBase.h:76
void SetRef(vctDynamicVectorBase< __vectorOwnerType, _elementType > &otherVector, size_type startPosition=0)
Definition: vctFixedSizeVectorRef.h:125
Definition: vctDynamicConstVectorBase.h:77
A template for a fixed length vector with fixed spacing in memory.
Definition: vctFixedSizeConstVectorBase.h:107
vctFixedSizeVectorRef(vctFixedSizeVectorBase< __size, _stride, _elementType, __dataPtrType > &otherVector, size_type startPosition=0)
Definition: vctFixedSizeVectorRef.h:76
pointer Pointer(size_type index=0)
Definition: vctFixedSizeVectorBase.h:226
void SetRef(const ThisType &other)
Definition: vctFixedSizeVectorRef.h:98
vctFixedSizeVectorRef(vctDynamicVectorBase< __vectorOwnerType, _elementType > &otherVector, size_type startPosition=0)
Definition: vctFixedSizeVectorRef.h:86
Definition: vctDynamicVectorBase.h:61
vctFixedSizeVectorTraits< _elementType, _size, _stride > VectorTraits
Definition: vctFixedSizeVectorRef.h:52