ptr_list.hpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // ptr_list.hpp
  2. // Copyright (c) 2007-2009 Ben Hanson (http://www.benhanson.net/)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file licence_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_LEXER_PTR_LIST_HPP
  7. #define BOOST_LEXER_PTR_LIST_HPP
  8. #include <list>
  9. namespace boost
  10. {
  11. namespace lexer
  12. {
  13. namespace detail
  14. {
  15. template<typename Type>
  16. class ptr_list
  17. {
  18. public:
  19. typedef std::list<Type *> list;
  20. ptr_list ()
  21. {
  22. }
  23. ~ptr_list ()
  24. {
  25. clear ();
  26. }
  27. list *operator -> ()
  28. {
  29. return &_list;
  30. }
  31. const list *operator -> () const
  32. {
  33. return &_list;
  34. }
  35. list &operator * ()
  36. {
  37. return _list;
  38. }
  39. const list &operator * () const
  40. {
  41. return _list;
  42. }
  43. void clear ()
  44. {
  45. while (!_list.empty ())
  46. {
  47. delete _list.front ();
  48. _list.pop_front ();
  49. }
  50. }
  51. private:
  52. list _list;
  53. ptr_list (const ptr_list &); // No copy construction.
  54. ptr_list &operator = (const ptr_list &); // No assignment.
  55. };
  56. }
  57. }
  58. }
  59. #endif