VectorBase.h 1001 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #ifdef URHO3D_IS_BUILDING
  5. #include "Urho3D.h"
  6. #else
  7. #include <Urho3D/Urho3D.h>
  8. #endif
  9. #include "../Container/Swap.h"
  10. #include "Iter.h"
  11. namespace Urho3D
  12. {
  13. /// %Vector base class.
  14. /** Note that to prevent extra memory use due to vtable pointer, %VectorBase intentionally does not declare a virtual destructor
  15. and therefore %VectorBase pointers should never be used.
  16. */
  17. class URHO3D_API VectorBase
  18. {
  19. public:
  20. /// Construct.
  21. VectorBase() noexcept :
  22. size_(0),
  23. capacity_(0),
  24. buffer_(nullptr)
  25. {
  26. }
  27. /// Swap with another vector.
  28. void Swap(VectorBase& rhs)
  29. {
  30. Urho3D::Swap(size_, rhs.size_);
  31. Urho3D::Swap(capacity_, rhs.capacity_);
  32. Urho3D::Swap(buffer_, rhs.buffer_);
  33. }
  34. protected:
  35. static u8* AllocateBuffer(i32 size);
  36. /// Size of vector.
  37. i32 size_;
  38. /// Buffer capacity.
  39. i32 capacity_;
  40. /// Buffer.
  41. u8* buffer_;
  42. };
  43. }