From 1d21940aae1e64f1ce92eef34a8561b771ce85e4 Mon Sep 17 00:00:00 2001
From: marco <marco@5a81b35b-ba03-0410-adc8-b2c5c5119f08>
Date: Thu, 8 Jul 2010 08:30:49 +0000
Subject: [PATCH] fixes and additions to PodVector

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2546 5a81b35b-ba03-0410-adc8-b2c5c5119f08
---
 modules/base/src/pod_vector.hh | 32 +++++++++++++++++++++++++++++---
 1 file changed, 29 insertions(+), 3 deletions(-)

diff --git a/modules/base/src/pod_vector.hh b/modules/base/src/pod_vector.hh
index a4da274b7..46b05bef7 100644
--- a/modules/base/src/pod_vector.hh
+++ b/modules/base/src/pod_vector.hh
@@ -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_;
-- 
GitLab