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 (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 SHSWIZZLE_HPP
00028 #define SHSWIZZLE_HPP
00029 
00030 #include <iosfwd>
00031 //#include <vector>
00032 #include "ShDllExport.hpp"
00033 #include "ShException.hpp"
00034 
00035 namespace SH {
00036 
00056 class
00057 SH_DLLEXPORT
00058 ShSwizzle {
00059 public:
00060 
00061   // Null swizzle
00062   ShSwizzle();
00063 
00065   ShSwizzle(int srcSize);
00067   ShSwizzle(int srcSize, int i0);
00069   ShSwizzle(int srcSize, int i0, int i1);
00071   ShSwizzle(int srcSize, int i0, int i1, int i2);
00073   ShSwizzle(int srcSize, int i0, int i1, int i2, int i3);
00075   ShSwizzle(int srcSize, int size, int* indices);
00076 
00077   ShSwizzle(const ShSwizzle& other);
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 Mon Jan 24 18:36:35 2005 for Sh by  doxygen 1.4.1