• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 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_ENUM_TRAITS_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_ENUM_TRAITS_H_
7 
8 #include "mojo/public/cpp/bindings/lib/template_util.h"
9 
10 namespace mojo {
11 
12 // This must be specialized for any type |T| to be serialized/deserialized as a
13 // mojom enum |MojomType|. Each specialization needs to implement:
14 //
15 //   template <>
16 //   struct EnumTraits<MojomType, T> {
17 //     static MojomType ToMojom(T input);
18 //
19 //     // Returning false results in deserialization failure and causes the
20 //     // message pipe receiving it to be disconnected.
21 //     static bool FromMojom(MojomType input, T* output);
22 //   };
23 //
24 template <typename MojomType, typename T>
25 struct EnumTraits {
26   static_assert(internal::AlwaysFalse<T>::value,
27                 "Cannot find the mojo::EnumTraits specialization. Did you "
28                 "forget to include the corresponding header file?");
29 };
30 
31 }  // namespace mojo
32 
33 #endif  // MOJO_PUBLIC_CPP_BINDINGS_ENUM_TRAITS_H_
34