Hierarchy.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Copyright (C) 2009-2020, 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. typedef Object<Foo2, Allocator<Foo2>,
  26. Deleter<Foo2, Allocator<Foo2>>> Base;
  27. int x = 666;
  28. static int constructorCallCount;
  29. static int destructorCallCount;
  30. Foo2(Foo2* parent)
  31. : Base(parent)
  32. {
  33. std::cout << __PRETTY_FUNCTION__ << std::endl;
  34. ++constructorCallCount;
  35. }
  36. ~Foo2()
  37. {
  38. std::cout << __PRETTY_FUNCTION__ << std::endl;
  39. ++destructorCallCount;
  40. }
  41. Foo2& operator=(const Foo2& b)
  42. {
  43. std::cout << __PRETTY_FUNCTION__ << std::endl;
  44. x = b.x;
  45. return *this;
  46. }
  47. Foo2& operator=(Foo2&& b)
  48. {
  49. std::cout << __PRETTY_FUNCTION__ << std::endl;
  50. x = b.x;
  51. b.x = 0;
  52. return *this;
  53. }
  54. static void reset()
  55. {
  56. destructorCallCount = constructorCallCount = 0;
  57. }
  58. };
  59. int Foo2::constructorCallCount = 0;
  60. int Foo2::destructorCallCount = 0;
  61. ANKI_TEST(Object, Test)
  62. {
  63. Foo2* a = new Foo2(nullptr);
  64. Foo2* b = new Foo2(a);
  65. Foo2* c = new Foo2(b);
  66. (void)c;
  67. delete a;
  68. }
  69. #endif