1
0

area_business.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #include <assert.h>
  2. #include "log.h"
  3. #include "area_business.h"
  4. #include "area_business_car_attendance.h"
  5. #include "area_business_card_enter_or_leave.h"
  6. #include "area_business_count_checker.h"
  7. #include "area_business_forbid.h"
  8. #include "area_business_person_dwell_checker.h"
  9. #include "area_business_person_attendance.h"
  10. #include "area_business_post_area.h"
  11. #include "area_business_speed_checker.h"
  12. #include "area_business_motionless_persion.h"
  13. #include "area_business_geofault.h"
  14. #include "area_business_work_rate.h"
  15. struct area_business_factory
  16. {
  17. void regist(int type,area_business* ab)
  18. {
  19. ab->m_business_type=type;
  20. if(type>=(int)m_check_list.size())
  21. {
  22. m_check_list.resize(type+1);
  23. }
  24. assert(!m_check_list[type]);
  25. m_check_list[type].reset(ab);
  26. }
  27. std::vector<area_business*> get_check_list(int business_type,int area_id)
  28. {
  29. std::vector<area_business*> check_list;
  30. for(int i=0;i<32;i++)
  31. {
  32. if(business_type==0)
  33. break;
  34. if((business_type&1)==0)
  35. {
  36. business_type >>= 1;
  37. continue;
  38. }
  39. business_type >>= 1;
  40. if(!m_check_list[i])
  41. {
  42. log_error("区域业务项目不存在:%d,area_id=%d",i,area_id);
  43. continue;
  44. }
  45. check_list.push_back(m_check_list[i].get());
  46. }
  47. return std::move(check_list);
  48. }
  49. static area_business_factory& instance()
  50. {
  51. static area_business_factory _instance;
  52. return _instance;
  53. }
  54. private:
  55. std::vector<std::unique_ptr<area_business>> m_check_list;
  56. area_business_factory()
  57. {
  58. regist(0, new area_business_post_area);
  59. regist(1, new area_business_person_dwell_checker);
  60. regist(2, new area_business_count_checker);
  61. regist(3, new area_business_speed_checker);
  62. regist(4, new area_business_person_attendance);
  63. regist(5, new area_business_car_attendance);
  64. regist(6, new area_business_forbid);
  65. regist(7, new area_business_card_enter_or_leave);
  66. regist(8, new area_business_motionless_persion);
  67. regist(9, new area_business_geofault);
  68. regist(10,new area_business_work_rate);
  69. }
  70. };
  71. std::vector<area_business*> area_business::get_instance_list(int business_type,int area_id)
  72. {
  73. return area_business_factory::instance().get_check_list(business_type,area_id);
  74. }