ndarray
NumPy-friendly multidimensional arrays in C++
Loading...
Searching...
No Matches
ExpressionBase.h
Go to the documentation of this file.
1// -*- c++ -*-
2/*
3 * Copyright (c) 2010-2012, Jim Bosch
4 * All rights reserved.
5 *
6 * ndarray is distributed under a simple BSD-like license;
7 * see the LICENSE file that should be present in the root
8 * of the source distribution, or alternately available at:
9 * https://github.com/ndarray/ndarray
10 */
11#ifndef NDARRAY_ExpressionBase_h_INCLUDED
12#define NDARRAY_ExpressionBase_h_INCLUDED
13
21#include "ndarray/Vector.h"
22
23namespace ndarray {
24
39template <typename Derived>
41public:
55 typedef Derived Self;
56
58 Reference operator[](Size n) const { return getSelf().operator[](n); }
59
61 Reference front() const { return this->operator[](0); }
62
64 Reference back() const { return this->operator[](this->template getSize<0>()-1); }
65
67 Iterator begin() const { return getSelf().begin(); }
68
70 Iterator end() const { return getSelf().end(); }
71
73 template <int P> Size getSize() const { return getSelf().template getSize<P>(); }
74
76 Index getShape() const { return getSelf().getShape(); }
77
79 Size getNumElements() const { return getSelf().getNumElements(); }
80
81 /* ------------------------- STL Compatibility -------------------------- */
82
83 typedef Value value_type;
84 typedef Iterator iterator;
85 typedef Iterator const_iterator;
86 typedef Reference reference;
87 typedef Reference const_reference;
88 typedef Iterator pointer;
89 typedef Offset difference_type;
90 typedef Size size_type;
91
93 size_type size() const { return this->template getSize<0>(); }
94
96 bool empty() const { return this->template getSize<0>() == 0; }
97
98 /* ---------------------------------------------------------------------- */
99
100protected:
101 Self & getSelf() { return *static_cast<Self *>(this); }
102 Self const & getSelf() const { return *static_cast<Self const *>(this); }
103};
104
105} // namespace ndarray
106
107#endif // !NDARRAY_ExpressionBase_h_INCLUDED
Traits for Expression.
Definition for Vector.
CRTP base class for all multidimensional expressions.
Definition ExpressionBase.h:40
ExpressionTraits< Derived >::Value Value
Nested expression or element value type.
Definition ExpressionBase.h:51
size_type size() const
Return the size of the first dimension.
Definition ExpressionBase.h:93
Reference front() const
Return the first nested expression or element.
Definition ExpressionBase.h:61
Reference back() const
Return the last nested expression or element.
Definition ExpressionBase.h:64
Vector< Size, ND::value > Index
Vector type for N-dimensional indices.
Definition ExpressionBase.h:53
Reference operator[](Size n) const
Return a single nested expression or element.
Definition ExpressionBase.h:58
ExpressionTraits< Derived >::ND ND
Number of dimensions (boost::mpl::int_).
Definition ExpressionBase.h:45
ExpressionTraits< Derived >::Reference Reference
Nested expression or element reference.
Definition ExpressionBase.h:49
Index getShape() const
Return a Vector of the sizes of all dimensions.
Definition ExpressionBase.h:76
Size getNumElements() const
Return the total number of elements in the expression.
Definition ExpressionBase.h:79
ExpressionTraits< Derived >::Element Element
Data type of expression elements.
Definition ExpressionBase.h:43
Iterator end() const
Return an Iterator to one past the end of the expression.
Definition ExpressionBase.h:70
Iterator begin() const
Return an Iterator to the beginning of the expression.
Definition ExpressionBase.h:67
Derived Self
CRTP derived type.
Definition ExpressionBase.h:55
bool empty() const
Return true if the first dimension has no elements.
Definition ExpressionBase.h:96
ExpressionTraits< Derived >::Iterator Iterator
Nested expression or element iterator.
Definition ExpressionBase.h:47
Size getSize() const
Return the size of a specific dimension.
Definition ExpressionBase.h:73
Traits for expressions.
Definition ExpressionTraits.h:30
A fixed-size 1D array class.
Definition Vector.h:82