area.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #ifndef _AREA_HPP_
  2. #define _AREA_HPP_
  3. #include <atomic>
  4. #include <algorithm>
  5. #include <iterator>
  6. #include <point.h>
  7. #include <write-copy.h>
  8. struct area_hover;
  9. struct point;
  10. struct area
  11. {
  12. area()
  13. {
  14. }
  15. virtual void on_hover(int64_t card_id,std::shared_ptr<area_hover>&c,double speed)=0;
  16. virtual void on_enter(int64_t card_id,std::shared_ptr<area_hover>&c,double speed)=0;
  17. virtual void on_leave(int64_t card_id,std::shared_ptr<area_hover>&c,double speed)=0;
  18. int id()const
  19. {
  20. return m_id;
  21. }
  22. std::atomic<int> m_card_count;
  23. int m_id;
  24. double m_limit_speed;
  25. // std::string m_name;
  26. // int m_limit_time_second;
  27. // int m_limit_person_count;
  28. // int m_area_type;
  29. std::vector<point> m_bound;
  30. };
  31. struct area_list:single_base<area_list,int,std::shared_ptr<area>>
  32. {
  33. area_list();
  34. std::vector<std::shared_ptr<area>> get_area(const point&pt);
  35. void init_from_db()
  36. {
  37. }
  38. };
  39. struct area_hover
  40. {
  41. std::shared_ptr<area> m_area;
  42. time_t m_enter_time,m_last_time;
  43. point m_enter_point,m_last_point;
  44. int m_num_speeding;
  45. area_hover(std::shared_ptr<area>&area,const point&pt,double speed)
  46. :m_area(area)
  47. {
  48. m_enter_time=m_last_time=time(0);
  49. m_enter_point=m_last_point=pt;
  50. m_num_speeding=0;
  51. if(speed>m_area->m_limit_speed)
  52. m_num_speeding++;
  53. }
  54. int id()const
  55. {
  56. return m_area->id();
  57. }
  58. bool operator == (const area_hover&o)const
  59. {
  60. return m_area->id()==o.m_area->id();
  61. }
  62. bool operator < (const area_hover&o)const
  63. {
  64. return m_area->id()<o.m_area->id();
  65. }
  66. };
  67. //每张卡包含一个对象
  68. //在解析出数据点时,调用on_point
  69. struct area_tool
  70. {
  71. std::vector<std::shared_ptr<area_hover>> m_clist;
  72. void on_point(int64_t card_id,const point&pt,double speed);
  73. //检测是否超时
  74. void on_timer(int64_t card_id)
  75. {
  76. }
  77. void do_hover_biz(int64_t card_id,std::shared_ptr<area_hover>&a,double speed)
  78. {
  79. a->m_area->on_hover(card_id,a,speed);
  80. }
  81. void do_enter_biz(int64_t card_id,std::shared_ptr<area_hover>&a,double speed)
  82. {
  83. a->m_area->on_enter(card_id,a,speed);
  84. }
  85. void do_leave_biz(int64_t card_id,std::shared_ptr<area_hover>&a,double speed)
  86. {
  87. a->m_area->on_leave(card_id,a,speed);
  88. }
  89. };
  90. #endif