00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #pragma once
00031
00032 #include "NvCloth/Callbacks.h"
00033
00034 namespace nv
00035 {
00036 namespace cloth
00037 {
00038
00039 template <class T>
00040 struct Range
00041 {
00044 Range();
00045
00052 Range(T* begin, T* end);
00053
00054 template <typename S>
00055 Range(const Range<S>& other);
00056
00057 uint32_t size() const;
00058 bool empty() const;
00059
00060 void popFront();
00061 void popBack();
00062
00063 T* begin() const;
00064 T* end() const;
00065
00066 T& front() const;
00067 T& back() const;
00068
00069 T& operator[](uint32_t i) const;
00070
00071 private:
00072 T* mBegin;
00073 T* mEnd;
00074 };
00075
00076 template <typename T>
00077 Range<T>::Range()
00078 : mBegin(0), mEnd(0)
00079 {
00080 }
00081
00082 template <typename T>
00083 Range<T>::Range(T* begin, T* end)
00084 : mBegin(begin), mEnd(end)
00085 {
00086 }
00087
00088 template <typename T>
00089 template <typename S>
00090 Range<T>::Range(const Range<S>& other)
00091 : mBegin(other.begin()), mEnd(other.end())
00092 {
00093 }
00094
00095 template <typename T>
00096 uint32_t Range<T>::size() const
00097 {
00098 return uint32_t(mEnd - mBegin);
00099 }
00100
00101 template <typename T>
00102 bool Range<T>::empty() const
00103 {
00104 return mBegin >= mEnd;
00105 }
00106
00107 template <typename T>
00108 void Range<T>::popFront()
00109 {
00110 NV_CLOTH_ASSERT(mBegin < mEnd);
00111 ++mBegin;
00112 }
00113
00114 template <typename T>
00115 void Range<T>::popBack()
00116 {
00117 NV_CLOTH_ASSERT(mBegin < mEnd);
00118 --mEnd;
00119 }
00120
00121 template <typename T>
00122 T* Range<T>::begin() const
00123 {
00124 return mBegin;
00125 }
00126
00127 template <typename T>
00128 T* Range<T>::end() const
00129 {
00130 return mEnd;
00131 }
00132
00133 template <typename T>
00134 T& Range<T>::front() const
00135 {
00136 NV_CLOTH_ASSERT(mBegin < mEnd);
00137 return *mBegin;
00138 }
00139
00140 template <typename T>
00141 T& Range<T>::back() const
00142 {
00143 NV_CLOTH_ASSERT(mBegin < mEnd);
00144 return mEnd[-1];
00145 }
00146
00147 template <typename T>
00148 T& Range<T>::operator[](uint32_t i) const
00149 {
00150 NV_CLOTH_ASSERT(mBegin + i < mEnd);
00151 return mBegin[i];
00152 }
00153
00154 }
00155 }