param_traits_read_macros.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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.
  4. #ifndef IPC_PARAM_TRAITS_READ_MACROS_H_
  5. #define IPC_PARAM_TRAITS_READ_MACROS_H_
  6. // Null out all the macros that need nulling.
  7. #include "ipc/ipc_message_null_macros.h"
  8. // STRUCT declarations cause corresponding STRUCT_TRAITS declarations to occur.
  9. #undef IPC_STRUCT_BEGIN_WITH_PARENT
  10. #undef IPC_STRUCT_MEMBER
  11. #undef IPC_STRUCT_END
  12. #define IPC_STRUCT_BEGIN_WITH_PARENT(struct_name, parent) \
  13. IPC_STRUCT_TRAITS_BEGIN(struct_name)
  14. #define IPC_STRUCT_MEMBER(type, name, ...) IPC_STRUCT_TRAITS_MEMBER(name)
  15. #define IPC_STRUCT_END() IPC_STRUCT_TRAITS_END()
  16. // Set up so next include will generate read methods.
  17. #undef IPC_STRUCT_TRAITS_BEGIN
  18. #undef IPC_STRUCT_TRAITS_MEMBER
  19. #undef IPC_STRUCT_TRAITS_PARENT
  20. #undef IPC_STRUCT_TRAITS_END
  21. #define IPC_STRUCT_TRAITS_BEGIN(struct_name) \
  22. bool ParamTraits<struct_name>::Read( \
  23. const base::Pickle* m, base::PickleIterator* iter, param_type* p) { \
  24. return
  25. #define IPC_STRUCT_TRAITS_MEMBER(name) ReadParam(m, iter, &p->name) &&
  26. #define IPC_STRUCT_TRAITS_PARENT(type) ParamTraits<type>::Read(m, iter, p) &&
  27. #define IPC_STRUCT_TRAITS_END() 1; }
  28. #undef IPC_ENUM_TRAITS_VALIDATE
  29. #define IPC_ENUM_TRAITS_VALIDATE(enum_name, validation_expression) \
  30. bool ParamTraits<enum_name>::Read( \
  31. const base::Pickle* m, base::PickleIterator* iter, param_type* p) { \
  32. int value; \
  33. if (!iter->ReadInt(&value)) \
  34. return false; \
  35. if (!(validation_expression)) \
  36. return false; \
  37. *p = static_cast<param_type>(value); \
  38. return true; \
  39. }
  40. #endif // IPC_PARAM_TRAITS_READ_MACROS_H_