9 #ifndef IMPKERNEL_CONST_VECTOR_H
10 #define IMPKERNEL_CONST_VECTOR_H
12 #include <IMP/kernel_config.h>
16 #include <boost/scoped_array.hpp>
17 #include <boost/serialization/access.hpp>
18 #include <boost/serialization/split_member.hpp>
22 IMPKERNEL_BEGIN_NAMESPACE
27 template <
class Data,
class SwigData = Data>
29 boost::scoped_array<Data> v_;
32 if (size() < o.size())
34 else if (size() > o.size())
36 for (
unsigned int i = 0; i < size(); ++i) {
39 else if (v_[i] > o.v_[i])
44 void create(
unsigned int sz) {
48 v_.reset(
new Data[sz]);
53 void copy_from(It b, It e) {
54 create(std::distance(b, e));
55 std::copy(b, e, v_.get());
59 friend class boost::serialization::access;
61 template<
class Archive>
void save(Archive &ar,
const unsigned int)
const {
63 for (
unsigned int i = 0; i < sz_; ++i) {
68 template<
class Archive>
void load(Archive &ar,
const unsigned int) {
71 for (
unsigned int i = 0; i < sz_; ++i) {
76 BOOST_SERIALIZATION_SPLIT_MEMBER()
83 std::fill(v_.get(), v_.get() + sz, fill);
90 template <
class Vector>
92 copy_from(i.begin(), i.end());
94 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
99 copy_from(o.begin(), o.end());
102 copy_from(o.begin(), o.end());
109 Data operator[](
unsigned int i)
const {
114 void set_item(
unsigned int i, SwigData v)
const {
122 SwigData __getitem__(
unsigned int i)
const {
125 return operator[](i);
127 unsigned int __len__()
const {
return sz_; }
130 unsigned int size()
const {
return sz_; }
134 for (
unsigned int i = 0; i < size(); ++i) {
141 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
142 typedef const Data *const_iterator;
143 const_iterator begin()
const {
return v_.get(); }
144 const_iterator end()
const {
return v_.get() + size(); }
146 std::swap(sz_, o.sz_);
155 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
162 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.