blob: f4248df1116867b836f74a037f888ee1596a2efa [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); \
[email protected]ce208f872012-03-07 20:42:5617 static bool Read(const Message* m, PickleIterator* iter, param_type* p); \
[email protected]6476c72c2011-02-11 18:46:1918 static void Log(const param_type& p, std::string* l); \
19 }; \
20 }
21
22#define IPC_STRUCT_TRAITS_MEMBER(name)
[email protected]94dc971d2011-03-05 19:08:3223#define IPC_STRUCT_TRAITS_PARENT(type)
[email protected]6476c72c2011-02-11 18:46:1924#define IPC_STRUCT_TRAITS_END()
25
[email protected]dedd0a92013-06-04 07:20:3226// Convenience macro for defining enumerated type traits for types which are
27// not range-checked by the IPC system. The author of the message handlers
28// is responsible for all validation. This macro should not need to be
29// subsequently redefined.
30#define IPC_ENUM_TRAITS(type) \
31 IPC_ENUM_TRAITS_VALIDATE(type, true)
32
33// Convenience macro for defining enumerated type traits for types which are
34// range-checked by the IPC system to be in the range of 0..maxvalue inclusive.
35// This macro should not need to be subsequently redefined.
36#define IPC_ENUM_TRAITS_MAX_VALUE(type, maxvalue) \
37 IPC_ENUM_TRAITS_MIN_MAX_VALUE(type, 0, maxvalue)
38
39// Convenience macro for defining enumerated type traits for types which are
40// range-checked by the IPC system to be in the range of minvalue..maxvalue
41// inclusive. This macro should not need to be subsequently redefined.
tsepez26d859a22014-10-23 02:39:2442// TODO(tsepez): Cast to std::underlying_type<>::type once that is permitted.
[email protected]dedd0a92013-06-04 07:20:3243#define IPC_ENUM_TRAITS_MIN_MAX_VALUE(type, minvalue, maxvalue) \
tsepez26d859a22014-10-23 02:39:2444 IPC_ENUM_TRAITS_VALIDATE( \
45 type, (static_cast<int>(value) >= static_cast<int>(minvalue) && \
46 static_cast<int>(value) <= static_cast<int>(maxvalue)))
[email protected]dedd0a92013-06-04 07:20:3247
48// Traits generation for enums. This macro may be redefined later.
49#define IPC_ENUM_TRAITS_VALIDATE(enum_name, validation_expression) \
[email protected]6476c72c2011-02-11 18:46:1950 namespace IPC { \
51 template <> \
[email protected]269f86d2011-12-07 02:43:4752 struct IPC_MESSAGE_EXPORT ParamTraits<enum_name> { \
[email protected]6476c72c2011-02-11 18:46:1953 typedef enum_name param_type; \
54 static void Write(Message* m, const param_type& p); \
[email protected]ce208f872012-03-07 20:42:5655 static bool Read(const Message* m, PickleIterator* iter, param_type* p); \
[email protected]6476c72c2011-02-11 18:46:1956 static void Log(const param_type& p, std::string* l); \
57 }; \
58 }
59
60#endif // IPC_PARAM_TRAITS_MACROS_H_
61