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 library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
00018 // MA  02110-1301, USA
00020 #ifndef SHGENERIC_HPP
00021 #define SHGENERIC_HPP
00022 
00023 #include "ShVariableType.hpp"
00024 #include "ShDataType.hpp"
00025 #include "ShVariable.hpp"
00026 #include "ShVariant.hpp"
00027 
00028 namespace SH {
00029 
00030 class ShProgram;
00031 
00056 template<int N, typename T>
00057 class ShGeneric : public ShVariable 
00058 {
00059 public:
00060   typedef T storage_type;
00061   static const ShValueType value_type = ShStorageTypeInfo<T>::value_type;
00062   typedef typename ShHostType<T>::type host_type; 
00063   typedef typename ShMemType<T>::type mem_type; 
00064   static const int typesize = N;
00065 
00066   typedef ShDataVariant<T, SH_HOST> VariantType; 
00067   typedef ShPointer<VariantType> VariantTypePtr;
00068   typedef ShPointer<const VariantType> VariantTypeCPtr;
00069 
00070 
00071   ShGeneric(const ShVariableNodePtr& node, ShSwizzle swizzle, bool neg);
00072   ~ShGeneric();
00073 
00074   // Copy constructor 
00075   // This should only be used internally.
00076   // It generates a ShVariableNode of type SH_TEMP 
00077   // @{
00078 
00079   // @todo type get rid of this. default should be okay for 
00080   // internal usage
00081   // ShGeneric(const ShGeneric<N, T> &other);
00082 
00083   template<typename T2>
00084   ShGeneric(const ShGeneric<N, T2> &other);
00085   // @}
00086 
00087   // This is needed because the templated assignment op is 
00088   // non-default, hence C++ spec 12.8.10 says the default
00089   // is implicitly defined.  Here that doesn't work so well. 
00090   ShGeneric& operator=(const ShGeneric& other);
00091 
00092   template<typename T2>
00093   ShGeneric& operator=(const ShGeneric<N, T2>& other);
00094 
00095   ShGeneric& operator=(const ShProgram& other);
00096 
00097   ShGeneric& operator++();
00098   ShGeneric& operator--();
00099   
00100   template<typename T2>
00101   ShGeneric& operator+=(const ShGeneric<N, T2>& right);
00102 
00103   template<typename T2>
00104   ShGeneric& operator-=(const ShGeneric<N, T2>& right);
00105 
00106   template<typename T2>
00107   ShGeneric& operator*=(const ShGeneric<N, T2>& right);
00108 
00109   template<typename T2>
00110   ShGeneric& operator/=(const ShGeneric<N, T2>& right);
00111 
00112   template<typename T2>
00113   ShGeneric& operator%=(const ShGeneric<N, T2>& right);
00114 
00115   template<typename T2>
00116   ShGeneric& operator+=(const ShGeneric<1, T2>& right);
00117 
00118   template<typename T2>
00119   ShGeneric& operator-=(const ShGeneric<1, T2>& right);
00120 
00121   template<typename T2>
00122   ShGeneric& operator*=(const ShGeneric<1, T2>& right);
00123 
00124   template<typename T2>
00125   ShGeneric& operator/=(const ShGeneric<1, T2>& right);
00126 
00127   template<typename T2>
00128   ShGeneric& operator%=(const ShGeneric<1, T2>& right);
00129 
00130   ShGeneric& operator+=(host_type);
00131   ShGeneric& operator-=(host_type);
00132   ShGeneric& operator*=(host_type);
00133   ShGeneric& operator/=(host_type);
00134   ShGeneric& operator%=(host_type);
00135 
00136   ShGeneric operator-() const;
00137 
00138   ShGeneric operator()() const; 
00139   ShGeneric<1, T> operator()(int) const;
00140   ShGeneric<1, T> operator[](int) const;
00141   ShGeneric<2, T> operator()(int, int) const;
00142   ShGeneric<3, T> operator()(int, int, int) const;
00143   ShGeneric<4, T> operator()(int, int, int, int) const;
00144 
00146   void range(host_type low, host_type high);
00147 
00148   VariantType lowBound() const; 
00149   host_type lowBound(int index) const;
00150 
00151   VariantType highBound() const;
00152   host_type highBound(int index) const;
00153   
00154   // Arbitrary Swizzle
00155   template<int N2>
00156   ShGeneric<N2, T> swiz(int indices[]) const;
00157 
00159   void getValues(host_type dest[]) const;
00160   host_type getValue(int index) const;
00161   
00164   void setValue(int index, const host_type &value); 
00165   void setValues(const host_type values[]);
00166 
00167 
00168 protected:
00169   ShGeneric(const ShVariableNodePtr& node);
00170 
00171 };
00172 
00173 template<typename T>
00174 class ShGeneric<1, T> : public ShVariable 
00175 {
00176 public:
00177   typedef T storage_type;
00178   static const ShValueType value_type = ShStorageTypeInfo<T>::value_type;
00179   typedef typename ShHostType<T>::type host_type; 
00180   typedef typename ShMemType<T>::type mem_type; 
00181   static const int typesize = 1;
00182 
00183   typedef ShDataVariant<T, SH_HOST> VariantType; 
00184   typedef ShPointer<VariantType> VariantTypePtr;
00185   typedef ShPointer<const VariantType> VariantTypeCPtr;
00186 
00187 
00188   ShGeneric(const ShVariableNodePtr& node, ShSwizzle swizzle, bool neg);
00189   ~ShGeneric();
00190 
00191   // Copy constructor 
00192   // This should only be used internally.  It generates a SH_TEMP, 
00193   // SH_ATTRIB, with the only characteristic copied from other being
00194   // the storage type.
00195   // @{
00196 
00197   // @todo type get rid of this
00198   // ShGeneric(const ShGeneric<1, T> &other);
00199 
00200   template<typename T2>
00201   ShGeneric(const ShGeneric<1, T2> &other);
00202   // @}
00203 
00204   ShGeneric& operator=(const ShGeneric<1, T>& other);
00205 
00206   template<typename T2>
00207   ShGeneric& operator=(const ShGeneric<1, T2>& other);
00208 
00209   ShGeneric& operator=(host_type);
00210   ShGeneric& operator=(const ShProgram& other);
00211   
00212   ShGeneric& operator++();
00213   ShGeneric& operator--();
00214 
00215   template<typename T2>
00216   ShGeneric& operator+=(const ShGeneric<1, T2>& right);
00217 
00218   template<typename T2>
00219   ShGeneric& operator-=(const ShGeneric<1, T2>& right);
00220 
00221   template<typename T2>
00222   ShGeneric& operator*=(const ShGeneric<1, T2>& right);
00223 
00224   template<typename T2>
00225   ShGeneric& operator/=(const ShGeneric<1, T2>& right);
00226 
00227   template<typename T2>
00228   ShGeneric& operator%=(const ShGeneric<1, T2>& right);
00229 
00230   ShGeneric& operator+=(host_type);
00231   ShGeneric& operator-=(host_type);
00232   ShGeneric& operator*=(host_type);
00233   ShGeneric& operator/=(host_type);
00234   ShGeneric& operator%=(host_type);
00235 
00236   ShGeneric operator-() const;
00237 
00238   ShGeneric operator()() const; 
00239   ShGeneric<1, T> operator()(int) const;
00240   ShGeneric<1, T> operator[](int) const;
00241   ShGeneric<2, T> operator()(int, int) const;
00242   ShGeneric<3, T> operator()(int, int, int) const;
00243   ShGeneric<4, T> operator()(int, int, int, int) const;
00244 
00246   void range(host_type low, host_type high);
00247 
00248   VariantType lowBound() const; 
00249   host_type lowBound(int index) const;
00250 
00251   VariantType highBound() const;
00252   host_type highBound(int index) const;
00253   
00254   // Arbitrary Swizzle
00255   template<int N2>
00256   ShGeneric<N2, T> swiz(int indices[]) const;
00257 
00259   void getValues(host_type dest[]) const;
00260   host_type getValue(int index) const;
00261   
00264   void setValue(int index, const host_type &value); 
00265   void setValues(const host_type values[]);
00266 
00267 protected:
00268   ShGeneric(const ShVariableNodePtr& node);
00269 
00270 };
00271 
00272 }
00273 
00274 // This is a hack for ShAttrib.hpp in particular.
00275 // A little dirty, but it works well.
00276 #ifndef SH_DO_NOT_INCLUDE_GENERIC_IMPL
00277 #include "ShGenericImpl.hpp"
00278 #endif
00279 
00280 #endif

Generated on Thu Jul 28 17:33:02 2005 for Sh by  doxygen 1.4.3-20050530