88
99#pragma once
1010
11+ #include < CL/sycl/detail/helpers.hpp>
12+ #include < CL/sycl/detail/item_base.hpp>
13+ #include < CL/sycl/detail/type_traits.hpp>
1114#include < CL/sycl/id.hpp>
1215#include < CL/sycl/range.hpp>
13- #include < stdexcept>
14- #include < type_traits>
1516
1617namespace cl {
1718namespace sycl {
@@ -20,93 +21,66 @@ class Builder;
2021}
2122template <int dimensions> class id ;
2223template <int dimensions> class range ;
23- template <int dimensions> class h_item ;
2424
2525template <int dimensions = 1 , bool with_offset = true > class item {
2626public:
2727 item () = delete ;
2828
29- id<dimensions> get_id () const { return index ; }
29+ id<dimensions> get_id () const { return MImpl. MIndex ; }
3030
31- size_t get_id (int dimension) const { return index [dimension]; }
31+ size_t get_id (int dimension) const { return MImpl. MIndex [dimension]; }
3232
33- size_t operator [](int dimension) const { return index [dimension]; }
33+ size_t operator [](int dimension) const { return MImpl. MIndex [dimension]; }
3434
35- range<dimensions> get_range () const { return extent ; }
35+ range<dimensions> get_range () const { return MImpl. MExtent ; }
3636
37- size_t get_range (int dimension) const { return extent. get ( dimension) ; }
37+ size_t get_range (int dimension) const { return MImpl. MExtent [ dimension] ; }
3838
39- // only available if with_offset is true;
40- template <bool W = with_offset,
41- typename = typename std::enable_if<(W == true )>::type>
42- id<dimensions> get_offset () const {
43- return offset;
39+ template <bool has_offset = with_offset>
40+ detail::enable_if_t <has_offset, id<dimensions>> get_offset () const {
41+ return MImpl.MOffset ;
4442 }
4543
46- template <bool W = with_offset>
47- operator typename std::enable_if<W == false , item<dimensions, true >>::type()
48- const {
49- return item<dimensions, true >(extent, index, offset);
44+ template <bool has_offset = with_offset>
45+ detail::enable_if_t <has_offset, size_t > get_offset (int dimension) const {
46+ return MImpl.MOffset [dimension];
5047 }
5148
52- /* The following member function is only available in the id class
53- * specialization where: dimensions>0 and dimensions<4 */
54- template <int N = dimensions,
55- typename = typename std::enable_if<((N > 0 ) && (N < 4 ))>::type>
56- size_t get_linear_id () const {
57- if (1 == dimensions) {
58- return index[0 ] - offset[0 ];
59- }
60- if (2 == dimensions) {
61- return (index[0 ] - offset[0 ]) * extent[1 ] + (index[1 ] - offset[1 ]);
62- }
63- return ((index[0 ] - offset[0 ]) * extent[1 ] * extent[2 ]) +
64- ((index[1 ] - offset[1 ]) * extent[2 ]) + (index[2 ] - offset[2 ]);
49+ template <bool has_offset = with_offset>
50+ operator detail::enable_if_t <!has_offset, item<dimensions, true >>() const {
51+ return detail::Builder::createItem<dimensions, true >(
52+ MImpl.MExtent , MImpl.MIndex , /* Offset*/ {});
6553 }
6654
67- item<dimensions, with_offset>(const item<dimensions, with_offset> &rhs) =
68- default ;
55+ size_t get_linear_id () const { return MImpl.get_linear_id (); }
6956
70- item<dimensions, with_offset>( item<dimensions, with_offset> & &rhs) = default ;
57+ item ( const item &rhs) = default ;
7158
72- item<dimensions, with_offset> &
73- operator =(const item<dimensions, with_offset> &rhs) = default ;
59+ item (item<dimensions, with_offset> &&rhs) = default ;
7460
75- item<dimensions, with_offset> &
76- operator =(item<dimensions, with_offset> &&rhs) = default ;
61+ item &operator =(const item &rhs) = default ;
7762
78- bool operator ==(const item<dimensions, with_offset> &rhs) const {
79- return (rhs.index == this ->index ) && (rhs.extent == this ->extent ) &&
80- (rhs.offset == this ->offset );
81- }
63+ item &operator =(item &&rhs) = default ;
8264
83- bool operator !=(const item<dimensions, with_offset> &rhs) const {
84- return !((*this ) == rhs);
85- }
65+ bool operator ==(const item &rhs) const { return rhs.MImpl == MImpl; }
8666
87- protected:
88- // For call constructor inside conversion operator
89- friend class item <dimensions, false >;
90- friend class item <dimensions, true >;
91- friend class h_item <dimensions>;
92- friend class detail ::Builder;
67+ bool operator !=(const item &rhs) const { return rhs.MImpl != MImpl; }
9368
94- template <size_t W = with_offset>
95- item (typename std::enable_if<(W == true ), const range<dimensions>>::type &R,
96- const id<dimensions> &I, const id<dimensions> &O)
97- : extent(R), index(I), offset(O) {}
69+ protected:
70+ template <bool has_offset = with_offset>
71+ item (detail::enable_if_t <has_offset, const range<dimensions>> &extent,
72+ const id<dimensions> &index, const id<dimensions> &offset)
73+ : MImpl{extent, index, offset} {}
9874
99- template <size_t W = with_offset>
100- item (typename std::enable_if<(W == false ) , const range<dimensions>>::type &R ,
101- const id<dimensions> &I )
102- : extent(R) , index(I), offset() {}
75+ template <bool has_offset = with_offset>
76+ item (detail:: enable_if_t <!has_offset , const range<dimensions>> &extent ,
77+ const id<dimensions> &index )
78+ : MImpl{ extent, index} {}
10379
104- void setID ( const id<dimensions> &ID) { index = ID; }
80+ friend struct detail ::Builder;
10581
10682private:
107- range<dimensions> extent;
108- id<dimensions> index;
109- id<dimensions> offset;
83+ detail::ItemBase<dimensions, with_offset> MImpl;
11084};
11185
11286} // namespace sycl
0 commit comments