ctkEvent.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include "ctkEvent.h"
  2. class ctkEventPrivate {
  3. public:
  4. ctkEventPrivate(const QString& topic, const ctkDictionary& properties)
  5. : ref(1), topic(topic), properties(properties)
  6. {
  7. }
  8. QAtomicInt ref;
  9. const QString topic;
  10. const ctkDictionary properties;
  11. };
  12. ctkEvent::ctkEvent(const QString& topic, const ctkDictionary& properties)
  13. : d(new ctkEventPrivate(topic, properties))
  14. {
  15. }
  16. /*
  17. * This is fast thanks to implicit sharing
  18. */
  19. ctkEvent::ctkEvent(const ctkEvent &event)
  20. : d(event.d)
  21. {
  22. d->ref.ref();
  23. }
  24. ctkEvent::~ctkEvent()
  25. {
  26. if (!d->ref.deref())
  27. delete d;
  28. }
  29. bool ctkEvent::operator==(const ctkEvent& other) const
  30. {
  31. if (d == other.d)
  32. return true;
  33. if (d->topic == other.d->topic &&
  34. d->properties == other.d->properties)
  35. return true;
  36. return false;
  37. }
  38. QVariant ctkEvent::property(const QString& name) const
  39. {
  40. return d->properties[name];
  41. }
  42. QStringList ctkEvent::propertyNames() const
  43. {
  44. return d->properties.keys();
  45. }
  46. const QString& ctkEvent::topic() const
  47. {
  48. return d->topic;
  49. }
  50. bool ctkEvent::matches(const ctkLDAPSearchFilter& filter) const
  51. {
  52. return filter.matchCase(d->properties);
  53. }