ShSwizzle.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 SHSWIZZLE_HPP
00021 #define SHSWIZZLE_HPP
00022 
00023 #include <iosfwd>
00024 //#include <vector>
00025 #include "ShDllExport.hpp"
00026 #include "ShException.hpp"
00027 
00028 namespace SH {
00029 
00049 class
00050 SH_DLLEXPORT
00051 ShSwizzle {
00052 public:
00053 
00054   // Null swizzle
00055   ShSwizzle();
00056 
00058   ShSwizzle(int srcSize);
00060   ShSwizzle(int srcSize, int i0);
00062   ShSwizzle(int srcSize, int i0, int i1);
00064   ShSwizzle(int srcSize, int i0, int i1, int i2);
00066   ShSwizzle(int srcSize, int i0, int i1, int i2, int i3);
00068   ShSwizzle(int srcSize, int size, int* indices);
00069 
00070   ShSwizzle(const ShSwizzle& other);
00071 
00072   /* Construct swizzle from repeating other n times */ 
00073   ShSwizzle(const ShSwizzle& other, int n);
00074   ~ShSwizzle();
00075 
00076   ShSwizzle& operator=(const ShSwizzle& other);
00077   
00080   ShSwizzle& operator*=(const ShSwizzle& other);
00081 
00083   ShSwizzle operator*(const ShSwizzle& other) const;
00084 
00086   int size() const { return m_size; }
00087 
00091   int operator[](int i) const;
00092 
00094   bool identity() const;
00095 
00097   bool operator==(const ShSwizzle& other) const;
00098   
00099 private:
00100   // copies the other swizzle's elements 
00101   void copy(const ShSwizzle &other, bool islocal);
00102 
00103   // throws an exception if index < 0 or index >= m_srcSize
00104   void checkSrcSize(int index); 
00105 
00106   // allocates the m_indices array to current m_size
00107   // returns true 
00108   bool alloc(); 
00109 
00110   // deallocates the m_indices array 
00111   void dealloc();
00112 
00113   // returns whether we're using local 
00114   bool local() const;
00115 
00116   // returns the identity swiz value on this machine
00117   int idswiz() const;
00118 
00119   // Declare these two first so alignment problems don't make the ShSwizzle struct larger
00120   int m_srcSize;
00121   int m_size;
00122 
00123   // when srcSize <= 255 and size <= 4, use local.
00124   // local is always initialized to 0x03020101, so identity comparison is
00125   // just an integer comparison using intval
00126   union {
00127     unsigned char local[4];
00128     int intval;
00129     int* ptr;
00130   } m_index;
00131 
00132   friend SH_DLLEXPORT std::ostream& operator<<(std::ostream& out, const ShSwizzle& swizzle);
00133 };
00134 
00137 class
00138 SH_DLLEXPORT ShSwizzleException : public ShException 
00139 {
00140 public:
00141   ShSwizzleException(const ShSwizzle& s, int idx, int size);
00142 };
00143   
00144 }
00145 
00146 #include "ShSwizzleImpl.hpp"
00147   
00148 #endif

Generated on Wed Nov 9 15:29:40 2005 for Sh by  doxygen 1.4.5