ctkEvent.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) 2010 German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. #include "ctkEvent.h"
  16. class ctkEventPrivate {
  17. public:
  18. ctkEventPrivate(const QString& topic, const ctkDictionary& properties)
  19. : ref(1), topic(topic), properties(properties)
  20. {
  21. }
  22. QAtomicInt ref;
  23. const QString topic;
  24. const ctkDictionary properties;
  25. };
  26. ctkEvent::ctkEvent(const QString& topic, const ctkDictionary& properties)
  27. : d(new ctkEventPrivate(topic, properties))
  28. {
  29. }
  30. /*
  31. * This is fast thanks to implicit sharing
  32. */
  33. ctkEvent::ctkEvent(const ctkEvent &event)
  34. : d(event.d)
  35. {
  36. d->ref.ref();
  37. }
  38. ctkEvent::~ctkEvent()
  39. {
  40. if (!d->ref.deref())
  41. delete d;
  42. }
  43. bool ctkEvent::operator==(const ctkEvent& other) const
  44. {
  45. if (d == other.d)
  46. return true;
  47. if (d->topic == other.d->topic &&
  48. d->properties == other.d->properties)
  49. return true;
  50. return false;
  51. }
  52. QVariant ctkEvent::property(const QString& name) const
  53. {
  54. return d->properties[name];
  55. }
  56. QStringList ctkEvent::propertyNames() const
  57. {
  58. return d->properties.keys();
  59. }
  60. const QString& ctkEvent::topic() const
  61. {
  62. return d->topic;
  63. }
  64. bool ctkEvent::matches(const ctkLDAPSearchFilter& filter) const
  65. {
  66. return filter.matchCase(d->properties);
  67. }