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>
21IMPKERNEL_BEGIN_NAMESPACE
26template <
class Data,
class SwigData = Data>
27class ConstVector :
public Value {
28 boost::scoped_array<Data> v_;
30 int compare(
const ConstVector &o)
const {
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) {
71 ConstVector(
unsigned int sz, Data fill) {
73 std::fill(v_.get(), v_.get() + sz, fill);
75 ConstVector() : v_(0), sz_(0) {}
77 ConstVector(It b, It e) {
80 template <
class Vector>
81 explicit ConstVector(
const Vector &i) {
82 copy_from(i.begin(), i.end());
84#if !defined(IMP_DOXYGEN) && !defined(SWIG)
88 ConstVector(
const ConstVector<Data, SwigData> &o) : Value(), sz_(0) {
89 copy_from(o.begin(), o.end());
91 ConstVector<Data, SwigData> &operator=(
const ConstVector<Data, SwigData> &o) {
92 copy_from(o.begin(), o.end());
95 ConstVector(
int sz) { create(sz); }
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(); }
135 void swap_with(ConstVector &o) {
136 std::swap(sz_, o.sz_);
145#if !defined(IMP_DOXYGEN) && !defined(SWIG)
152IMPKERNEL_END_NAMESPACE
Base class for a simple primitive-like type.
Various general useful macros for IMP.
#define IMP_THROW(message, exception_name)
Throw an exception with a message.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Store an array of values of the same type.
An exception for a request for an invalid member of a container.
Helper class to aid in output of IMP classes to streams.
A more IMP-like version of the std::vector.
#define IMP_COMPARISONS(Name)
Implement comparison in a class using a compare function.
Exception definitions and assertions.
Helper functions for implementing hashes.
#define IMP_HASHABLE_INLINE(name, hashret)
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.