NVBIO
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
static_vector.h
Go to the documentation of this file.
1 /*
2  * nvbio
3  * Copyright (c) 2011-2014, NVIDIA CORPORATION. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the NVIDIA CORPORATION nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #pragma once
29 
30 #include <nvbio/basic/types.h>
31 #include <nvbio/basic/numbers.h>
32 #include <cmath>
33 #include <limits>
34 
35 namespace nvbio {
36 
40 template <typename T, uint32 DIM>
42 {
44  const T& operator[] (const uint32 i) const { return data[i]; }
45 
47  T& operator[] (const uint32 i) { return data[i]; }
48 
49  T data[DIM];
50 };
51 
55 template <typename T>
56 struct StaticVectorBase<T,2>
57 {
59 
62 
65 
67  const T& operator[] (const uint32 i) const { return (&data.x)[i]; }
68 
70  T& operator[] (const uint32 i) { return (&data.x)[i]; }
71 
73  operator base_type() const { return data; }
74 
76 };
77 
81 template <typename T>
82 struct StaticVectorBase<T,3>
83 {
85 
88 
91 
93  const T& operator[] (const uint32 i) const { return (&data.x)[i]; }
94 
96  T& operator[] (const uint32 i) { return (&data.x)[i]; }
97 
99  operator base_type() const { return data; }
100 
102 };
103 
107 template <typename T>
108 struct StaticVectorBase<T,4>
109 {
111 
114 
117 
119  const T& operator[] (const uint32 i) const { return (&data.x)[i]; }
120 
122  T& operator[] (const uint32 i) { return (&data.x)[i]; }
123 
125  operator base_type() const { return data; }
126 
128 };
129 
133 template <typename T, uint32 DIM>
134 struct StaticVector : public StaticVectorBase<T,DIM>
135 {
138 
139  //NVBIO_FORCEINLINE NVBIO_HOST_DEVICE
140  //StaticVector(const T* v);
141 
143  explicit StaticVector(const T v);
144 
147 };
148 
149 template <typename T,uint32 DIM_T> struct vector_traits< StaticVectorBase<T,DIM_T> > { typedef T value_type; const static uint32 DIM = DIM_T; };
150 
151 template <typename T, uint32 DIM>
154 
155 template <typename T, uint32 DIM>
158 
159 template <typename T, uint32 DIM>
162 
163 template <typename T, uint32 DIM>
166 
167 template <typename T, uint32 DIM>
170 
171 template <typename T, uint32 DIM>
174 
175 template <typename T, uint32 DIM>
178 
179 template <typename T, uint32 DIM>
182 
183 template <typename T, uint32 DIM>
186 
187 template <typename T, uint32 DIM>
190 
191 template <typename T, uint32 DIM>
193 bool any(const StaticVector<T,DIM>& op);
194 
195 template <typename T, uint32 DIM>
197 bool all(const StaticVector<T,DIM>& op);
198 
199 template <typename T, uint32 DIM>
201 bool operator== (const StaticVector<T,DIM>& op1, const StaticVector<T,DIM>& op2);
202 
203 template <typename T, uint32 DIM>
205 bool operator!= (const StaticVector<T,DIM>& op1, const StaticVector<T,DIM>& op2);
206 
207 } // namespace nvbio
208