Main Page   Class List   Class Members  

  • Main Page
  • Modules
  • Classes
  • Files
  • File List

Range.h

Go to the documentation of this file.
00001 // This code contains NVIDIA Confidential Information and is disclosed to you
00002 // under a form of NVIDIA software license agreement provided separately to you.
00003 //
00004 // Notice
00005 // NVIDIA Corporation and its licensors retain all intellectual property and
00006 // proprietary rights in and to this software and related documentation and
00007 // any modifications thereto. Any use, reproduction, disclosure, or
00008 // distribution of this software and related documentation without an express
00009 // license agreement from NVIDIA Corporation is strictly prohibited.
00010 //
00011 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
00012 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
00013 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
00014 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
00015 //
00016 // Information and code furnished is believed to be accurate and reliable.
00017 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
00018 // information or for any infringement of patents or other rights of third parties that may
00019 // result from its use. No license is granted by implication or otherwise under any patent
00020 // or patent rights of NVIDIA Corporation. Details are subject to change without notice.
00021 // This code supersedes and replaces all information previously supplied.
00022 // NVIDIA Corporation products are not authorized for use as critical
00023 // components in life support devices or systems without express written approval of
00024 // NVIDIA Corporation.
00025 //
00026 // Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved.
00027 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
00028 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
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; // past last element (like std::vector::end())
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 } // namespace cloth
00155 } // namespace nv
Copyright © 2016-2017 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com