9 #ifndef IMPKERNEL_CONST_VECTOR_H
10 #define IMPKERNEL_CONST_VECTOR_H
12 #include <IMP/kernel_config.h>
16 #include <boost/scoped_array.hpp>
20 IMPKERNEL_BEGIN_NAMESPACE
25 template <
class Data,
class SwigData = Data>
27 boost::scoped_array<Data> v_;
30 if (size() < o.size())
32 else if (size() > o.size())
34 for (
unsigned int i = 0; i < size(); ++i) {
37 else if (v_[i] > o.v_[i])
42 void create(
unsigned int sz) {
46 v_.reset(
new Data[sz]);
51 void copy_from(It b, It e) {
52 create(std::distance(b, e));
53 std::copy(b, e, v_.get());
60 std::fill(v_.get(), v_.get() + sz, fill);
67 template <
class Vector>
69 copy_from(i.begin(), i.end());
71 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
76 copy_from(o.begin(), o.end());
79 copy_from(o.begin(), o.end());
86 Data operator[](
unsigned int i)
const {
91 void set_item(
unsigned int i, SwigData v)
const {
99 SwigData __getitem__(
unsigned int i)
const {
102 return operator[](i);
104 unsigned int __len__()
const {
return sz_; }
107 unsigned int size()
const {
return sz_; }
111 for (
unsigned int i = 0; i < size(); ++i) {
118 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
119 typedef const Data *const_iterator;
120 const_iterator begin()
const {
return v_.get(); }
121 const_iterator end()
const {
return v_.get() + size(); }
123 std::swap(sz_, o.sz_);
132 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
139 IMPKERNEL_END_NAMESPACE
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
#define IMP_HASHABLE_INLINE(name, hashret)
Helper functions for implementing hashes.
#define IMP_COMPARISONS(Name)
Implement comparison in a class using a compare function.
Exception definitions and assertions.
A more IMP-like version of the std::vector.
Base class for a simple primitive-like type.
int compare(const VectorD< D > &a, const VectorD< D > &b)
lexicographic comparison of two vectors
An exception for a request for an invalid member of a container.
#define IMP_THROW(message, exception_name)
Throw an exception with a message.
Base class for a simple primitive-like type.
Store an array of values of the same type.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Helper class to aid in output of IMP classes to streams.
Various general useful macros for IMP.