Roll src/third_party/WebKit f298044:aa8346d (svn 202628:202629)
[chromium-blink-merge.git] / ipc / param_traits_macros.h
blob317f31228d993f2d26aa0e8eeb5d9ab21c9aa620
1 // Copyright (c) 2012 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.
5 #ifndef IPC_PARAM_TRAITS_MACROS_H_
6 #define IPC_PARAM_TRAITS_MACROS_H_
8 #include <string>
10 // Traits generation for structs.
11 #define IPC_STRUCT_TRAITS_BEGIN(struct_name) \
12 namespace IPC { \
13 template <> \
14 struct IPC_MESSAGE_EXPORT ParamTraits<struct_name> { \
15 typedef struct_name param_type; \
16 static void Write(Message* m, const param_type& p); \
17 static bool Read(const Message* m, base::PickleIterator* iter, \
18 param_type* p); \
19 static void Log(const param_type& p, std::string* l); \
20 }; \
23 #define IPC_STRUCT_TRAITS_MEMBER(name)
24 #define IPC_STRUCT_TRAITS_PARENT(type)
25 #define IPC_STRUCT_TRAITS_END()
27 // Convenience macro for defining enumerated type traits for types which are
28 // not range-checked by the IPC system. The author of the message handlers
29 // is responsible for all validation. This macro should not need to be
30 // subsequently redefined.
31 #define IPC_ENUM_TRAITS(type) \
32 IPC_ENUM_TRAITS_VALIDATE(type, true)
34 // Convenience macro for defining enumerated type traits for types which are
35 // range-checked by the IPC system to be in the range of 0..maxvalue inclusive.
36 // This macro should not need to be subsequently redefined.
37 #define IPC_ENUM_TRAITS_MAX_VALUE(type, maxvalue) \
38 IPC_ENUM_TRAITS_MIN_MAX_VALUE(type, 0, maxvalue)
40 // Convenience macro for defining enumerated type traits for types which are
41 // range-checked by the IPC system to be in the range of minvalue..maxvalue
42 // inclusive. This macro should not need to be subsequently redefined.
43 // TODO(tsepez): Cast to std::underlying_type<>::type once that is permitted.
44 #define IPC_ENUM_TRAITS_MIN_MAX_VALUE(type, minvalue, maxvalue) \
45 IPC_ENUM_TRAITS_VALIDATE( \
46 type, (static_cast<int>(value) >= static_cast<int>(minvalue) && \
47 static_cast<int>(value) <= static_cast<int>(maxvalue)))
49 // Traits generation for enums. This macro may be redefined later.
50 #define IPC_ENUM_TRAITS_VALIDATE(enum_name, validation_expression) \
51 namespace IPC { \
52 template <> \
53 struct IPC_MESSAGE_EXPORT ParamTraits<enum_name> { \
54 typedef enum_name param_type; \
55 static void Write(Message* m, const param_type& p); \
56 static bool Read(const Message* m, base::PickleIterator* iter, \
57 param_type* p); \
58 static void Log(const param_type& p, std::string* l); \
59 }; \
62 #endif // IPC_PARAM_TRAITS_MACROS_H_