ctkLDAPSearchFilter.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) 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 "ctkLDAPSearchFilter.h"
  16. #include "ctkLDAPExpr_p.h"
  17. #include "ctkServiceReference_p.h"
  18. //----------------------------------------------------------------------------
  19. class ctkLDAPSearchFilterData : public QSharedData
  20. {
  21. public:
  22. ctkLDAPSearchFilterData()
  23. {}
  24. ctkLDAPSearchFilterData(const QString& filter)
  25. : ldapExpr(filter)
  26. {}
  27. ctkLDAPSearchFilterData(const ctkLDAPSearchFilterData& other)
  28. : QSharedData(other), ldapExpr(other.ldapExpr)
  29. {}
  30. ctkLDAPExpr ldapExpr;
  31. };
  32. //----------------------------------------------------------------------------
  33. ctkLDAPSearchFilter::ctkLDAPSearchFilter()
  34. : d(0)
  35. {
  36. }
  37. //----------------------------------------------------------------------------
  38. ctkLDAPSearchFilter::ctkLDAPSearchFilter(const QString& filter)
  39. : d(0)
  40. {
  41. d = new ctkLDAPSearchFilterData(filter);
  42. }
  43. //----------------------------------------------------------------------------
  44. ctkLDAPSearchFilter::ctkLDAPSearchFilter(const ctkLDAPSearchFilter& other)
  45. : d(other.d)
  46. {
  47. }
  48. //----------------------------------------------------------------------------
  49. ctkLDAPSearchFilter::~ctkLDAPSearchFilter()
  50. {
  51. }
  52. //----------------------------------------------------------------------------
  53. ctkLDAPSearchFilter::operator bool() const
  54. {
  55. return d;
  56. }
  57. //----------------------------------------------------------------------------
  58. bool ctkLDAPSearchFilter::match(const ctkServiceReference& reference) const
  59. {
  60. return d->ldapExpr.evaluate(reference.d_func()->getProperties(), true);
  61. }
  62. //----------------------------------------------------------------------------
  63. bool ctkLDAPSearchFilter::match(const ctkDictionary& dictionary) const
  64. {
  65. return d->ldapExpr.evaluate(dictionary, false);
  66. }
  67. //----------------------------------------------------------------------------
  68. bool ctkLDAPSearchFilter::matchCase(const ctkDictionary& dictionary) const
  69. {
  70. return d->ldapExpr.evaluate(dictionary, true);
  71. }
  72. //----------------------------------------------------------------------------
  73. QString ctkLDAPSearchFilter::toString() const
  74. {
  75. return d->ldapExpr.toString();
  76. }
  77. //----------------------------------------------------------------------------
  78. bool ctkLDAPSearchFilter::operator==(const ctkLDAPSearchFilter& other) const
  79. {
  80. return d->ldapExpr.toString() == other.d->ldapExpr.toString();
  81. }
  82. //----------------------------------------------------------------------------
  83. ctkLDAPSearchFilter& ctkLDAPSearchFilter::operator=(const ctkLDAPSearchFilter& filter)
  84. {
  85. d = filter.d;
  86. return *this;
  87. }
  88. //----------------------------------------------------------------------------
  89. QDebug operator<<(QDebug dbg, const ctkLDAPSearchFilter& filter)
  90. {
  91. dbg << filter.toString();
  92. return dbg.maybeSpace();
  93. }