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

Generated on Wed Jun 15 18:12:42 2005 for Sh by  doxygen 1.4.3-20050530