Hierarchy.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #include <Tests/Framework/Framework.h>
  6. #include <AnKi/Util/Hierarchy.h>
  7. using namespace anki;
  8. #if 0
  9. template<typename T, typename Alloc>
  10. struct Deleter
  11. {
  12. void onChildRemoved(T* x, T* parent)
  13. {
  14. std::cout << __PRETTY_FUNCTION__ << std::endl;
  15. Alloc alloc = x->getAllocator();
  16. alloc.destroy(x);
  17. alloc.deallocate(x, 1);
  18. }
  19. void onChildAdded(T*, T*)
  20. {}
  21. };
  22. struct Foo2: public Object<Foo2, Allocator<Foo2>,
  23. Deleter<Foo2, Allocator<Foo2>>>
  24. {
  25. using Base = Object<Foo2, Allocator<Foo2>, Deleter<Foo2, Allocator<Foo2>>>;
  26. int x = 666;
  27. static int constructorCallCount;
  28. static int destructorCallCount;
  29. Foo2(Foo2* parent)
  30. : Base(parent)
  31. {
  32. std::cout << __PRETTY_FUNCTION__ << std::endl;
  33. ++constructorCallCount;
  34. }
  35. ~Foo2()
  36. {
  37. std::cout << __PRETTY_FUNCTION__ << std::endl;
  38. ++destructorCallCount;
  39. }
  40. Foo2& operator=(const Foo2& b)
  41. {
  42. std::cout << __PRETTY_FUNCTION__ << std::endl;
  43. x = b.x;
  44. return *this;
  45. }
  46. Foo2& operator=(Foo2&& b)
  47. {
  48. std::cout << __PRETTY_FUNCTION__ << std::endl;
  49. x = b.x;
  50. b.x = 0;
  51. return *this;
  52. }
  53. static void reset()
  54. {
  55. destructorCallCount = constructorCallCount = 0;
  56. }
  57. };
  58. int Foo2::constructorCallCount = 0;
  59. int Foo2::destructorCallCount = 0;
  60. ANKI_TEST(Object, Test)
  61. {
  62. Foo2* a = new Foo2(nullptr);
  63. Foo2* b = new Foo2(a);
  64. Foo2* c = new Foo2(b);
  65. (void)c;
  66. delete a;
  67. }
  68. #endif