param_traits_log_macros.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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_LOG_MACROS_H_
  5. #define IPC_PARAM_TRAITS_LOG_MACROS_H_
  6. #include <string>
  7. // Null out all the macros that need nulling.
  8. #include "ipc/ipc_message_null_macros.h"
  9. // STRUCT declarations cause corresponding STRUCT_TRAITS declarations to occur.
  10. #undef IPC_STRUCT_BEGIN_WITH_PARENT
  11. #undef IPC_STRUCT_MEMBER
  12. #undef IPC_STRUCT_END
  13. #define IPC_STRUCT_BEGIN_WITH_PARENT(struct_name, parent) \
  14. IPC_STRUCT_TRAITS_BEGIN(struct_name)
  15. #define IPC_STRUCT_MEMBER(type, name, ...) IPC_STRUCT_TRAITS_MEMBER(name)
  16. #define IPC_STRUCT_END() IPC_STRUCT_TRAITS_END()
  17. // Set up so next include will generate log methods.
  18. #undef IPC_STRUCT_TRAITS_BEGIN
  19. #undef IPC_STRUCT_TRAITS_MEMBER
  20. #undef IPC_STRUCT_TRAITS_PARENT
  21. #undef IPC_STRUCT_TRAITS_END
  22. #define IPC_STRUCT_TRAITS_BEGIN(struct_name) \
  23. void ParamTraits<struct_name>::Log(const param_type& p, std::string* l) { \
  24. bool needs_comma = false; \
  25. (void)needs_comma; \
  26. l->append("(");
  27. #define IPC_STRUCT_TRAITS_MEMBER(name) \
  28. if (needs_comma) \
  29. l->append(", "); \
  30. LogParam(p.name, l); \
  31. needs_comma = true;
  32. #define IPC_STRUCT_TRAITS_PARENT(type) \
  33. if (needs_comma) \
  34. l->append(", "); \
  35. ParamTraits<type>::Log(p, l); \
  36. needs_comma = true;
  37. #define IPC_STRUCT_TRAITS_END() \
  38. l->append(")"); \
  39. }
  40. #undef IPC_ENUM_TRAITS_VALIDATE
  41. #define IPC_ENUM_TRAITS_VALIDATE(enum_name, validation_expression) \
  42. void ParamTraits<enum_name>::Log(const param_type& p, std::string* l) { \
  43. LogParam(static_cast<int>(p), l); \
  44. }
  45. #endif // IPC_PARAM_TRAITS_LOG_MACROS_H_