ivl 679
|
00001 /* This file is part of the ivl C++ library <http://image.ntua.gr/ivl>. 00002 A C++ template library extending syntax towards mathematical notation. 00003 00004 Copyright (C) 2012 Yannis Avrithis <iavr@image.ntua.gr> 00005 Copyright (C) 2012 Kimon Kontosis <kimonas@image.ntua.gr> 00006 00007 ivl is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU Lesser General Public License 00009 version 3 as published by the Free Software Foundation. 00010 00011 Alternatively, you can redistribute it and/or modify it under the terms 00012 of the GNU General Public License version 2 as published by the Free 00013 Software Foundation. 00014 00015 ivl is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00018 See the GNU General Public License for more details. 00019 00020 You should have received a copy of the GNU General Public License 00021 and a copy of the GNU Lesser General Public License along 00022 with ivl. If not, see <http://www.gnu.org/licenses/>. */ 00023 00024 #ifndef IVL_ARRAY_DETAILS_RANGE_HPP 00025 #define IVL_ARRAY_DETAILS_RANGE_HPP 00026 00027 00028 namespace ivl { 00029 00036 template<class T> 00037 class range : public array<T, data::range<> > 00038 { 00039 private: 00040 typedef array<T, data::range<> > base_class; 00041 00042 public: 00043 typedef typename base_class::step_type step_type; 00044 00045 using base_class::first; 00046 using base_class::last; 00047 using base_class::step; 00048 00050 00051 00052 inline range(); 00053 00060 inline range(T s, T e); 00068 inline range(T s, step_type st , T e); 00070 template<class J> 00071 inline range(const range<J>& o) 00072 { 00073 first = o.first; 00074 last = o.last; 00075 step = o.step; 00076 } 00077 00083 using base_class::length; 00084 }; 00085 00086 typedef range<size_t> size_range; 00087 00088 00089 //-------------------------------------------------------------- 00090 // range CONSTRUCTORS 00091 00092 template <class T> 00093 inline 00094 range<T>::range() 00095 { 00096 first =0; 00097 last = 0; 00098 step = 0; 00099 } 00100 00101 template <class T> 00102 inline 00103 range<T>::range(T s, typename range<T>::step_type st, T e) 00104 { 00105 first = s; 00106 last = e; 00107 step = st; 00108 CHECK(!((st == 0 || (st > 0 && s > e) || (st < 0 && s < e))), erange); 00109 } 00110 00111 template <class T> 00112 inline 00113 range<T>::range(T s, T e) 00114 { 00115 //matlab like 00116 first = s; 00117 last = e; 00118 step = 1; 00119 if(e < s) 00120 last = first - 1; 00121 } 00122 00123 inline slice::slice(size_range ra) 00124 : start(ra.first), length(ra.length()), stride(ra.step) 00125 { 00126 } 00127 /* 00128 inline size_range rng(size_t s, size_t e) 00129 { 00130 return size_range(s, e); 00131 } 00132 00133 inline size_range rng(size_t s, size_range::step_type st, size_t e) 00134 { 00135 return size_range(s, st, e); 00136 } 00137 00138 */ 00139 00140 namespace core_details { 00141 00142 template<class J, class S> 00143 struct range_sup_1 00144 { 00145 J j; S s; 00146 range_sup_1(J j, S s) : j(j), s(s) {} 00147 template<class K> 00148 range<J> operator, (const K& k) { return range<J>(j, s, k); } 00149 }; 00150 00151 template<class J, class S> 00152 struct range_sup : public range<J> 00153 { 00154 J j; S s; 00155 range_sup() {} 00156 range_sup(const J& j, const S& s) : range<J>(j, s), j(j), s(s) { } 00157 }; 00158 00159 }; // namespace core_details 00160 00161 } /*namespace ivl*/ 00162 00163 00164 #endif // IVL_ARRAY_DETAILS_RANGE_HPP