Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ShGeneric.hpp

00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright (c) 2003 University of Waterloo Computer Graphics Laboratory
00004 // Project administrator: Michael D. McCool
00005 // Authors: Zheng Qin, Stefanus Du Toit, Kevin Moule, Tiberiu S. Popa,
00006 //          Michael D. McCool
00007 // 
00008 // This software is provided 'as-is', without any express or implied
00009 // warranty. In no event will the authors be held liable for any damages
00010 // arising from the use of this software.
00011 // 
00012 // Permission is granted to anyone to use this software for any purpose,
00013 // including commercial applications, and to alter it and redistribute it
00014 // freely, subject to the following restrictions:
00015 // 
00016 // 1. The origin of this software must not be misrepresented; you must
00017 // not claim that you wrote the original software. If you use this
00018 // software in a product, an acknowledgment in the product documentation
00019 // would be appreciated but is not required.
00020 // 
00021 // 2. Altered source versions must be plainly marked as such, and must
00022 // not be misrepresented as being the original software.
00023 // 
00024 // 3. This notice may not be removed or altered from any source
00025 // distribution.
00027 #ifndef SHGENERIC_HPP
00028 #define SHGENERIC_HPP
00029 
00030 #include "ShVariableType.hpp"
00031 #include "ShDataType.hpp"
00032 #include "ShVariable.hpp"
00033 #include "ShVariant.hpp"
00034 
00035 namespace SH {
00036 
00037 class ShProgram;
00038 
00063 template<int N, typename T>
00064 class ShGeneric : public ShVariable 
00065 {
00066 public:
00067   typedef T storage_type;
00068   static const ShValueType value_type = ShStorageTypeInfo<T>::value_type;
00069   typedef typename ShHostType<T>::type host_type; 
00070   typedef typename ShMemType<T>::type mem_type; 
00071   static const int typesize = N;
00072 
00073   typedef ShDataVariant<T, SH_HOST> VariantType; 
00074   typedef ShPointer<VariantType> VariantTypePtr;
00075   typedef ShPointer<const VariantType> VariantTypeCPtr;
00076 
00077 
00078   ShGeneric(const ShVariableNodePtr& node, ShSwizzle swizzle, bool neg);
00079   ~ShGeneric();
00080 
00081   // Copy constructor 
00082   // This should only be used internally.
00083   // It generates a ShVariableNode of type SH_TEMP 
00084   // @{
00085 
00086   // @todo type get rid of this. default should be okay for 
00087   // internal usage
00088   // ShGeneric(const ShGeneric<N, T> &other);
00089 
00090   template<typename T2>
00091   ShGeneric(const ShGeneric<N, T2> &other);
00092   // @}
00093 
00094   // This is needed because the templated assignment op is 
00095   // non-default, hence C++ spec 12.8.10 says the default
00096   // is implicitly defined.  Here that doesn't work so well. 
00097   ShGeneric& operator=(const ShGeneric& other);
00098 
00099   template<typename T2>
00100   ShGeneric& operator=(const ShGeneric<N, T2>& other);
00101 
00102   ShGeneric& operator=(const ShProgram& other);
00103   
00104   template<typename T2>
00105   ShGeneric& operator+=(const ShGeneric<N, T2>& right);
00106 
00107   template<typename T2>
00108   ShGeneric& operator-=(const ShGeneric<N, T2>& right);
00109 
00110   template<typename T2>
00111   ShGeneric& operator*=(const ShGeneric<N, T2>& right);
00112 
00113   template<typename T2>
00114   ShGeneric& operator/=(const ShGeneric<N, T2>& right);
00115 
00116   template<typename T2>
00117   ShGeneric& operator%=(const ShGeneric<N, T2>& right);
00118 
00119   template<typename T2>
00120   ShGeneric& operator+=(const ShGeneric<1, T2>& right);
00121 
00122   template<typename T2>
00123   ShGeneric& operator-=(const ShGeneric<1, T2>& right);
00124 
00125   template<typename T2>
00126   ShGeneric& operator*=(const ShGeneric<1, T2>& right);
00127 
00128   template<typename T2>
00129   ShGeneric& operator/=(const ShGeneric<1, T2>& right);
00130 
00131   template<typename T2>
00132   ShGeneric& operator%=(const ShGeneric<1, T2>& right);
00133 
00134   ShGeneric& operator+=(host_type);
00135   ShGeneric& operator-=(host_type);
00136   ShGeneric& operator*=(host_type);
00137   ShGeneric& operator/=(host_type);
00138   ShGeneric& operator%=(host_type);
00139 
00140   ShGeneric operator-() const;
00141 
00142   ShGeneric operator()() const; 
00143   ShGeneric<1, T> operator()(int) const;
00144   ShGeneric<1, T> operator[](int) const;
00145   ShGeneric<2, T> operator()(int, int) const;
00146   ShGeneric<3, T> operator()(int, int, int) const;
00147   ShGeneric<4, T> operator()(int, int, int, int) const;
00148 
00150   void range(host_type low, host_type high);
00151 
00152   VariantType lowBound() const; 
00153   host_type lowBound(int index) const;
00154 
00155   VariantType highBound() const;
00156   host_type highBound(int index) const;
00157   
00158   // Arbitrary Swizzle
00159   template<int N2>
00160   ShGeneric<N2, T> swiz(int indices[]) const;
00161 
00163   void getValues(host_type dest[]) const;
00164   host_type getValue(int index) const;
00165   
00168   void setValue(int index, const host_type &value); 
00169   void setValues(const host_type values[]);
00170 
00171 
00172 protected:
00173   ShGeneric(const ShVariableNodePtr& node);
00174 
00175 };
00176 
00177 template<typename T>
00178 class ShGeneric<1, T> : public ShVariable 
00179 {
00180 public:
00181   typedef T storage_type;
00182   static const ShValueType value_type = ShStorageTypeInfo<T>::value_type;
00183   typedef typename ShHostType<T>::type host_type; 
00184   typedef typename ShMemType<T>::type mem_type; 
00185   static const int typesize = 1;
00186 
00187   typedef ShDataVariant<T, SH_HOST> VariantType; 
00188   typedef ShPointer<VariantType> VariantTypePtr;
00189   typedef ShPointer<const VariantType> VariantTypeCPtr;
00190 
00191 
00192   ShGeneric(const ShVariableNodePtr& node, ShSwizzle swizzle, bool neg);
00193   ~ShGeneric();
00194 
00195   // Copy constructor 
00196   // This should only be used internally.  It generates a SH_TEMP, 
00197   // SH_ATTRIB, with the only characteristic copied from other being
00198   // the storage type.
00199   // @{
00200 
00201   // @todo type get rid of this
00202   // ShGeneric(const ShGeneric<1, T> &other);
00203 
00204   template<typename T2>
00205   ShGeneric(const ShGeneric<1, T2> &other);
00206   // @}
00207 
00208   ShGeneric& operator=(const ShGeneric<1, T>& other);
00209 
00210   template<typename T2>
00211   ShGeneric& operator=(const ShGeneric<1, T2>& other);
00212 
00213   ShGeneric& operator=(host_type);
00214   ShGeneric& operator=(const ShProgram& other);
00215   
00216   template<typename T2>
00217   ShGeneric& operator+=(const ShGeneric<1, T2>& right);
00218 
00219   template<typename T2>
00220   ShGeneric& operator-=(const ShGeneric<1, T2>& right);
00221 
00222   template<typename T2>
00223   ShGeneric& operator*=(const ShGeneric<1, T2>& right);
00224 
00225   template<typename T2>
00226   ShGeneric& operator/=(const ShGeneric<1, T2>& right);
00227 
00228   template<typename T2>
00229   ShGeneric& operator%=(const ShGeneric<1, T2>& right);
00230 
00231   ShGeneric& operator+=(host_type);
00232   ShGeneric& operator-=(host_type);
00233   ShGeneric& operator*=(host_type);
00234   ShGeneric& operator/=(host_type);
00235   ShGeneric& operator%=(host_type);
00236 
00237   ShGeneric operator-() const;
00238 
00239   ShGeneric operator()() const; 
00240   ShGeneric<1, T> operator()(int) const;
00241   ShGeneric<1, T> operator[](int) const;
00242   ShGeneric<2, T> operator()(int, int) const;
00243   ShGeneric<3, T> operator()(int, int, int) const;
00244   ShGeneric<4, T> operator()(int, int, int, int) const;
00245 
00247   void range(host_type low, host_type high);
00248 
00249   VariantType lowBound() const; 
00250   host_type lowBound(int index) const;
00251 
00252   VariantType highBound() const;
00253   host_type highBound(int index) const;
00254   
00255   // Arbitrary Swizzle
00256   template<int N2>
00257   ShGeneric<N2, T> swiz(int indices[]) const;
00258 
00260   void getValues(host_type dest[]) const;
00261   host_type getValue(int index) const;
00262   
00265   void setValue(int index, const host_type &value); 
00266   void setValues(const host_type values[]);
00267 
00268 protected:
00269   ShGeneric(const ShVariableNodePtr& node);
00270 
00271 };
00272 
00273 }
00274 
00275 // This is a hack for ShAttrib.hpp in particular.
00276 // A little dirty, but it works well.
00277 #ifndef SH_DO_NOT_INCLUDE_GENERIC_IMPL
00278 #include "ShGenericImpl.hpp"
00279 #endif
00280 
00281 #endif

Generated on Mon Jan 24 18:36:31 2005 for Sh by  doxygen 1.4.1