Tesseract
Motion Planning Environment
Loading...
Searching...
No Matches
vhacdSArray.h
Go to the documentation of this file.
1/* Copyright (c) 2011 Khaled Mamou (kmamou at gmail dot com)
2 All rights reserved.
3
4
5 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
6 following conditions are met:
7
8 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
9 disclaimer.
10
11 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
12 disclaimer in the documentation and/or other materials provided with the distribution.
13
14 3. The names of the contributors may not be used to endorse or promote products derived from this software without
15 specific prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25#pragma once
26
29#include <stdio.h>
30#include <stdlib.h>
31#include <string.h>
32
33#define SARRAY_DEFAULT_MIN_SIZE 16
34
35namespace tesseract_collision
36{
37namespace VHACD
38{
40template <typename T, size_t N = 64>
41class SArray
42{
43public:
44 T& operator[](size_t i)
45 {
46 T* const data = Data();
47 return data[i];
48 }
49 const T& operator[](size_t i) const
50 {
51 const T* const data = Data();
52 return data[i];
53 }
54 size_t Size() const { return m_size; }
55 T* Data() { return (m_maxSize == N) ? m_data0 : m_data; }
56 const T* Data() const { return (m_maxSize == N) ? m_data0 : m_data; }
57 void Clear()
58 {
59 m_size = 0;
60 delete[] m_data;
61 m_data = 0;
62 m_maxSize = N;
63 }
64 void PopBack() { --m_size; }
65 void Allocate(size_t size)
66 {
67 if (size > m_maxSize)
68 {
69 T* temp = new T[size];
70 memcpy(temp, Data(), m_size * sizeof(T));
71 delete[] m_data;
72 m_data = temp;
73 m_maxSize = size;
74 }
75 }
76 void Resize(size_t size)
77 {
78 Allocate(size);
79 m_size = size;
80 }
81
82 void PushBack(const T& value)
83 {
84 if (m_size == m_maxSize)
85 {
86 size_t maxSize = (m_maxSize << 1);
87 T* temp = new T[maxSize];
88 memcpy(temp, Data(), m_maxSize * sizeof(T));
89 delete[] m_data;
90 m_data = temp;
91 m_maxSize = maxSize;
92 }
93 T* const data = Data();
94 data[m_size++] = value;
95 }
96 bool Find(const T& value, size_t& pos)
97 {
98 T* const data = Data();
99 for (pos = 0; pos < m_size; ++pos)
100 if (value == data[pos])
101 return true;
102 return false;
103 }
104 bool Insert(const T& value)
105 {
106 size_t pos;
107 if (Find(value, pos))
108 return false;
110 return true;
111 }
112 bool Erase(const T& value)
113 {
114 size_t pos;
115 T* const data = Data();
116 if (Find(value, pos))
117 {
118 for (size_t j = pos + 1; j < m_size; ++j)
119 data[j - 1] = data[j];
120 --m_size;
121 return true;
122 }
123 return false;
124 }
125 void operator=(const SArray& rhs)
126 {
127 if (m_maxSize < rhs.m_size)
128 {
129 delete[] m_data;
130 m_maxSize = rhs.m_maxSize;
131 m_data = new T[m_maxSize];
132 }
133 m_size = rhs.m_size;
134 memcpy(Data(), rhs.Data(), m_size * sizeof(T));
135 }
137 {
138 m_data = 0;
139 m_size = 0;
140 m_maxSize = N;
141 }
142 SArray(const SArray& rhs)
143 {
144 m_data = 0;
145 m_size = 0;
146 m_maxSize = N;
147 *this = rhs;
148 }
150 ~SArray() { delete[] m_data; }
151
152private:
155 size_t m_size;
156 size_t m_maxSize;
157};
158} // namespace VHACD
159} // namespace tesseract_collision
SArray.
Definition: vhacdSArray.h:42
void Initialize()
Definition: vhacdSArray.h:136
size_t m_size
Definition: vhacdSArray.h:155
SArray(const SArray &rhs)
Definition: vhacdSArray.h:142
void PushBack(const T &value)
Definition: vhacdSArray.h:82
void Allocate(size_t size)
Definition: vhacdSArray.h:65
T * Data()
Definition: vhacdSArray.h:55
void Clear()
Definition: vhacdSArray.h:57
T * m_data
Definition: vhacdSArray.h:154
void operator=(const SArray &rhs)
Definition: vhacdSArray.h:125
~SArray()
Definition: vhacdSArray.h:150
T m_data0[N]
Definition: vhacdSArray.h:153
bool Erase(const T &value)
Definition: vhacdSArray.h:112
void PopBack()
Definition: vhacdSArray.h:64
void Resize(size_t size)
Definition: vhacdSArray.h:76
SArray()
Definition: vhacdSArray.h:149
const T & operator[](size_t i) const
Definition: vhacdSArray.h:49
bool Insert(const T &value)
Definition: vhacdSArray.h:104
size_t Size() const
Definition: vhacdSArray.h:54
bool Find(const T &value, size_t &pos)
Definition: vhacdSArray.h:96
size_t m_maxSize
Definition: vhacdSArray.h:156
T & operator[](size_t i)
Definition: vhacdSArray.h:44
const T * Data() const
Definition: vhacdSArray.h:56
Definition: polygon_mesh.h:46
CollisionMarginData data(default_margin)
Definition: collision_margin_data_unit.cpp:34
Common Tesseract Macros.
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
Definition: macros.h:71
Definition: create_convex_hull.cpp:36
Definition: bullet_cast_bvh_manager.h:49
object value
Definition: tesseract_common_serialization_unit.cpp:495
JointDynamics j
Definition: tesseract_scene_graph_joint_unit.cpp:15