ShUtility.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 SHUTILITY_HPP
00021 #define SHUTILITY_HPP
00022 
00027 #include <iosfwd>
00028 #include <map>
00029 #include "ShDllExport.hpp"
00030 
00031 namespace SH {
00032 
00034 SH_DLLEXPORT
00035 std::ostream& shPrintIndent(std::ostream& out, int indent);
00036 
00040 template<bool B> struct ShCompileTimeChecker
00041 {
00042   ShCompileTimeChecker(...);
00043 };
00044 template<> struct ShCompileTimeChecker<false> {
00045 };
00046 
00047 #define SH_STATIC_CHECK(expr, msg) \
00048 { \
00049   class SH_ERROR_##msg {} y; \
00050   (void)sizeof(ShCompileTimeChecker<(expr)>(y));\
00051 }
00052 
00053 struct 
00054 SH_DLLEXPORT ShIgnore {
00055   template<typename T>
00056   T& operator&(T& other) { return other; }
00057 };
00058 
00060 template<bool B, typename T1, typename T2>
00061 struct SelectType;
00062 
00063 template<typename T1, typename T2>
00064 struct SelectType<true, T1, T2> {
00065   typedef T1 type;
00066 };
00067 
00068 template<typename T1, typename T2>
00069 struct SelectType<false, T1, T2> {
00070   typedef T2 type;
00071 };
00072 
00074 template<typename T1, typename T2>
00075 struct MatchType {
00076   static const bool matches = false; 
00077 };
00078 
00079 template<typename T>
00080 struct MatchType<T, T> {
00081   static const bool matches = true; 
00082 };
00083 
00084 template<typename T, typename T1, typename T2>
00085 struct MatchEitherType {
00086     static const bool matches = MatchType<T1, T>::matches ||
00087                                     MatchType<T2, T>::matches;
00088 };
00089 
00101 template<typename T, template<typename A> class B>
00102 struct MatchTemplateType {
00103     static const bool matches = false; 
00104 };
00105 
00106 template<typename T, template<typename A> class B>
00107 struct MatchTemplateType<B<T>, B> {
00108     static const bool matches = true; 
00109 };
00110 
00112 template<typename T, template<typename A> class B>
00113 struct TemplateParameterType; 
00114 
00115 template<typename T, template<typename A> class B>
00116 struct TemplateParameterType<B<T>, B> {
00117     typedef T type;
00118 };
00119 
00120 }
00121 
00122 #endif

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