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 2003-2005 Serious Hack Inc.
00004 // 
00005 // This software is provided 'as-is', without any express or implied
00006 // warranty. In no event will the authors be held liable for any damages
00007 // arising from the use of this software.
00008 // 
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it
00011 // freely, subject to the following restrictions:
00012 // 
00013 // 1. The origin of this software must not be misrepresented; you must
00014 // not claim that you wrote the original software. If you use this
00015 // software in a product, an acknowledgment in the product documentation
00016 // would be appreciated but is not required.
00017 // 
00018 // 2. Altered source versions must be plainly marked as such, and must
00019 // not be misrepresented as being the original software.
00020 // 
00021 // 3. This notice may not be removed or altered from any source
00022 // distribution.
00024 #ifndef SHGENERIC_HPP
00025 #define SHGENERIC_HPP
00026 
00027 #include "ShVariableType.hpp"
00028 #include "ShDataType.hpp"
00029 #include "ShVariable.hpp"
00030 #include "ShVariant.hpp"
00031 
00032 namespace SH {
00033 
00034 class ShProgram;
00035 
00060 template<int N, typename T>
00061 class ShGeneric : public ShVariable 
00062 {
00063 public:
00064   typedef T storage_type;
00065   static const ShValueType value_type = ShStorageTypeInfo<T>::value_type;
00066   typedef typename ShHostType<T>::type host_type; 
00067   typedef typename ShMemType<T>::type mem_type; 
00068   static const int typesize = N;
00069 
00070   typedef ShDataVariant<T, SH_HOST> VariantType; 
00071   typedef ShPointer<VariantType> VariantTypePtr;
00072   typedef ShPointer<const VariantType> VariantTypeCPtr;
00073 
00074 
00075   ShGeneric(const ShVariableNodePtr& node, ShSwizzle swizzle, bool neg);
00076   ~ShGeneric();
00077 
00078   // Copy constructor 
00079   // This should only be used internally.
00080   // It generates a ShVariableNode of type SH_TEMP 
00081   // @{
00082 
00083   // @todo type get rid of this. default should be okay for 
00084   // internal usage
00085   // ShGeneric(const ShGeneric<N, T> &other);
00086 
00087   template<typename T2>
00088   ShGeneric(const ShGeneric<N, T2> &other);
00089   // @}
00090 
00091   // This is needed because the templated assignment op is 
00092   // non-default, hence C++ spec 12.8.10 says the default
00093   // is implicitly defined.  Here that doesn't work so well. 
00094   ShGeneric& operator=(const ShGeneric& other);
00095 
00096   template<typename T2>
00097   ShGeneric& operator=(const ShGeneric<N, T2>& other);
00098 
00099   ShGeneric& operator=(const ShProgram& other);
00100 
00101   ShGeneric& operator++();
00102   ShGeneric& operator--();
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   ShGeneric& operator++();
00217   ShGeneric& operator--();
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   template<typename T2>
00232   ShGeneric& operator%=(const ShGeneric<1, T2>& right);
00233 
00234   ShGeneric& operator+=(host_type);
00235   ShGeneric& operator-=(host_type);
00236   ShGeneric& operator*=(host_type);
00237   ShGeneric& operator/=(host_type);
00238   ShGeneric& operator%=(host_type);
00239 
00240   ShGeneric operator-() const;
00241 
00242   ShGeneric operator()() const; 
00243   ShGeneric<1, T> operator()(int) const;
00244   ShGeneric<1, T> operator[](int) const;
00245   ShGeneric<2, T> operator()(int, int) const;
00246   ShGeneric<3, T> operator()(int, int, int) const;
00247   ShGeneric<4, T> operator()(int, int, int, int) const;
00248 
00250   void range(host_type low, host_type high);
00251 
00252   VariantType lowBound() const; 
00253   host_type lowBound(int index) const;
00254 
00255   VariantType highBound() const;
00256   host_type highBound(int index) const;
00257   
00258   // Arbitrary Swizzle
00259   template<int N2>
00260   ShGeneric<N2, T> swiz(int indices[]) const;
00261 
00263   void getValues(host_type dest[]) const;
00264   host_type getValue(int index) const;
00265   
00268   void setValue(int index, const host_type &value); 
00269   void setValues(const host_type values[]);
00270 
00271 protected:
00272   ShGeneric(const ShVariableNodePtr& node);
00273 
00274 };
00275 
00276 }
00277 
00278 // This is a hack for ShAttrib.hpp in particular.
00279 // A little dirty, but it works well.
00280 #ifndef SH_DO_NOT_INCLUDE_GENERIC_IMPL
00281 #include "ShGenericImpl.hpp"
00282 #endif
00283 
00284 #endif

Generated on Thu Apr 21 17:32:47 2005 for Sh by  doxygen 1.4.2