jbates@chromium.org | 0fc8736 | 2012-03-08 05:42:56 +0900 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
tsepez@chromium.org | 1ac4613 | 2011-02-12 03:46:19 +0900 | [diff] [blame] | 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 IPC_PARAM_TRAITS_MACROS_H_ |
| 6 | #define IPC_PARAM_TRAITS_MACROS_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | // Traits generation for structs. |
rockot | 6dbfea5 | 2016-02-04 05:20:16 +0900 | [diff] [blame] | 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(base::Pickle* m, const param_type& p); \ |
| 17 | static bool Read(const base::Pickle* m, \ |
| 18 | base::PickleIterator* iter, \ |
| 19 | param_type* p); \ |
| 20 | static void Log(const param_type& p, std::string* l); \ |
| 21 | }; \ |
tsepez@chromium.org | 1ac4613 | 2011-02-12 03:46:19 +0900 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | #define IPC_STRUCT_TRAITS_MEMBER(name) |
jam@chromium.org | 4ae3f56 | 2011-03-06 04:08:32 +0900 | [diff] [blame] | 25 | #define IPC_STRUCT_TRAITS_PARENT(type) |
tsepez@chromium.org | 1ac4613 | 2011-02-12 03:46:19 +0900 | [diff] [blame] | 26 | #define IPC_STRUCT_TRAITS_END() |
| 27 | |
tsepez@chromium.org | 384d976 | 2013-06-04 16:20:32 +0900 | [diff] [blame] | 28 | // Convenience macro for defining enumerated type traits for types which are |
| 29 | // not range-checked by the IPC system. The author of the message handlers |
| 30 | // is responsible for all validation. This macro should not need to be |
| 31 | // subsequently redefined. |
| 32 | #define IPC_ENUM_TRAITS(type) \ |
| 33 | IPC_ENUM_TRAITS_VALIDATE(type, true) |
| 34 | |
| 35 | // Convenience macro for defining enumerated type traits for types which are |
| 36 | // range-checked by the IPC system to be in the range of 0..maxvalue inclusive. |
| 37 | // This macro should not need to be subsequently redefined. |
| 38 | #define IPC_ENUM_TRAITS_MAX_VALUE(type, maxvalue) \ |
| 39 | IPC_ENUM_TRAITS_MIN_MAX_VALUE(type, 0, maxvalue) |
| 40 | |
| 41 | // Convenience macro for defining enumerated type traits for types which are |
| 42 | // range-checked by the IPC system to be in the range of minvalue..maxvalue |
| 43 | // inclusive. This macro should not need to be subsequently redefined. |
tsepez | 0dd1088 | 2014-10-23 11:39:24 +0900 | [diff] [blame] | 44 | // TODO(tsepez): Cast to std::underlying_type<>::type once that is permitted. |
tsepez@chromium.org | 384d976 | 2013-06-04 16:20:32 +0900 | [diff] [blame] | 45 | #define IPC_ENUM_TRAITS_MIN_MAX_VALUE(type, minvalue, maxvalue) \ |
tsepez | 0dd1088 | 2014-10-23 11:39:24 +0900 | [diff] [blame] | 46 | IPC_ENUM_TRAITS_VALIDATE( \ |
| 47 | type, (static_cast<int>(value) >= static_cast<int>(minvalue) && \ |
| 48 | static_cast<int>(value) <= static_cast<int>(maxvalue))) |
tsepez@chromium.org | 384d976 | 2013-06-04 16:20:32 +0900 | [diff] [blame] | 49 | |
| 50 | // Traits generation for enums. This macro may be redefined later. |
| 51 | #define IPC_ENUM_TRAITS_VALIDATE(enum_name, validation_expression) \ |
rockot | 6dbfea5 | 2016-02-04 05:20:16 +0900 | [diff] [blame] | 52 | namespace IPC { \ |
| 53 | template <> \ |
| 54 | struct IPC_MESSAGE_EXPORT ParamTraits<enum_name> { \ |
| 55 | typedef enum_name param_type; \ |
| 56 | static void Write(base::Pickle* m, const param_type& p); \ |
| 57 | static bool Read(const base::Pickle* m, \ |
| 58 | base::PickleIterator* iter, \ |
| 59 | param_type* p); \ |
| 60 | static void Log(const param_type& p, std::string* l); \ |
| 61 | }; \ |
tsepez@chromium.org | 1ac4613 | 2011-02-12 03:46:19 +0900 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | #endif // IPC_PARAM_TRAITS_MACROS_H_ |
| 65 | |