List.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright 2009-2010, Pier Luigi Fiorini. All rights reserved.
  3. * Distributed under the terms of the MIT License.
  4. */
  5. #ifndef _LIST_H
  6. #define _LIST_H
  7. #include <list>
  8. #include <SupportDefs.h>
  9. template<class T>
  10. class List {
  11. public:
  12. uint32 CountItems() const;
  13. void AddItem(T type);
  14. void RemoveItemAt(uint32 position);
  15. T ItemAt(uint32 position);
  16. void AddList(List<T> appendList);
  17. private:
  18. std::list<T> fList;
  19. typedef typename std::list<T>::iterator fIter;
  20. };
  21. template<class T>
  22. uint32 List<T>::CountItems() const
  23. {
  24. return fList.size();
  25. }
  26. template<class T>
  27. void List<T>::AddItem(T type)
  28. {
  29. fList.push_back(type);
  30. }
  31. template<class T>
  32. void List<T>::RemoveItemAt(uint32 position)
  33. {
  34. fIter i = fList.begin();
  35. std::advance(i, position);
  36. fList.erase(i);
  37. }
  38. template<class T>
  39. T List<T>::ItemAt(uint32 position)
  40. {
  41. fIter i = fList.begin();
  42. std::advance(i, position);
  43. return *i;
  44. }
  45. template<class T>
  46. void List<T>::AddList(List<T> appendList)
  47. {
  48. if (appendList.CountItems() == 0)
  49. return;
  50. for (int i = 0; i < appendList.CountItems(); i++)
  51. AddItem(appendList.ItemAt(i));
  52. }
  53. #endif // _LIST_H