Notifier.cpp 969 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright 2009-2011, Andrea Anzani. All rights reserved.
  3. * Distributed under the terms of the MIT License.
  4. *
  5. * Authors:
  6. * Andrea Anzani, andrea.anzani@gmail.com
  7. */
  8. #include "Notifier.h"
  9. #include "Observer.h"
  10. void
  11. Notifier::RegisterObserver(Observer* obs)
  12. {
  13. if (!fObserverList.HasItem(obs))
  14. fObserverList.AddItem(obs);
  15. }
  16. void
  17. Notifier::UnregisterObserver(Observer* obs)
  18. {
  19. if (fObserverList.HasItem(obs))
  20. fObserverList.RemoveItem(obs, false);
  21. }
  22. void
  23. Notifier::NotifyString(int32 what, BString str)
  24. {
  25. for (int i = 0; i < fObserverList.CountItems(); i++)
  26. fObserverList.ItemAt(i)->ObserveString(what, str);
  27. }
  28. void
  29. Notifier::NotifyInteger(int32 what, int32 value)
  30. {
  31. for (int i = 0; i < fObserverList.CountItems(); i++)
  32. fObserverList.ItemAt(i)->ObserveInteger(what, value);
  33. }
  34. void
  35. Notifier::NotifyPointer(int32 what, void* ptr)
  36. {
  37. for (int i = 0; i < fObserverList.CountItems(); i++)
  38. fObserverList.ItemAt(i)->ObservePointer(what, ptr);
  39. }