Event.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/WeakPtr.h>
  7. #include <LibCore/Event.h>
  8. #include <LibCore/Object.h>
  9. namespace Core {
  10. ChildEvent::ChildEvent(Type type, Object& child, Object* insertion_before_child)
  11. : Core::Event(type)
  12. , m_child(child.make_weak_ptr())
  13. , m_insertion_before_child(AK::try_make_weak_ptr(insertion_before_child))
  14. {
  15. }
  16. ChildEvent::~ChildEvent()
  17. {
  18. }
  19. Object* ChildEvent::child()
  20. {
  21. if (auto ref = m_child.strong_ref())
  22. return ref.ptr();
  23. return nullptr;
  24. }
  25. const Object* ChildEvent::child() const
  26. {
  27. if (auto ref = m_child.strong_ref())
  28. return ref.ptr();
  29. return nullptr;
  30. }
  31. Object* ChildEvent::insertion_before_child()
  32. {
  33. if (auto ref = m_insertion_before_child.strong_ref())
  34. return ref.ptr();
  35. return nullptr;
  36. }
  37. const Object* ChildEvent::insertion_before_child() const
  38. {
  39. if (auto ref = m_insertion_before_child.strong_ref())
  40. return ref.ptr();
  41. return nullptr;
  42. }
  43. }