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

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

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