OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef IPC_PARAM_TRAITS_READ_MACROS_H_ | 5 #ifndef IPC_PARAM_TRAITS_READ_MACROS_H_ |
6 #define IPC_PARAM_TRAITS_READ_MACROS_H_ | 6 #define IPC_PARAM_TRAITS_READ_MACROS_H_ |
7 | 7 |
8 // Null out all the macros that need nulling. | 8 // Null out all the macros that need nulling. |
9 #include "ipc/ipc_message_null_macros.h" | 9 #include "ipc/ipc_message_null_macros.h" |
10 | 10 |
11 // STRUCT declarations cause corresponding STRUCT_TRAITS declarations to occur. | 11 // STRUCT declarations cause corresponding STRUCT_TRAITS declarations to occur. |
12 #undef IPC_STRUCT_BEGIN | |
13 #undef IPC_STRUCT_BEGIN_WITH_PARENT | 12 #undef IPC_STRUCT_BEGIN_WITH_PARENT |
14 #undef IPC_STRUCT_MEMBER | 13 #undef IPC_STRUCT_MEMBER |
15 #undef IPC_STRUCT_END | 14 #undef IPC_STRUCT_END |
16 #define IPC_STRUCT_BEGIN_WITH_PARENT(struct_name, parent) \ | 15 #define IPC_STRUCT_BEGIN_WITH_PARENT(struct_name, parent) \ |
17 IPC_STRUCT_BEGIN(struct_name) | 16 IPC_STRUCT_TRAITS_BEGIN(struct_name) |
18 #define IPC_STRUCT_BEGIN(struct_name) IPC_STRUCT_TRAITS_BEGIN(struct_name) | |
19 #define IPC_STRUCT_MEMBER(type, name, ...) IPC_STRUCT_TRAITS_MEMBER(name) | 17 #define IPC_STRUCT_MEMBER(type, name, ...) IPC_STRUCT_TRAITS_MEMBER(name) |
20 #define IPC_STRUCT_END() IPC_STRUCT_TRAITS_END() | 18 #define IPC_STRUCT_END() IPC_STRUCT_TRAITS_END() |
21 | 19 |
22 // Set up so next include will generate read methods. | 20 // Set up so next include will generate read methods. |
23 #undef IPC_STRUCT_TRAITS_BEGIN | 21 #undef IPC_STRUCT_TRAITS_BEGIN |
24 #undef IPC_STRUCT_TRAITS_MEMBER | 22 #undef IPC_STRUCT_TRAITS_MEMBER |
25 #undef IPC_STRUCT_TRAITS_PARENT | 23 #undef IPC_STRUCT_TRAITS_PARENT |
26 #undef IPC_STRUCT_TRAITS_END | 24 #undef IPC_STRUCT_TRAITS_END |
27 #define IPC_STRUCT_TRAITS_BEGIN(struct_name) \ | 25 #define IPC_STRUCT_TRAITS_BEGIN(struct_name) \ |
28 bool ParamTraits<struct_name>:: \ | 26 bool ParamTraits<struct_name>:: \ |
29 Read(const Message* m, PickleIterator* iter, param_type* p) { \ | 27 Read(const Message* m, PickleIterator* iter, param_type* p) { \ |
30 return | 28 return |
31 #define IPC_STRUCT_TRAITS_MEMBER(name) ReadParam(m, iter, &p->name) && | 29 #define IPC_STRUCT_TRAITS_MEMBER(name) ReadParam(m, iter, &p->name) && |
32 #define IPC_STRUCT_TRAITS_PARENT(type) ParamTraits<type>::Read(m, iter, p) && | 30 #define IPC_STRUCT_TRAITS_PARENT(type) ParamTraits<type>::Read(m, iter, p) && |
33 #define IPC_STRUCT_TRAITS_END() 1; } | 31 #define IPC_STRUCT_TRAITS_END() 1; } |
34 | 32 |
35 #undef IPC_ENUM_TRAITS | 33 #undef IPC_ENUM_TRAITS_VALIDATE |
36 #define IPC_ENUM_TRAITS(enum_name) \ | 34 #define IPC_ENUM_TRAITS_VALIDATE(enum_name, validation_expression) \ |
37 bool ParamTraits<enum_name>:: \ | 35 bool ParamTraits<enum_name>:: \ |
38 Read(const Message* m, PickleIterator* iter, param_type* p) { \ | 36 Read(const Message* m, PickleIterator* iter, param_type* p) { \ |
39 int type; \ | 37 int value; \ |
40 if (!m->ReadInt(iter, &type)) \ | 38 if (!m->ReadInt(iter, &value)) \ |
41 return false; \ | 39 return false; \ |
42 *p = static_cast<param_type>(type); \ | 40 if (!validation_expression) \ |
darin (slow to review)
2013/06/03 17:52:53
nit: you might consider writing this as "!(validat
Tom Sepez
2013/06/03 18:33:00
Indeed. thanks.
| |
41 return false; \ | |
42 *p = static_cast<param_type>(value); \ | |
43 return true; \ | 43 return true; \ |
44 } | 44 } |
45 | 45 |
46 #endif // IPC_PARAM_TRAITS_READ_MACROS_H_ | 46 #endif // IPC_PARAM_TRAITS_READ_MACROS_H_ |
47 | 47 |
OLD | NEW |