ShVariable.hpp

00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright 2003-2006 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 SHVARIABLE_HPP
00021 #define SHVARIABLE_HPP
00022 
00023 #include "ShDllExport.hpp"
00024 #include "ShRefCount.hpp"
00025 #include "ShSwizzle.hpp"
00026 #include "ShUtility.hpp"
00027 #include "ShMetaForwarder.hpp"
00028 #include "ShVariant.hpp"
00029 #include "ShVariableNode.hpp"
00030 
00031 namespace SH {
00032 
00033 class ShProgram;
00034 
00041 class 
00042 SH_DLLEXPORT ShVariable : public ShMetaForwarder {
00043 public:
00044   ShVariable();
00045   ShVariable(const ShVariableNodePtr& node);
00046   ShVariable(const ShVariableNodePtr& node, const ShSwizzle& swizzle, bool neg);
00047 
00048   ~ShVariable() {}
00049 
00050   /* Executes a program and assigns the result to this variable.
00051    *
00052    * In retained mode, the prg gets inserted into the ShProgram currently
00053    * being defined.
00054    */
00055   ShVariable& operator=(const ShProgram& prg);
00056  
00057   /* Attaches a ShProgram to this variable, making it a dependent uniform. */
00058   void attach(const ShProgram& prg);
00059   
00060   bool null() const; 
00061   
00062   bool uniform() const; 
00063   bool hasValues() const; 
00064 
00065   
00066   int size() const; 
00067 
00068                     
00069   ShValueType valueType() const; 
00070 
00076 
00077   
00079   // TODO check if this works when swizzle contains one index more than once
00080   void rangeVariant(const ShVariant* low, const ShVariant* high);
00081 
00083   // @{
00084   ShVariantPtr lowBoundVariant() const;
00085 
00087   ShVariantPtr highBoundVariant() const;
00088 
00090   
00092   const ShSwizzle& swizzle() const;
00093 
00095   const ShVariableNodePtr& node() const;
00096 
00098   bool neg() const;
00099 
00100   bool& neg();
00101 
00103   
00105   ShVariantPtr getVariant() const;
00106   ShVariantPtr getVariant(int index) const;
00107 
00123   bool loadVariant(ShVariant *&result) const;
00124   void updateVariant();
00125   // @}
00126 
00127   
00132   void setVariant(const ShVariant* other, bool neg, const ShSwizzle &writemask); 
00133   void setVariant(const ShVariantCPtr& other, bool neg, const ShSwizzle &writemask); 
00134   // @}
00135  
00139   void setVariant(const ShVariant* other, int index); 
00140   void setVariant(const ShVariantCPtr& other, int index); 
00141   // @}
00142 
00146   void setVariant(const ShVariant* other);
00147   void setVariant(const ShVariantCPtr& other);
00148   // @}
00149 
00150 
00151   ShVariable operator()() const; 
00152   ShVariable operator()(int) const;
00153   ShVariable operator()(int, int) const;
00154   ShVariable operator()(int, int, int) const;
00155   ShVariable operator()(int, int, int, int) const;
00156   ShVariable operator()(int size, int indices[]) const;
00157   ShVariable operator()(const ShSwizzle &swizzle) const;
00158 
00159   
00160   ShVariable operator-() const;
00161 
00162   bool operator==(const ShVariable& other) const;
00163   bool operator!=(const ShVariable& other) const { return !((*this) == other); }
00164 
00168   void clone(const ShVariable& other);
00169   
00170 protected:
00171   
00172   ShVariableNodePtr m_node; 
00173   ShSwizzle m_swizzle; 
00174   bool m_neg; 
00175 
00176   friend SH_DLLEXPORT std::ostream& operator<<(std::ostream& out, const ShVariable& shVariableToPrint);
00177 };
00178 
00179 }
00180 
00181 #endif

Generated on Thu Feb 16 14:51:39 2006 for Sh by  doxygen 1.4.6