123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- #ifndef _AREA_HPP_
- #define _AREA_HPP_
- #include <atomic>
- #include <algorithm>
- #include <iterator>
- #include <point.h>
- #include <write-copy.h>
- struct area_hover;
- struct point;
- struct area
- {
- area()
- {
- }
- virtual void on_hover(int64_t card_id,std::shared_ptr<area_hover>&c,double speed)=0;
- virtual void on_enter(int64_t card_id,std::shared_ptr<area_hover>&c,double speed)=0;
- virtual void on_leave(int64_t card_id,std::shared_ptr<area_hover>&c,double speed)=0;
- int id()const
- {
- return m_id;
- }
- std::atomic<int> m_card_count;
- int m_id;
- double m_limit_speed;
- // std::string m_name;
- // int m_limit_time_second;
- // int m_limit_person_count;
- // int m_area_type;
- std::vector<point> m_bound;
- };
- struct area_list:single_base<area_list,int,std::shared_ptr<area>>
- {
- area_list();
- std::vector<std::shared_ptr<area>> get_area(const point&pt);
- void init_from_db()
- {
- }
- };
- struct area_hover
- {
- std::shared_ptr<area> m_area;
- time_t m_enter_time,m_last_time;
- point m_enter_point,m_last_point;
- int m_num_speeding;
- area_hover(std::shared_ptr<area>&area,const point&pt,double speed)
- :m_area(area)
- {
- m_enter_time=m_last_time=time(0);
- m_enter_point=m_last_point=pt;
- m_num_speeding=0;
- if(speed>m_area->m_limit_speed)
- m_num_speeding++;
- }
- int id()const
- {
- return m_area->id();
- }
- bool operator == (const area_hover&o)const
- {
- return m_area->id()==o.m_area->id();
- }
- bool operator < (const area_hover&o)const
- {
- return m_area->id()<o.m_area->id();
- }
- };
- //每张卡包含一个对象
- //在解析出数据点时,调用on_point
- struct area_tool
- {
- std::vector<std::shared_ptr<area_hover>> m_clist;
- void on_point(int64_t card_id,const point&pt,double speed);
- //检测是否超时
- void on_timer(int64_t card_id)
- {
-
- }
- void do_hover_biz(int64_t card_id,std::shared_ptr<area_hover>&a,double speed)
- {
- a->m_area->on_hover(card_id,a,speed);
- }
- void do_enter_biz(int64_t card_id,std::shared_ptr<area_hover>&a,double speed)
- {
- a->m_area->on_enter(card_id,a,speed);
- }
- void do_leave_biz(int64_t card_id,std::shared_ptr<area_hover>&a,double speed)
- {
- a->m_area->on_leave(card_id,a,speed);
- }
- };
- #endif
|