9 #ifndef IMPKERNEL_CONST_VECTOR_H
10 #define IMPKERNEL_CONST_VECTOR_H
12 #include <IMP/kernel_config.h>
17 #include <boost/scoped_array.hpp>
21 IMPKERNEL_BEGIN_NAMESPACE
26 template <
class Data,
class SwigData = Data>
28 boost::scoped_array<Data> v_;
31 if (size() < o.size())
33 else if (size() > o.size())
35 for (
unsigned int i = 0; i < size(); ++i) {
38 else if (v_[i] > o.v_[i])
43 void create(
unsigned int sz) {
47 v_.reset(
new Data[sz]);
52 void copy_from(It b, It e) {
53 create(std::distance(b, e));
54 std::copy(b, e, v_.get());
61 std::fill(v_.get(), v_.get() + sz, fill);
68 template <
class Vector>
70 copy_from(i.begin(), i.end());
72 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
77 copy_from(o.begin(), o.end());
80 copy_from(o.begin(), o.end());
87 Data operator[](
unsigned int i)
const {
92 void set_item(
unsigned int i, SwigData v)
const {
100 SwigData __getitem__(
unsigned int i)
const {
103 return operator[](i);
105 unsigned int __len__()
const {
return sz_; }
108 unsigned int size()
const {
return sz_; }
112 for (
unsigned int i = 0; i < size(); ++i) {
119 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
120 typedef const Data *const_iterator;
121 const_iterator begin()
const {
return v_.get(); }
122 const_iterator end()
const {
return v_.get() + size(); }
124 std::swap(sz_, o.sz_);
133 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
140 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.
Provide a nullptr keyword analog.
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.