9#ifndef IMPKERNEL_ARRAY_H
10#define IMPKERNEL_ARRAY_H
12#include <IMP/kernel_config.h>
20#include <cereal/access.hpp>
21#include <cereal/types/array.hpp>
23IMPKERNEL_BEGIN_NAMESPACE
39template <
unsigned int D,
class Data,
class SwigData = Data>
40class Array :
public Value {
41 typedef std::array<Data, D> Storage;
44 friend class cereal::access;
45 template<
class Archive>
void serialize(Archive &ar) {
49 int compare(
const Array<D, Data, SwigData>& o)
const {
50 for (
unsigned int i = 0; i < D; ++i) {
53 else if (d_[i] > o.get(i))
61 typedef SwigData value_type;
63 unsigned int get_dimension() {
68 template<int DT=D, typename std::enable_if<DT == 2>::type* =
nullptr>
69 Array(SwigData x, SwigData y) {
74 template<int DT=D, typename std::enable_if<DT == 3>::type* =
nullptr>
75 Array(SwigData x, SwigData y, SwigData z) {
81 template<int DT=D, typename std::enable_if<DT == 4>::type* =
nullptr>
82 Array(SwigData x0, SwigData x1, SwigData x2, SwigData x3) {
89 SwigData get(
unsigned int i)
const {
return d_[i]; }
92 for (
unsigned int i = 0; i < D; ++i) {
93 boost::hash_combine(seed, d_[i]);
97 const Data operator[](
unsigned int i)
const {
101 Data& operator[](
unsigned int i) {
106 void set_item(
unsigned int i, SwigData v)
const {
113 SwigData __getitem__(
unsigned int i)
const {
115 return operator[](i);
117 unsigned int __len__()
const {
return D; }
120 unsigned int size()
const {
return D; }
122 std::string get_name()
const {
123 std::ostringstream oss;
125 for (
unsigned int i = 0; i < D; ++i) {
136 typedef typename Storage::iterator iterator;
137 iterator begin() {
return d_.begin(); }
138 iterator end() {
return d_.end(); }
139 typedef typename Storage::const_iterator const_iterator;
140 const_iterator begin()
const {
return d_.begin(); }
141 const_iterator end()
const {
return d_.end(); }
151 const Data* data()
const {
160#if !defined(IMP_DOXYGEN) && !defined(SWIG)
161template <
unsigned int D,
class Data,
class SwigData>
162inline std::size_t hash_value(
const Array<D, Data, SwigData> &t) {
167IMPKERNEL_END_NAMESPACE
171 template <
unsigned int I,
unsigned int D,
class Data,
class SwigData>
172 const Data& get(
const IMP::Array<D, Data, SwigData> &arr) {
173 static_assert(I < D,
"array index is within bounds");
174 return *(arr.begin() + I);
177 template <
unsigned int I,
unsigned int D,
class Data,
class SwigData>
178 Data& get(IMP::Array<D, Data, SwigData> &arr) {
179 static_assert(I < D,
"array index is within bounds");
180 return *(arr.begin() + I);
Base class for a simple primitive-like type.
Helper macros for throwing and handling exceptions.
#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.
An exception for a request for an invalid member of a container.
Helper macros for implementing comparisons of IMP objects.
#define IMP_COMPARISONS(Name)
Implement comparison in a class using a compare function.
Helper macros for implementing hashable classes.
#define IMP_HASHABLE_INLINE(name, hashret)
Macros to help with objects that can be printed to a stream.
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.