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

ShUtility.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 SHUTILITY_HPP
00028 #define SHUTILITY_HPP
00029 
00034 #include <iosfwd>
00035 #include <map>
00036 #include "ShDllExport.hpp"
00037 
00038 namespace SH {
00039 
00041 SH_DLLEXPORT
00042 std::ostream& shPrintIndent(std::ostream& out, int indent);
00043 
00047 template<bool B> struct ShCompileTimeChecker
00048 {
00049   ShCompileTimeChecker(...);
00050 };
00051 template<> struct ShCompileTimeChecker<false> {
00052 };
00053 
00054 #define SH_STATIC_CHECK(expr, msg) \
00055 { \
00056   class SH_ERROR_##msg {} y; \
00057   (void)sizeof(ShCompileTimeChecker<(expr)>(y));\
00058 }
00059 
00060 struct 
00061 SH_DLLEXPORT ShIgnore {
00062   template<typename T>
00063   T& operator&(T& other) { return other; }
00064 };
00065 
00067 template<bool B, typename T1, typename T2>
00068 struct SelectType;
00069 
00070 template<typename T1, typename T2>
00071 struct SelectType<true, T1, T2> {
00072   typedef T1 type;
00073 };
00074 
00075 template<typename T1, typename T2>
00076 struct SelectType<false, T1, T2> {
00077   typedef T2 type;
00078 };
00079 
00081 template<typename T1, typename T2>
00082 struct MatchType {
00083   static const bool matches = false; 
00084 };
00085 
00086 template<typename T>
00087 struct MatchType<T, T> {
00088   static const bool matches = true; 
00089 };
00090 
00091 template<typename T, typename T1, typename T2>
00092 struct MatchEitherType {
00093     static const bool matches = MatchType<T1, T>::matches ||
00094                                     MatchType<T2, T>::matches;
00095 };
00096 
00108 template<typename T, template<typename A> class B>
00109 struct MatchTemplateType {
00110     static const bool matches = false; 
00111 };
00112 
00113 template<typename T, template<typename A> class B>
00114 struct MatchTemplateType<B<T>, B> {
00115     static const bool matches = true; 
00116 };
00117 
00119 template<typename T, template<typename A> class B>
00120 struct TemplateParameterType; 
00121 
00122 template<typename T, template<typename A> class B>
00123 struct TemplateParameterType<B<T>, B> {
00124     typedef T type;
00125 };
00126 
00127 }
00128 
00129 #endif

Generated on Mon Jan 24 18:36:36 2005 for Sh by  doxygen 1.4.1