ctkLDAPSearchFilter.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 "ctkServiceReferencePrivate.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. try
  42. {
  43. d = new ctkLDAPSearchFilterData(filter);
  44. }
  45. catch (const std::exception& e)
  46. {
  47. throw std::invalid_argument(e.what());
  48. }
  49. }
  50. //----------------------------------------------------------------------------
  51. ctkLDAPSearchFilter::ctkLDAPSearchFilter(const ctkLDAPSearchFilter& other)
  52. : d(other.d)
  53. {
  54. }
  55. //----------------------------------------------------------------------------
  56. ctkLDAPSearchFilter::~ctkLDAPSearchFilter()
  57. {
  58. }
  59. //----------------------------------------------------------------------------
  60. ctkLDAPSearchFilter::operator bool() const
  61. {
  62. return d;
  63. }
  64. //----------------------------------------------------------------------------
  65. bool ctkLDAPSearchFilter::match(const ctkServiceReference& reference) const
  66. {
  67. return d->ldapExpr.evaluate(reference.d_func()->getProperties(), true);
  68. }
  69. //----------------------------------------------------------------------------
  70. bool ctkLDAPSearchFilter::match(const ctkDictionary& dictionary) const
  71. {
  72. return d->ldapExpr.evaluate(dictionary, false);
  73. }
  74. //----------------------------------------------------------------------------
  75. bool ctkLDAPSearchFilter::matchCase(const ctkDictionary& dictionary) const
  76. {
  77. return d->ldapExpr.evaluate(dictionary, true);
  78. }
  79. //----------------------------------------------------------------------------
  80. QString ctkLDAPSearchFilter::toString() const
  81. {
  82. return d->ldapExpr.toString();
  83. }
  84. //----------------------------------------------------------------------------
  85. bool ctkLDAPSearchFilter::operator==(const ctkLDAPSearchFilter& other) const
  86. {
  87. return d->ldapExpr.toString() == other.d->ldapExpr.toString();
  88. }
  89. //----------------------------------------------------------------------------
  90. ctkLDAPSearchFilter& ctkLDAPSearchFilter::operator=(const ctkLDAPSearchFilter& filter)
  91. {
  92. d = filter.d;
  93. return *this;
  94. }
  95. //----------------------------------------------------------------------------
  96. QDebug operator<<(QDebug dbg, const ctkLDAPSearchFilter& filter)
  97. {
  98. dbg << filter.toString();
  99. return dbg.maybeSpace();
  100. }