VectorOfPtr.tlh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #pragma once
  2. #include <vector>
  3. #include <memory>
  4. //#include <Iterator.tlh>
  5. //-----------------------------------------------------------------------------
  6. // VectorOfPtr
  7. //-----------------------------------------------------------------------------
  8. template <typename T>
  9. class VectorOfPtr : public std::vector <std::unique_ptr <T>>
  10. {
  11. using inherited = std::vector <std::unique_ptr <T>>;
  12. public:
  13. // using inherited::inherited;
  14. VectorOfPtr ()
  15. {
  16. }
  17. VectorOfPtr (VectorOfPtr && from) : inherited (std::move (from))
  18. {
  19. }
  20. VectorOfPtr (const VectorOfPtr & from) = delete;
  21. ~VectorOfPtr ()
  22. {
  23. __noop;
  24. }
  25. VectorOfPtr & operator = (VectorOfPtr && from)
  26. {
  27. inherited::operator = (std::move (from));
  28. return (*this);
  29. }
  30. public:
  31. inline void Attach (T * value)
  32. {
  33. std::unique_ptr <T> ptr (value);
  34. inherited::push_back (std::move (ptr));
  35. }
  36. inline int GetSize () const
  37. {
  38. return (int) (this->size ());
  39. }
  40. inline bool IsEmpty () const
  41. {
  42. return inherited::empty ();
  43. }
  44. inline void Reset ()
  45. {
  46. this->clear ();
  47. }
  48. inline std::vector <T *> ToVector ()
  49. {
  50. std::vector <T *> to;
  51. for (const auto & Item : *this)
  52. {
  53. to.push_back (Item.get ());
  54. }
  55. return to;
  56. }
  57. // int IndexOf (const T * t) const;
  58. };