9 #ifndef IMPKERNEL_ARRAY_H
10 #define IMPKERNEL_ARRAY_H
12 #include <IMP/kernel_config.h>
19 #include <type_traits>
20 #include <cereal/access.hpp>
21 #include <cereal/types/array.hpp>
23 IMPKERNEL_BEGIN_NAMESPACE
34 template <
unsigned int D,
class Data,
class SwigData = Data>
36 typedef std::array<Data, D> Storage;
39 friend class cereal::access;
40 template<
class Archive>
void serialize(Archive &ar) {
45 for (
unsigned int i = 0; i < D; ++i) {
48 else if (d_[i] > o.get(i))
56 typedef SwigData value_type;
58 unsigned int get_dimension() {
63 template<int DT=D, typename std::enable_if<DT == 2>::type* =
nullptr>
64 Array(SwigData x, SwigData y) {
69 template<int DT=D, typename std::enable_if<DT == 3>::type* =
nullptr>
70 Array(SwigData x, SwigData y, SwigData z) {
76 template<int DT=D, typename std::enable_if<DT == 4>::type* =
nullptr>
77 Array(SwigData x0, SwigData x1, SwigData x2, SwigData x3) {
84 SwigData
get(
unsigned int i)
const {
return d_[i]; }
87 for (
unsigned int i = 0; i < D; ++i) {
88 boost::hash_combine(seed, d_[i]);
92 const Data operator[](
unsigned int i)
const {
96 Data& operator[](
unsigned int i) {
101 void set_item(
unsigned int i, SwigData v)
const {
108 SwigData __getitem__(
unsigned int i)
const {
110 return operator[](i);
112 unsigned int __len__()
const {
return D; }
115 unsigned int size()
const {
return D; }
117 std::string get_name()
const {
118 std::ostringstream oss;
120 for (
unsigned int i = 0; i < D; ++i) {
130 typedef typename Storage::iterator iterator;
131 iterator begin() {
return d_.begin(); }
132 iterator end() {
return d_.end(); }
133 typedef typename Storage::const_iterator const_iterator;
134 const_iterator begin()
const {
return d_.begin(); }
135 const_iterator end()
const {
return d_.end(); }
145 const Data* data()
const {
154 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
155 template <
unsigned int D,
class Data,
class SwigData>
161 IMPKERNEL_END_NAMESPACE
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
Helper macros for implementing comparisons of IMP objects.
A class to store a fixed array of same-typed values.
#define IMP_HASHABLE_INLINE(name, hashret)
#define IMP_COMPARISONS(Name)
Implement comparison in a class using a compare function.
Base class for a simple primitive-like type.
int compare(const VectorD< D > &a, const VectorD< D > &b)
lexicographic comparison of two vectors
Helper macros for implementing hashable classes.
An exception for a request for an invalid member of a container.
#define IMP_THROW(message, exception_name)
Throw an exception with a message.
Helper macros for throwing and handling exceptions.
Base class for a simple primitive-like type.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Macros to help with objects that can be printed to a stream.