ctkLDAPSearchFilter.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. class ctkLDAPSearchFilterData : public QSharedData
  19. {
  20. public:
  21. ctkLDAPSearchFilterData()
  22. {}
  23. ctkLDAPSearchFilterData(const QString& filter)
  24. : ldapExpr(filter)
  25. {}
  26. ctkLDAPSearchFilterData(const ctkLDAPSearchFilterData& other)
  27. : QSharedData(other), ldapExpr(other.ldapExpr)
  28. {}
  29. ctkLDAPExpr ldapExpr;
  30. };
  31. ctkLDAPSearchFilter::ctkLDAPSearchFilter()
  32. : d(0)
  33. {
  34. }
  35. ctkLDAPSearchFilter::ctkLDAPSearchFilter(const QString& filter)
  36. : d(0)
  37. {
  38. try
  39. {
  40. d = new ctkLDAPSearchFilterData(filter);
  41. }
  42. catch (const std::exception& e)
  43. {
  44. throw std::invalid_argument(e.what());
  45. }
  46. }
  47. ctkLDAPSearchFilter::ctkLDAPSearchFilter(const ctkLDAPSearchFilter& other)
  48. : d(other.d)
  49. {
  50. }
  51. ctkLDAPSearchFilter::~ctkLDAPSearchFilter()
  52. {
  53. }
  54. ctkLDAPSearchFilter::operator bool() const
  55. {
  56. return d;
  57. }
  58. bool ctkLDAPSearchFilter::match(const ctkServiceReference& reference) const
  59. {
  60. return d->ldapExpr.evaluate(reference.d_func()->getProperties(), true);
  61. }
  62. bool ctkLDAPSearchFilter::match(const ctkDictionary& dictionary) const
  63. {
  64. return d->ldapExpr.evaluate(dictionary, false);
  65. }
  66. bool ctkLDAPSearchFilter::matchCase(const ctkDictionary& dictionary) const
  67. {
  68. return d->ldapExpr.evaluate(dictionary, true);
  69. }
  70. QString ctkLDAPSearchFilter::toString() const
  71. {
  72. return d->ldapExpr.toString();
  73. }
  74. bool ctkLDAPSearchFilter::operator==(const ctkLDAPSearchFilter& other) const
  75. {
  76. return d->ldapExpr.toString() == other.d->ldapExpr.toString();
  77. }
  78. ctkLDAPSearchFilter& ctkLDAPSearchFilter::operator=(const ctkLDAPSearchFilter& filter)
  79. {
  80. d = filter.d;
  81. return *this;
  82. }
  83. QDebug operator<<(QDebug dbg, const ctkLDAPSearchFilter& filter)
  84. {
  85. dbg << filter.toString();
  86. return dbg.maybeSpace();
  87. }