9 #ifndef IMPBASE_CONST_VECTOR_H
10 #define IMPBASE_CONST_VECTOR_H
12 #include <IMP/base/base_config.h>
17 #include <boost/scoped_array.hpp>
21 IMPBASE_BEGIN_NAMESPACE
26 template <
class Data,
class SwigData=Data>
28 boost::scoped_array<Data> v_;
31 if (size() < o.size())
return -1;
32 else if (size() > o.size())
return 1;
33 for (
unsigned int i=0; i< size(); ++i) {
34 if (v_[i] < o.v_[i])
return -1;
35 else if (v_[i] > o.v_[i])
return 1;
39 void create(
unsigned int sz) {
43 v_.reset(
new Data[sz]);
48 void copy_from(It b, It e) {
49 create(std::distance(b,e));
50 std::copy(b,e, v_.get());
57 std::fill(v_.get(), v_.get()+sz, fill);
64 template <
class Vector>
66 copy_from(i.begin(), i.end());
68 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
73 copy_from(o.begin(), o.end());
76 copy_from(o.begin(), o.end());
85 Data operator[](
unsigned int i)
const {
90 void set_item(
unsigned int i, SwigData v)
const {
97 SwigData __getitem__(
unsigned int i)
const {
98 if (i >= sz_)
IMP_THROW(
"Out of bound " << i <<
" vs " << sz_,
100 return operator[](i);
102 unsigned int __len__()
const {
return sz_;}
105 unsigned int size()
const {
111 for (
unsigned int i=0; i< size(); ++i) {
113 if (i != size()-1) out <<
" ";
117 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
118 typedef const Data * const_iterator;
119 const_iterator begin()
const {
122 const_iterator end()
const {
123 return v_.get()+size();
126 std::swap(sz_, o.sz_);
136 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
143 IMPBASE_END_NAMESPACE