message_compare.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //
  2. // Created by zx on 2020/7/10.
  3. //
  4. #ifndef NNXX_TESTS_MESSAGE_COMPARE_H__H
  5. #define NNXX_TESTS_MESSAGE_COMPARE_H__H
  6. namespace message {
  7. static bool operator==(const message::Command_info &msg1, const message::Command_info &msg2) {
  8. return (msg1.event() == msg2.event()) && (0==msg1.time().compare(msg2.time())) && (0==msg1.place().compare(msg2.place()));
  9. }
  10. static bool operator!=(const message::Command_info &msg1, const message::Command_info &msg2) {
  11. return msg1.event() != msg2.event() ||0!= msg1.time().compare(msg2.time()) || 0!=msg1.place().compare(msg2.place());
  12. }
  13. static bool operator<(const message::Command_info &msg1, const message::Command_info &msg2) {
  14. return msg1.time().compare(msg2.time()) < 0 ||
  15. msg1.place().compare(msg2.place())<0 || msg1.event()<msg2.event();
  16. }
  17. /*static bool operator>(const message::Command_info &msg1, const message::Command_info &msg2) {
  18. LOG(WARNING)<<">>>>>>>>>>>"<<msg1.time().compare(msg2.time());
  19. return msg1.time().compare(msg2.time())>0;
  20. }*/
  21. }
  22. #define RegistoryCompare(NAMESPACE,NAME) \
  23. namespace NAMESPACE \
  24. { \
  25. static bool operator==(const NAME& msg1,const NAME& msg2){ \
  26. if(msg1.base_info().msg_type() == msg2.base_info().msg_type() \
  27. && msg1.base_info().sender() == msg2.base_info().sender() \
  28. && msg1.base_info().receiver() == msg2.base_info().receiver() \
  29. && msg1.command_info() == msg2.command_info()){ \
  30. return true; \
  31. }else{ \
  32. return false; \
  33. } \
  34. } \
  35. static bool operator<(const NAME& msg1,const NAME& msg2){ \
  36. return msg1.command_info() < msg2.command_info(); \
  37. } \
  38. }
  39. #endif //NNXX_TESTS_MESSAGE_COMPARE_H