| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_VALUE_TRAITS_H_ | |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_VALUE_TRAITS_H_ | |
| 7 | |
| 8 #include "mojo/public/cpp/bindings/lib/template_util.h" | |
| 9 | |
| 10 namespace mojo { | |
| 11 | |
| 12 template <typename T> | |
| 13 class Array; | |
| 14 | |
| 15 template <typename T> | |
| 16 class AssociatedInterfacePtrInfo; | |
| 17 | |
| 18 template <typename T> | |
| 19 class AssociatedInterfaceRequest; | |
| 20 | |
| 21 template <typename T> | |
| 22 class InlinedStructPtr; | |
| 23 | |
| 24 template <typename T> | |
| 25 class InterfacePtr; | |
| 26 | |
| 27 template <typename T> | |
| 28 class InterfaceRequest; | |
| 29 | |
| 30 template <typename K, typename V> | |
| 31 class Map; | |
| 32 | |
| 33 template <typename T> | |
| 34 class ScopedHandleBase; | |
| 35 | |
| 36 template <typename T> | |
| 37 class StructPtr; | |
| 38 | |
| 39 template <typename T> | |
| 40 class WTFArray; | |
| 41 | |
| 42 namespace internal { | |
| 43 | |
| 44 template <typename T, typename Enable = void> | |
| 45 struct ValueTraits { | |
| 46 static bool Equals(const T& a, const T& b) { return a == b; } | |
| 47 }; | |
| 48 | |
| 49 template <typename T> | |
| 50 struct ValueTraits< | |
| 51 T, | |
| 52 typename EnableIf<IsSpecializationOf<Array, T>::value || | |
| 53 IsSpecializationOf<WTFArray, T>::value || | |
| 54 IsSpecializationOf<Map, T>::value || | |
| 55 IsSpecializationOf<StructPtr, T>::value || | |
| 56 IsSpecializationOf<InlinedStructPtr, T>::value>::type> { | |
| 57 static bool Equals(const T& a, const T& b) { return a.Equals(b); } | |
| 58 }; | |
| 59 | |
| 60 template <typename T> | |
| 61 struct ValueTraits<ScopedHandleBase<T>> { | |
| 62 static bool Equals(const ScopedHandleBase<T>& a, | |
| 63 const ScopedHandleBase<T>& b) { | |
| 64 return a.get().value() == b.get().value(); | |
| 65 } | |
| 66 }; | |
| 67 | |
| 68 template <typename T> | |
| 69 struct ValueTraits< | |
| 70 T, | |
| 71 typename EnableIf< | |
| 72 IsSpecializationOf<InterfaceRequest, T>::value || | |
| 73 IsSpecializationOf<AssociatedInterfaceRequest, T>::value>::type> { | |
| 74 static bool Equals(const T& a, const T& b) { | |
| 75 if (&a == &b) | |
| 76 return true; | |
| 77 | |
| 78 // Now that |a| and |b| refer to different objects, they are equivalent if | |
| 79 // and only if they are both invalid. | |
| 80 return !a.is_pending() && !b.is_pending(); | |
| 81 } | |
| 82 }; | |
| 83 | |
| 84 template <typename T> | |
| 85 struct ValueTraits<InterfacePtr<T>> { | |
| 86 static bool Equals(const InterfacePtr<T>& a, const InterfacePtr<T>& b) { | |
| 87 if (&a == &b) | |
| 88 return true; | |
| 89 | |
| 90 // Now that |a| and |b| refer to different objects, they are equivalent if | |
| 91 // and only if they are both null. | |
| 92 return !a && !b; | |
| 93 } | |
| 94 }; | |
| 95 | |
| 96 template <typename T> | |
| 97 struct ValueTraits<AssociatedInterfacePtrInfo<T>> { | |
| 98 static bool Equals(const AssociatedInterfacePtrInfo<T>& a, | |
| 99 const AssociatedInterfacePtrInfo<T>& b) { | |
| 100 if (&a == &b) | |
| 101 return true; | |
| 102 | |
| 103 // Now that |a| and |b| refer to different objects, they are equivalent if | |
| 104 // and only if they are both invalid. | |
| 105 return !a.is_valid() && !b.is_valid(); | |
| 106 } | |
| 107 }; | |
| 108 | |
| 109 } // namespace internal | |
| 110 } // namespace mojo | |
| 111 | |
| 112 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_VALUE_TRAITS_H_ | |
| OLD | NEW |