blob: 317f31228d993f2d26aa0e8eeb5d9ab21c9aa620 [file] [log] [blame]
[email protected]ce208f872012-03-07 20:42:561// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]6476c72c2011-02-11 18:46:192// 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.
11#define IPC_STRUCT_TRAITS_BEGIN(struct_name) \
12 namespace IPC { \
13 template <> \
[email protected]03ff5e52011-09-30 00:28:1414 struct IPC_MESSAGE_EXPORT ParamTraits<struct_name> { \
[email protected]6476c72c2011-02-11 18:46:1915 typedef struct_name param_type; \
16 static void Write(Message* m, const param_type& p); \
brettw05cfd8ddb2015-06-02 07:02:4717 static bool Read(const Message* m, base::PickleIterator* iter, \
18 param_type* p); \
[email protected]6476c72c2011-02-11 18:46:1919 static void Log(const param_type& p, std::string* l); \
20 }; \
21 }
22
23#define IPC_STRUCT_TRAITS_MEMBER(name)
[email protected]94dc971d2011-03-05 19:08:3224#define IPC_STRUCT_TRAITS_PARENT(type)
[email protected]6476c72c2011-02-11 18:46:1925#define IPC_STRUCT_TRAITS_END()
26
[email protected]dedd0a92013-06-04 07:20:3227// 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)
33
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)
39
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.
tsepez26d859a22014-10-23 02:39:2443// TODO(tsepez): Cast to std::underlying_type<>::type once that is permitted.
[email protected]dedd0a92013-06-04 07:20:3244#define IPC_ENUM_TRAITS_MIN_MAX_VALUE(type, minvalue, maxvalue) \
tsepez26d859a22014-10-23 02:39:2445 IPC_ENUM_TRAITS_VALIDATE( \
46 type, (static_cast<int>(value) >= static_cast<int>(minvalue) && \
47 static_cast<int>(value) <= static_cast<int>(maxvalue)))
[email protected]dedd0a92013-06-04 07:20:3248
49// Traits generation for enums. This macro may be redefined later.
50#define IPC_ENUM_TRAITS_VALIDATE(enum_name, validation_expression) \
[email protected]6476c72c2011-02-11 18:46:1951 namespace IPC { \
52 template <> \
[email protected]269f86d2011-12-07 02:43:4753 struct IPC_MESSAGE_EXPORT ParamTraits<enum_name> { \
[email protected]6476c72c2011-02-11 18:46:1954 typedef enum_name param_type; \
55 static void Write(Message* m, const param_type& p); \
brettw05cfd8ddb2015-06-02 07:02:4756 static bool Read(const Message* m, base::PickleIterator* iter, \
57 param_type* p); \
[email protected]6476c72c2011-02-11 18:46:1958 static void Log(const param_type& p, std::string* l); \
59 }; \
60 }
61
62#endif // IPC_PARAM_TRAITS_MACROS_H_
63