astrotypes  0.0
ReducedRankSlice.h
Go to the documentation of this file.
1 /*
2  * MIT License
3  *
4  * Copyright (c) 2018 PulsarSearchSoft
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #ifndef PSS_ASTROTYPES_MULTIARRAY_REDUCEDRANKSLICE_H
25 #define PSS_ASTROTYPES_MULTIARRAY_REDUCEDRANKSLICE_H
26 #include <tuple>
27 
28 namespace pss {
29 namespace astrotypes {
30 namespace multiarray {
31 
32 /*
33  * @brief Helper Class for Slice. Provides an interface for slices manipulated with operator[] that is consistent
34  * whichever dimension order they are called
35  * @details not intended for public use
36  */
37 
38 template<typename SliceType, typename ExcludedDim, std::size_t RankT=SliceType::rank - 1>
39 class ReducedRankSlice : public SliceType
40 {
41  typedef SliceType BaseT;
42 
43  protected:
48  friend typename iterator::BaseT;
49  friend typename iterator::ImplT;
50  friend typename const_iterator::BaseT;
51  friend typename const_iterator::ImplT;
52 
53  public:
54  static constexpr std::size_t rank = SliceType::rank - 1;
55 
56  public:
57  ReducedRankSlice(SliceType const& s) : SliceType(s) {}
58  ReducedRankSlice(SliceType&& s) : SliceType(std::forward<SliceType>(s)) {}
59 
63  iterator begin();
64  const_iterator begin() const;
65  const_iterator cbegin() const;
66 
70  iterator end();
71  const_iterator end() const;
72  const_iterator cend() const;
73 
74  template<typename Dim>
75  typename std::enable_if<!std::is_same<Dim, ExcludedDim>::value
78 
79  template<typename Dim>
80  typename std::enable_if<!std::is_same<Dim, ExcludedDim>::value
83 
87  template<typename Dim>
88  static
89  typename std::enable_if<std::is_same<Dim, ExcludedDim>::value, std::size_t>::type
90  dimension();
91 };
92 
93 template<typename SliceType, typename ExcludedDim>
94 class ReducedRankSlice<SliceType, ExcludedDim, 1> : public SliceType
95 {
96  typedef SliceType BaseT;
98 
99  public:
101  typedef typename std::iterator_traits<typename SliceType::iterator>::reference reference_type;
102  typedef typename std::iterator_traits<typename SliceType::Parent::const_iterator>::reference const_reference_type;
105 
106  private:
107  friend typename iterator::BaseT;
108  friend typename iterator::ImplT;
109  friend typename const_iterator::BaseT;
110  friend typename const_iterator::ImplT;
111 
112  public:
113  ReducedRankSlice(SliceType const& s) : BaseT(s) {}
114  ReducedRankSlice(SliceType&& s) : BaseT(std::forward<SliceType>(s)) {}
115 
119  iterator begin();
120  const_iterator begin() const;
121  const_iterator cbegin() const;
122 
126  iterator end();
127  const_iterator end() const;
128  const_iterator cend() const;
129 
133  template<typename Dim>
134  typename std::enable_if<!has_type<ExcludeTuple, Dim>::value
135  , reference_type>::type
137 
138  template<typename Dim>
139  typename std::enable_if<!has_type<ExcludeTuple, Dim>::value
140  , const_reference_type>::type
142 
146  template<typename Dim>
147  static
148  typename std::enable_if<std::is_same<Dim, ExcludedDim>::value, std::size_t>::type
149  dimension();
150 };
151 
152 } // namespace multiarray
153 } // namespace astrotypes
154 } // namespace pss
155 #include "ReducedRankSlice.cpp"
156 
157 #endif // PSS_ASTROTYPES_MULTIARRAY_REDUCEDRANKSLICE_H
produces a tuple type with params form all provided Tuples
Definition: TypeTraits.h:294
A tagged dimensionIndex variable.
SliceIteratorHelper< ReducedRankSlice, typename SliceType::iterator >::type iterator
iterator begin()
iterator pointing to the first element in the slice
STL namespace.
std::enable_if<!std::is_same< Dim, ExcludedDim >::value, ReducedRankSlice< typename SliceMixinRemover< typename SliceType::template OperatorSliceType< Dim >::type >::type, ExcludedDim > >::type operator[](DimensionIndex< Dim >)
std::iterator_traits< typename SliceType::iterator >::reference reference_type
join_tuples< typename BaseT::ExcludeTuple, std::tuple< ExcludedDim > >::type ExcludeTuple
static std::enable_if< std::is_same< Dim, ExcludedDim >::value, std::size_t >::type dimension()
the width of the slice in this dimesnion has been reduced to 1
astrotypes::tuple_diff< typename SliceType::DimensionTuple, ExcludeTuple >::type DimensionTuple
SliceIteratorHelper< ReducedRankSlice, typename SliceType::iterator >::type iterator
SliceIteratorHelper< ReducedRankSlice, typename SliceType::const_iterator >::type const_iterator
tuple_diff< typename SliceType::DimensionTuple, ExcludeTuple >::type DimensionTuple
iterator end()
iterator pointing to just after the last element
SliceIteratorHelper< ReducedRankSlice, typename SliceType::const_iterator >::type const_iterator
std::iterator_traits< typename SliceType::Parent::const_iterator >::reference const_reference_type