1$$ -*- mode: c++; -*- 2$var n = 50 $$ Maximum length of type lists we want to support. 3// Copyright 2008 Google Inc. 4// All Rights Reserved. 5// 6// Redistribution and use in source and binary forms, with or without 7// modification, are permitted provided that the following conditions are 8// met: 9// 10// * Redistributions of source code must retain the above copyright 11// notice, this list of conditions and the following disclaimer. 12// * Redistributions in binary form must reproduce the above 13// copyright notice, this list of conditions and the following disclaimer 14// in the documentation and/or other materials provided with the 15// distribution. 16// * Neither the name of Google Inc. nor the names of its 17// contributors may be used to endorse or promote products derived from 18// this software without specific prior written permission. 19// 20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31// 32// Author: wan@google.com (Zhanyong Wan) 33 34// Type utilities needed for implementing typed and type-parameterized 35// tests. This file is generated by a SCRIPT. DO NOT EDIT BY HAND! 36// 37// Currently we support at most $n types in a list, and at most $n 38// type-parameterized tests in one type-parameterized test case. 39// Please contact googletestframework@googlegroups.com if you need 40// more. 41 42#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_ 43#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_ 44 45#include "gtest/internal/gtest-port.h" 46#include "gtest/internal/gtest-string.h" 47 48// #ifdef __GNUC__ is too general here. It is possible to use gcc without using 49// libstdc++ (which is where cxxabi.h comes from). 50# ifdef __GLIBCXX__ 51# include <cxxabi.h> 52# endif // __GLIBCXX__ 53 54namespace testing { 55namespace internal { 56 57// GetTypeName<T>() returns a human-readable name of type T. 58// NB: This function is also used in Google Mock, so don't move it inside of 59// the typed-test-only section below. 60template <typename T> 61String GetTypeName() { 62# if GTEST_HAS_RTTI 63 64 const char* const name = typeid(T).name(); 65# ifdef __GLIBCXX__ 66 int status = 0; 67 // gcc's implementation of typeid(T).name() mangles the type name, 68 // so we have to demangle it. 69 char* const readable_name = abi::__cxa_demangle(name, 0, 0, &status); 70 const String name_str(status == 0 ? readable_name : name); 71 free(readable_name); 72 return name_str; 73# else 74 return name; 75# endif // __GLIBCXX__ 76 77# else 78 79 return "<type>"; 80 81# endif // GTEST_HAS_RTTI 82} 83 84#if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P 85 86// AssertyTypeEq<T1, T2>::type is defined iff T1 and T2 are the same 87// type. This can be used as a compile-time assertion to ensure that 88// two types are equal. 89 90template <typename T1, typename T2> 91struct AssertTypeEq; 92 93template <typename T> 94struct AssertTypeEq<T, T> { 95 typedef bool type; 96}; 97 98// A unique type used as the default value for the arguments of class 99// template Types. This allows us to simulate variadic templates 100// (e.g. Types<int>, Type<int, double>, and etc), which C++ doesn't 101// support directly. 102struct None {}; 103 104// The following family of struct and struct templates are used to 105// represent type lists. In particular, TypesN<T1, T2, ..., TN> 106// represents a type list with N types (T1, T2, ..., and TN) in it. 107// Except for Types0, every struct in the family has two member types: 108// Head for the first type in the list, and Tail for the rest of the 109// list. 110 111// The empty type list. 112struct Types0 {}; 113 114// Type lists of length 1, 2, 3, and so on. 115 116template <typename T1> 117struct Types1 { 118 typedef T1 Head; 119 typedef Types0 Tail; 120}; 121 122$range i 2..n 123 124$for i [[ 125$range j 1..i 126$range k 2..i 127template <$for j, [[typename T$j]]> 128struct Types$i { 129 typedef T1 Head; 130 typedef Types$(i-1)<$for k, [[T$k]]> Tail; 131}; 132 133 134]] 135 136} // namespace internal 137 138// We don't want to require the users to write TypesN<...> directly, 139// as that would require them to count the length. Types<...> is much 140// easier to write, but generates horrible messages when there is a 141// compiler error, as gcc insists on printing out each template 142// argument, even if it has the default value (this means Types<int> 143// will appear as Types<int, None, None, ..., None> in the compiler 144// errors). 145// 146// Our solution is to combine the best part of the two approaches: a 147// user would write Types<T1, ..., TN>, and Google Test will translate 148// that to TypesN<T1, ..., TN> internally to make error messages 149// readable. The translation is done by the 'type' member of the 150// Types template. 151 152$range i 1..n 153template <$for i, [[typename T$i = internal::None]]> 154struct Types { 155 typedef internal::Types$n<$for i, [[T$i]]> type; 156}; 157 158template <> 159struct Types<$for i, [[internal::None]]> { 160 typedef internal::Types0 type; 161}; 162 163$range i 1..n-1 164$for i [[ 165$range j 1..i 166$range k i+1..n 167template <$for j, [[typename T$j]]> 168struct Types<$for j, [[T$j]]$for k[[, internal::None]]> { 169 typedef internal::Types$i<$for j, [[T$j]]> type; 170}; 171 172]] 173 174namespace internal { 175 176# define GTEST_TEMPLATE_ template <typename T> class 177 178// The template "selector" struct TemplateSel<Tmpl> is used to 179// represent Tmpl, which must be a class template with one type 180// parameter, as a type. TemplateSel<Tmpl>::Bind<T>::type is defined 181// as the type Tmpl<T>. This allows us to actually instantiate the 182// template "selected" by TemplateSel<Tmpl>. 183// 184// This trick is necessary for simulating typedef for class templates, 185// which C++ doesn't support directly. 186template <GTEST_TEMPLATE_ Tmpl> 187struct TemplateSel { 188 template <typename T> 189 struct Bind { 190 typedef Tmpl<T> type; 191 }; 192}; 193 194# define GTEST_BIND_(TmplSel, T) \ 195 TmplSel::template Bind<T>::type 196 197// A unique struct template used as the default value for the 198// arguments of class template Templates. This allows us to simulate 199// variadic templates (e.g. Templates<int>, Templates<int, double>, 200// and etc), which C++ doesn't support directly. 201template <typename T> 202struct NoneT {}; 203 204// The following family of struct and struct templates are used to 205// represent template lists. In particular, TemplatesN<T1, T2, ..., 206// TN> represents a list of N templates (T1, T2, ..., and TN). Except 207// for Templates0, every struct in the family has two member types: 208// Head for the selector of the first template in the list, and Tail 209// for the rest of the list. 210 211// The empty template list. 212struct Templates0 {}; 213 214// Template lists of length 1, 2, 3, and so on. 215 216template <GTEST_TEMPLATE_ T1> 217struct Templates1 { 218 typedef TemplateSel<T1> Head; 219 typedef Templates0 Tail; 220}; 221 222$range i 2..n 223 224$for i [[ 225$range j 1..i 226$range k 2..i 227template <$for j, [[GTEST_TEMPLATE_ T$j]]> 228struct Templates$i { 229 typedef TemplateSel<T1> Head; 230 typedef Templates$(i-1)<$for k, [[T$k]]> Tail; 231}; 232 233 234]] 235 236// We don't want to require the users to write TemplatesN<...> directly, 237// as that would require them to count the length. Templates<...> is much 238// easier to write, but generates horrible messages when there is a 239// compiler error, as gcc insists on printing out each template 240// argument, even if it has the default value (this means Templates<list> 241// will appear as Templates<list, NoneT, NoneT, ..., NoneT> in the compiler 242// errors). 243// 244// Our solution is to combine the best part of the two approaches: a 245// user would write Templates<T1, ..., TN>, and Google Test will translate 246// that to TemplatesN<T1, ..., TN> internally to make error messages 247// readable. The translation is done by the 'type' member of the 248// Templates template. 249 250$range i 1..n 251template <$for i, [[GTEST_TEMPLATE_ T$i = NoneT]]> 252struct Templates { 253 typedef Templates$n<$for i, [[T$i]]> type; 254}; 255 256template <> 257struct Templates<$for i, [[NoneT]]> { 258 typedef Templates0 type; 259}; 260 261$range i 1..n-1 262$for i [[ 263$range j 1..i 264$range k i+1..n 265template <$for j, [[GTEST_TEMPLATE_ T$j]]> 266struct Templates<$for j, [[T$j]]$for k[[, NoneT]]> { 267 typedef Templates$i<$for j, [[T$j]]> type; 268}; 269 270]] 271 272// The TypeList template makes it possible to use either a single type 273// or a Types<...> list in TYPED_TEST_CASE() and 274// INSTANTIATE_TYPED_TEST_CASE_P(). 275 276template <typename T> 277struct TypeList { typedef Types1<T> type; }; 278 279 280$range i 1..n 281template <$for i, [[typename T$i]]> 282struct TypeList<Types<$for i, [[T$i]]> > { 283 typedef typename Types<$for i, [[T$i]]>::type type; 284}; 285 286#endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P 287 288} // namespace internal 289} // namespace testing 290 291#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_ 292