1 |
/* |
/* |
2 |
* Copyright (c) 2014 Christian Schoenebeck |
* Copyright (c) 2014 - 2019 Christian Schoenebeck |
3 |
* |
* |
4 |
* http://www.linuxsampler.org |
* http://www.linuxsampler.org |
5 |
* |
* |
41 |
* |
* |
42 |
* @param capacity - maximum size this object may ever grow |
* @param capacity - maximum size this object may ever grow |
43 |
*/ |
*/ |
44 |
ConstCapacityArray(int capacity) : |
ConstCapacityArray(ssize_t capacity) : |
45 |
m_data(new T[capacity]), m_capacity(capacity), m_size(0) {} |
m_data(new T[capacity]), m_capacity(capacity), m_size(0) {} |
46 |
|
|
47 |
/** |
/** |
63 |
* |
* |
64 |
* @see capacity() |
* @see capacity() |
65 |
*/ |
*/ |
66 |
inline uint size() const { |
inline size_t size() const { |
67 |
return m_size; |
return m_size; |
68 |
} |
} |
69 |
|
|
76 |
* |
* |
77 |
* @see size() |
* @see size() |
78 |
*/ |
*/ |
79 |
inline uint capacity() const { |
inline size_t capacity() const { |
80 |
return m_capacity; |
return m_capacity; |
81 |
} |
} |
82 |
|
|
115 |
* @param index - position where element(s) shall be removed |
* @param index - position where element(s) shall be removed |
116 |
* @param count - amount of elements to be removed |
* @param count - amount of elements to be removed |
117 |
*/ |
*/ |
118 |
inline void remove(uint index, uint count = 1) { |
inline void remove(size_t index, size_t count = 1) { |
119 |
if (index >= m_size || index + count > m_size) |
if (index >= m_size || index + count > m_size) |
120 |
return; |
return; |
121 |
// don't use memmove() here! Since it is not RT safe with all libc |
// don't use memmove() here! Since it is not RT safe with all libc |
122 |
// implementations and on all architectures |
// implementations and on all architectures |
123 |
for (uint i = 0; i < count; ++i) |
for (size_t i = 0; i < count; ++i) |
124 |
m_data[index + i] = m_data[index + i + count]; |
m_data[index + i] = m_data[index + i + count]; |
125 |
m_size -= count; |
m_size -= count; |
126 |
} |
} |
132 |
* @param value - value to be searched for |
* @param value - value to be searched for |
133 |
*/ |
*/ |
134 |
bool contains(const T& value) const { |
bool contains(const T& value) const { |
135 |
for (uint i = 0; i < m_size; ++i) |
for (size_t i = 0; i < m_size; ++i) |
136 |
if (m_data[i] == value) return true; |
if (m_data[i] == value) return true; |
137 |
return false; |
return false; |
138 |
} |
} |
145 |
* @param value - value to be searched for |
* @param value - value to be searched for |
146 |
* @returns index of found element |
* @returns index of found element |
147 |
*/ |
*/ |
148 |
uint find(const T& value) const { |
size_t find(const T& value) const { |
149 |
for (uint i = 0; i < m_size; ++i) |
for (size_t i = 0; i < m_size; ++i) |
150 |
if (m_data[i] == value) return i; |
if (m_data[i] == value) return i; |
151 |
return -1; |
return -1; |
152 |
} |
} |
172 |
* |
* |
173 |
* @param index - position of array to access |
* @param index - position of array to access |
174 |
*/ |
*/ |
175 |
inline T& operator[](uint index) { |
inline T& operator[](size_t index) { |
176 |
return m_data[index]; |
return m_data[index]; |
177 |
} |
} |
178 |
|
|
185 |
* |
* |
186 |
* @param index - position of array to access |
* @param index - position of array to access |
187 |
*/ |
*/ |
188 |
inline const T& operator[](uint index) const { |
inline const T& operator[](size_t index) const { |
189 |
return m_data[index]; |
return m_data[index]; |
190 |
} |
} |
191 |
|
|
192 |
private: |
private: |
193 |
T* __restrict const m_data; |
T* __restrict const m_data; |
194 |
int m_capacity; |
ssize_t m_capacity; |
195 |
int m_size; |
ssize_t m_size; |
196 |
}; |
}; |
197 |
|
|
198 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |