gmock-generated-internal-utils.h.pump 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. $$ -*- mode: c++; -*-
  2. $$ This is a Pump source file. Please use Pump to convert it to
  3. $$ gmock-generated-function-mockers.h.
  4. $$
  5. $var n = 10 $$ The maximum arity we support.
  6. // Copyright 2007, Google Inc.
  7. // All rights reserved.
  8. //
  9. // Redistribution and use in source and binary forms, with or without
  10. // modification, are permitted provided that the following conditions are
  11. // met:
  12. //
  13. // * Redistributions of source code must retain the above copyright
  14. // notice, this list of conditions and the following disclaimer.
  15. // * Redistributions in binary form must reproduce the above
  16. // copyright notice, this list of conditions and the following disclaimer
  17. // in the documentation and/or other materials provided with the
  18. // distribution.
  19. // * Neither the name of Google Inc. nor the names of its
  20. // contributors may be used to endorse or promote products derived from
  21. // this software without specific prior written permission.
  22. //
  23. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  25. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  26. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  27. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  28. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  29. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  30. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  31. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  32. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. //
  35. // Author: wan@google.com (Zhanyong Wan)
  36. // Google Mock - a framework for writing C++ mock classes.
  37. //
  38. // This file contains template meta-programming utility classes needed
  39. // for implementing Google Mock.
  40. #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_
  41. #define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_
  42. #include "gmock/internal/gmock-port.h"
  43. namespace testing {
  44. template <typename T>
  45. class Matcher;
  46. namespace internal {
  47. // An IgnoredValue object can be implicitly constructed from ANY value.
  48. // This is used in implementing the IgnoreResult(a) action.
  49. class IgnoredValue {
  50. public:
  51. // This constructor template allows any value to be implicitly
  52. // converted to IgnoredValue. The object has no data member and
  53. // doesn't try to remember anything about the argument. We
  54. // deliberately omit the 'explicit' keyword in order to allow the
  55. // conversion to be implicit.
  56. template <typename T>
  57. IgnoredValue(const T& /* ignored */) {} // NOLINT(runtime/explicit)
  58. };
  59. // MatcherTuple<T>::type is a tuple type where each field is a Matcher
  60. // for the corresponding field in tuple type T.
  61. template <typename Tuple>
  62. struct MatcherTuple;
  63. $range i 0..n
  64. $for i [[
  65. $range j 1..i
  66. $var typename_As = [[$for j, [[typename A$j]]]]
  67. $var As = [[$for j, [[A$j]]]]
  68. $var matcher_As = [[$for j, [[Matcher<A$j>]]]]
  69. template <$typename_As>
  70. struct MatcherTuple< ::testing::tuple<$As> > {
  71. typedef ::testing::tuple<$matcher_As > type;
  72. };
  73. ]]
  74. // Template struct Function<F>, where F must be a function type, contains
  75. // the following typedefs:
  76. //
  77. // Result: the function's return type.
  78. // ArgumentN: the type of the N-th argument, where N starts with 1.
  79. // ArgumentTuple: the tuple type consisting of all parameters of F.
  80. // ArgumentMatcherTuple: the tuple type consisting of Matchers for all
  81. // parameters of F.
  82. // MakeResultVoid: the function type obtained by substituting void
  83. // for the return type of F.
  84. // MakeResultIgnoredValue:
  85. // the function type obtained by substituting Something
  86. // for the return type of F.
  87. template <typename F>
  88. struct Function;
  89. template <typename R>
  90. struct Function<R()> {
  91. typedef R Result;
  92. typedef ::testing::tuple<> ArgumentTuple;
  93. typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
  94. typedef void MakeResultVoid();
  95. typedef IgnoredValue MakeResultIgnoredValue();
  96. };
  97. $range i 1..n
  98. $for i [[
  99. $range j 1..i
  100. $var typename_As = [[$for j [[, typename A$j]]]]
  101. $var As = [[$for j, [[A$j]]]]
  102. $var matcher_As = [[$for j, [[Matcher<A$j>]]]]
  103. $range k 1..i-1
  104. $var prev_As = [[$for k, [[A$k]]]]
  105. template <typename R$typename_As>
  106. struct Function<R($As)>
  107. : Function<R($prev_As)> {
  108. typedef A$i Argument$i;
  109. typedef ::testing::tuple<$As> ArgumentTuple;
  110. typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
  111. typedef void MakeResultVoid($As);
  112. typedef IgnoredValue MakeResultIgnoredValue($As);
  113. };
  114. ]]
  115. } // namespace internal
  116. } // namespace testing
  117. #endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_