
#ifndef PLS_ALIGNED_STACK_IMPL_H
#define PLS_ALIGNED_STACK_IMPL_H

namespace pls {
namespace internal {
namespace data_structures {

template<typename T>
T *aligned_stack::push(const T &object) {
  // Copy-Construct
  return new(push < T > ())T(object);
}

template<typename T>
void *aligned_stack::push() {
  void *result = reinterpret_cast<T *>(head_);

  // Move head to next aligned position after new object
  head_ = base::alignment::next_alignment(head_ + sizeof(T));
  if (head_ >= memory_end_) {
    PLS_ERROR("Tried to allocate object on alligned_stack without sufficient memory!");
  }

  return result;
}

template<typename T>
T aligned_stack::pop() {
  head_ = head_ - base::alignment::next_alignment(sizeof(T));
  return *reinterpret_cast<T *>(head_);
}

}
}
}

#endif //PLS_ALIGNED_STACK_IMPL_H
