Skip to content
Snippets Groups Projects
Commit 1d21940a authored by marco's avatar marco
Browse files

fixes and additions to PodVector

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2546 5a81b35b-ba03-0410-adc8-b2c5c5119f08
parent 1786892b
No related branches found
No related tags found
No related merge requests found
......@@ -25,10 +25,11 @@
#include <ost/module_config.hh>
#include <cassert>
#include <memory>
#include <iterator>
#include <string>
#include <iostream>
namespace ost {
/// \brief vector container that treats its data as POD - even if it isn't in
......@@ -37,6 +38,17 @@ template <typename T>
class TEMPLATE_DEF_EXPORT PodVector {
public:
PodVector(): begin_(NULL), end_(NULL), capacity_(NULL) {}
PodVector(const PodVector<T>& rhs)
{
this->do_reserve(rhs.capacity());
this->raw_set(rhs.data(), rhs.size());
}
~PodVector()
{
if (begin_) {
free(begin_);
}
}
typedef T value_type;
typedef T& reference;
typedef const T& const_reference;
......@@ -75,7 +87,7 @@ public:
void push_back(const_reference val)
{
if (end_<=capacity_) {
if (end_>=capacity_) {
this->do_reserve(this->capacity()*2);
}
memcpy(end_, &val, sizeof(value_type));
......@@ -87,7 +99,11 @@ public:
--end_;
}
void clear() { return this->do_reserve(0); }
void clear()
{
this->do_reserve(0);
end_=begin_;
}
void reserve(size_t n)
{
......@@ -102,6 +118,16 @@ public:
{
return begin_[index];
}
T* data() { return begin_; }
const T* data() const { return begin_; }
void raw_set(T* data, size_t n)
{
this->do_reserve(n);
memcpy(begin_, data, sizeof(T)*n);
end_=begin_+n;
}
private:
void do_reserve(size_t n);
value_type* begin_;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment