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 <cereal/access.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());
57 friend class cereal::access;
59 template<
class Archive>
void serialize(Archive &ar) {
61 if (std::is_base_of<cereal::detail::InputArchiveBase, Archive>::value) {
64 for (
unsigned int i = 0; i < sz_; ++i) {
73 std::fill(v_.get(), v_.get() + sz, fill);
80 template <
class Vector>
82 copy_from(i.begin(), i.end());
84 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
89 copy_from(o.begin(), o.end());
92 copy_from(o.begin(), o.end());
99 Data operator[](
unsigned int i)
const {
104 void set_item(
unsigned int i, SwigData v)
const {
112 SwigData __getitem__(
unsigned int i)
const {
115 return operator[](i);
117 unsigned int __len__()
const {
return sz_; }
120 unsigned int size()
const {
return sz_; }
124 for (
unsigned int i = 0; i < size(); ++i) {
131 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
132 typedef const Data *const_iterator;
133 const_iterator begin()
const {
return v_.get(); }
134 const_iterator end()
const {
return v_.get() + size(); }
136 std::swap(sz_, o.sz_);
145 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
152 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.