SafeList.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. _Ty _pop_front_()
  29. {
  30. AutoThreadSection aSection(&_critSection);
  31. if (size())
  32. {
  33. _Ty it = front();
  34. pop_front();
  35. return it;
  36. }
  37. return NULL;
  38. }
  39. void _pop_back()
  40. {
  41. AutoThreadSection aSection(&_critSection);
  42. pop_back();
  43. }
  44. void _remove(const _Ty& _Val_arg)
  45. {
  46. AutoThreadSection aSection(&_critSection);
  47. remove(_Val_arg);
  48. }
  49. reference _front()
  50. {
  51. AutoThreadSection aSection(&_critSection);
  52. return (*begin());
  53. }
  54. const_reference _front() const
  55. {
  56. AutoThreadSection aSection(&_critSection);
  57. return (*begin());
  58. }
  59. reference _back()
  60. {
  61. AutoThreadSection aSection(&_critSection);
  62. return (*(--end()));
  63. }
  64. const_reference _back() const
  65. {
  66. AutoThreadSection aSection(&_critSection);
  67. return (*(--end()));
  68. }
  69. size_type _size()
  70. {
  71. //AutoThreadSection aSection(&_critSection);
  72. return size();
  73. }
  74. };
  75. typedef SafeList<CDatabase*> ODBCConnectList;
  76. #endif // __SAFE_LIST__