ViennaCL - The Vienna Computing Library
1.5.1
|
00001 #ifndef VIENNACL_SLICE_HPP_ 00002 #define VIENNACL_SLICE_HPP_ 00003 00004 /* ========================================================================= 00005 Copyright (c) 2010-2014, Institute for Microelectronics, 00006 Institute for Analysis and Scientific Computing, 00007 TU Wien. 00008 Portions of this software are copyright by UChicago Argonne, LLC. 00009 00010 ----------------- 00011 ViennaCL - The Vienna Computing Library 00012 ----------------- 00013 00014 Project Head: Karl Rupp rupp@iue.tuwien.ac.at 00015 00016 (A list of authors and contributors can be found in the PDF manual) 00017 00018 License: MIT (X11), see file LICENSE in the base directory 00019 ============================================================================= */ 00020 00025 #include <vector> 00026 #include <stddef.h> 00027 #include <assert.h> 00028 #include "viennacl/forwards.h" 00029 00030 namespace viennacl 00031 { 00032 00037 template <typename SizeType /* see forwards.h for default argument*/, 00038 typename DistanceType /* see forwards.h for default argument*/> 00039 class basic_slice 00040 { 00041 public: 00042 typedef SizeType size_type; 00043 typedef DistanceType difference_type; 00044 typedef size_type value_type; 00045 typedef value_type const_reference; 00046 typedef const_reference reference; 00047 00048 basic_slice() : start_(0), stride_(1), size_(0) {} 00049 basic_slice(size_type start_index, 00050 difference_type stride_arg, 00051 size_type size_arg) : start_(start_index), stride_(stride_arg), size_(size_arg) {} 00052 00053 00054 size_type start() const { return start_; } 00055 difference_type stride() const { return stride_; } 00056 size_type size() const { return size_; } 00057 00058 const_reference operator()(size_type i) const 00059 { 00060 assert(i < size()); 00061 return start_ + i * stride_; 00062 } 00063 const_reference operator[](size_type i) const { return operator()(i); } 00064 00065 bool operator==(const basic_slice & s) const { return (start_ == s.start_) && (stride_ == s.stride_) && (size_ == s.size_); } 00066 bool operator!=(const basic_slice & s) const { return !(*this == s); } 00067 00068 private: 00069 size_type start_; 00070 difference_type stride_; 00071 size_type size_; 00072 }; 00073 00074 00075 } 00076 00077 #endif