SafeList.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #ifndef __SAFE_LIST__
  2. #define __SAFE_LIST__
  3. #include <list>
  4. #include <locale.h>
  5. #include "CritSection.h"
  6. class CDatabase;
  7. using namespace std;
  8. template <class _Ty,class _Ax = allocator<_Ty>>
  9. class SafeList: public std::list<_Ty, _Ax>
  10. {
  11. public:
  12. ThreadSection _critSection;
  13. void _push_back(const _Ty& _Val)
  14. {
  15. AutoThreadSection aSection(&_critSection);
  16. push_back(_Val);
  17. }
  18. void _push_front(const _Ty& _Val)
  19. {
  20. AutoThreadSection aSection(&_critSection);
  21. push_front(_Val);
  22. }
  23. void _pop_front()
  24. {
  25. AutoThreadSection aSection(&_critSection);
  26. pop_front();
  27. }
  28. CDatabase* _pop_front_()
  29. {
  30. AutoThreadSection aSection(&_critSection);
  31. CDatabase* it = front();
  32. pop_front();
  33. return it;
  34. }
  35. void _pop_back()
  36. {
  37. AutoThreadSection aSection(&_critSection);
  38. pop_back();
  39. }
  40. void _remove(const _Ty& _Val_arg)
  41. {
  42. AutoThreadSection aSection(&_critSection);
  43. remove(_Val_arg);
  44. }
  45. reference _front()
  46. {
  47. AutoThreadSection aSection(&_critSection);
  48. return (*begin());
  49. }
  50. const_reference _front() const
  51. {
  52. AutoThreadSection aSection(&_critSection);
  53. return (*begin());
  54. }
  55. reference _back()
  56. {
  57. AutoThreadSection aSection(&_critSection);
  58. return (*(--end()));
  59. }
  60. const_reference _back() const
  61. {
  62. AutoThreadSection aSection(&_critSection);
  63. return (*(--end()));
  64. }
  65. size_type _size()
  66. {
  67. //AutoThreadSection aSection(&_critSection);
  68. return size();
  69. }
  70. };
  71. #endif // __SAFE_LIST__