33#if __GNUC__ < 5 && !defined(__clang__)
37 align(
size_t alignment,
size_t bytes,
void*& bufferPlace,
size_t& bufferSpace)
noexcept
39 const auto uiptr =
reinterpret_cast<uintptr_t
>(bufferPlace);
40 const auto alignedPlace = (uiptr - 1u + alignment) & -alignment;
41 const auto spaceRequired = alignedPlace - uiptr;
42 if ((bytes + spaceRequired) > bufferSpace)
48 bufferSpace -= spaceRequired;
49 return bufferPlace =
reinterpret_cast<void*
>(alignedPlace);
64 return begin_ == current_;
70 return storage_ !=
nullptr;
76 return static_cast<const std::uint8_t*
>(end_) -
77 static_cast<const std::uint8_t*
>(current_);
83 return static_cast<const std::uint8_t*
>(end_) -
84 static_cast<const std::uint8_t*
>(begin_);
90 return static_cast<const std::uint8_t*
>(current_) -
91 static_cast<const std::uint8_t*
>(begin_);
116 storage_.reset(
new std::uint8_t[sz]);
117 begin_ =
static_cast<void*
>(storage_.get());
119 end_ =
static_cast<void*
>(storage_.get() + sz);
123 template <
class Derived>
128 std::is_base_of<Base, Derived>::value,
129 "HeterogenousContinuousContainerBase::pushBack: Derived must derive Base");
132 void* ptr =
std::align(d->_alignof(), d->_sizeof(), current_, space_);
138 current_ =
static_cast<void*
>(
static_cast<std::uint8_t*
>(ptr) + d->_sizeof());
139 return d->_placementCopyConstruct(ptr);
149 std::unique_ptr<std::uint8_t[]> storage_{
nullptr};
150 void* begin_{
nullptr};
151 void* current_{
nullptr};
158 template <
class Base,
bool UsePropagateConst = true>
165 typename std::conditional<UsePropagateConst, PropagateConst<Base*>, Base*>::type;
171 bool compressElems =
false)
206 return elements_.size();
212 return elements_.capacity();
225 if (elements_.capacity() > cnt)
228 elements_ = std::vector<ElementType>{};
230 elements_.reserve(cnt);
233 template <
class Derived>
238 std::is_base_of<Base, Derived>::value,
239 "HeterogenousContinuousContainerBase::pushBack: Derived must derive Base");
248 elements_.emplace_back(ptr);
253 template <
class Derived>
260 template <
class Derived>
267 std::vector<ElementType>&
273 const std::vector<ElementType>&
282 for (
auto& e : elements_)
291 std::vector<ElementType> elements_;
294 template <
class Base,
bool UsePropagateConst = true>
302 typename std::conditional<UsePropagateConst, PropagateConst<Base*>, Base*>::type;
308 bool compressElems =
false)
312 std::vector<std::size_t> elemCaps;
313 elemCaps.reserve(other.
elements().size());
314 for (
const auto& d1 : other.
elements())
316 elemCaps.emplace_back(compressElems ? d1.size() : d1.capacity());
319 for (std::size_t i = 0; i < other.
elements().size(); ++i)
321 for (
auto& e : other.
elements().at(i))
335 std::vector<std::size_t> elemCaps;
336 elemCaps.reserve(other.
elements().size());
337 for (
const auto& d1 : other.
elements())
339 elemCaps.emplace_back(d1.capacity());
342 for (std::size_t i = 0; i < other.
elements().size(); ++i)
344 for (
auto& e : other.
elements().at(i))
360 return elements_.at(d0).size();
366 return elements_.at(d0).capacity();
379 elements_.resize(cnt.size());
380 for (std::size_t i = 0; i < cnt.size(); ++i)
382 if (elements_.at(i).capacity() > cnt)
385 elements_.at(i) = std::vector<ElementType>{};
387 elements_.at(i).reserve(cnt.at(i));
391 template <
class Derived>
396 std::is_base_of<Base, Derived>::value,
397 "HeterogenousContinuousContainerBase::pushBack: Derived must derive Base");
406 elements_.at(d0).emplace_back(ptr);
411 template <
class Derived>
418 template <
class Derived>
425 std::vector<std::vector<ElementType>>&
431 const std::vector<std::vector<ElementType>>&
440 for (
auto& d1 : elements_)
452 std::vector<std::vector<ElementType>> elements_;
~HeterogenousContinuous2DContainer()
std::size_t getRemainingElementCapacity(std::size_t d0) const
std::size_t getElementCount(std::size_t d0) const
HeterogenousContinuous2DContainer & operator=(const HeterogenousContinuous2DContainer &other)
typename std::conditional< UsePropagateConst, PropagateConst< Base * >, Base * >::type ElementType
std::vector< std::vector< ElementType > > & elements()
void setElementCapacity(const std::vector< std::size_t > &cnt)
HeterogenousContinuous2DContainer(HeterogenousContinuous2DContainer &&)=default
Base * pushBack(std::size_t d0, const Derived &d)
HeterogenousContinuous2DContainer(const HeterogenousContinuous2DContainer &other, bool compressElems=false)
Base * pushBack(std::size_t d0, const Derived *d)
const std::vector< std::vector< ElementType > > & elements() const
std::size_t getElementCapacity(std::size_t d0) const
HeterogenousContinuous2DContainer & operator=(HeterogenousContinuous2DContainer &&)=default
HeterogenousContinuous2DContainer()=default
Base * pushBack(std::size_t d0, const PropagateConst< Derived * > &d)
std::size_t getRemainingElementCapacity() const
HeterogenousContinuousContainer()=default
std::size_t getElementCount() const
HeterogenousContinuousContainer & operator=(const HeterogenousContinuousContainer &other)
std::size_t getElementCapacity() const
typename std::conditional< UsePropagateConst, PropagateConst< Base * >, Base * >::type ElementType
void setElementCapacity(std::size_t cnt)
Base * pushBack(const Derived *d)
HeterogenousContinuousContainer(const HeterogenousContinuousContainer &other, bool compressElems=false)
HeterogenousContinuousContainer(HeterogenousContinuousContainer &&)=default
Base * pushBack(const PropagateConst< Derived * > &d)
~HeterogenousContinuousContainer()
Base * pushBack(const Derived &d)
std::vector< ElementType > & elements()
HeterogenousContinuousContainer & operator=(HeterogenousContinuousContainer &&)=default
const std::vector< ElementType > & elements() const
Wrapper for a pointer to propagate const to the pointed to value.
std::size_t getRemainingStorageCapacity() const
std::size_t getUsedStorageCapacity() const
void setStorageCapacity(std::size_t sz)
Base * pushBack(const Derived *d)
void assignStorage(void *begin, void *end)
std::size_t getStorageCapacity() const
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_CHECK_LESS_EQUAL(lhs, rhs)
This macro evaluates whether lhs is less or equal (<=) rhs and if it turns out to be false it will th...
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
This file offers overloads of toIce() and fromIce() functions for STL container types.
void * align(size_t alignment, size_t bytes, void *&bufferPlace, size_t &bufferSpace) noexcept