ctkLDAPSearchFilter.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. #ifndef CTKLDAPSEARCHFILTER_H
  16. #define CTKLDAPSEARCHFILTER_H
  17. #include "ctkPluginFrameworkExport.h"
  18. #include "ctkServiceReference.h"
  19. #include "ctkPluginFramework_global.h"
  20. #include <QSharedDataPointer>
  21. #include <QDebug>
  22. class ctkLDAPSearchFilterData;
  23. /**
  24. * An <a href="http://www.ietf.org/rfc/rfc1960.txt">RFC 1960</a>-based Filter.
  25. *
  26. * <p>
  27. * A {@code ctkLDAPSearchFilter} can be used numerous times to determine if the match
  28. * argument matches the filter string that was used to create the {@code ctkLDAPSearchFilter}.
  29. * <p>
  30. * Some examples of LDAP filters are:
  31. *
  32. * \verbatim
  33. * "(cn=Babs Jensen)"
  34. * "(!(cn=Tim Howes))"
  35. * "(&(" + ctkPluginConstants::OBJECTCLASS + "=Person)(|(sn=Jensen)(cn=Babs J*)))"
  36. * "(o=univ*of*mich*)"
  37. * \endverbatim
  38. *
  39. * \see "CTK Wiki for a description of the filter string syntax." TODO!
  40. * \threadsafe
  41. */
  42. class CTK_PLUGINFW_EXPORT ctkLDAPSearchFilter {
  43. public:
  44. ctkLDAPSearchFilter();
  45. /**
  46. * Creates a <code>ctkLDAPSearchFilter</code> object. This <code>ctkLDAPSearchFilter</code>
  47. * object may be used to match a <code>ctkServiceReference</code> object or a
  48. * <code>ctkDictionary</code> object.
  49. *
  50. * <p>
  51. * If the filter cannot be parsed, an std::invalid_argument will be
  52. * thrown with a human readable message where the filter became unparsable.
  53. *
  54. * @param filter The filter string.
  55. * @return A <code>ctkLDAPSearchFilter</code> object encapsulating the filter string.
  56. * @throws std::invalid_argument If <code>filter</code> contains an invalid
  57. * filter string that cannot be parsed.
  58. * @see "Framework specification for a description of the filter string syntax." TODO!
  59. */
  60. ctkLDAPSearchFilter(const QString& filter);
  61. ctkLDAPSearchFilter(const ctkLDAPSearchFilter& other);
  62. ~ctkLDAPSearchFilter();
  63. /**
  64. * Filter using a service's properties.
  65. * <p>
  66. * This {@code ctkLDAPSearchFilter} is executed using the keys and values of the
  67. * referenced service's properties. The keys are looked up in a case
  68. * insensitive manner.
  69. *
  70. * @param reference The reference to the service whose properties are used
  71. * in the match.
  72. * @return <code>true</code> if the service's properties match this
  73. * <code>ctkLDAPSearchFilter</code> <code>false</code> otherwise.
  74. */
  75. bool match(const ctkServiceReference& reference) const;
  76. /**
  77. * Filter using a <code>ctkDictionary</code> with case insensitive key lookup. This
  78. * <code>ctkLDAPSearchFilter</code> is executed using the specified <code>ctkDictionary</code>'s keys
  79. * and values. The keys are looked up in a case insensitive manner.
  80. *
  81. * @param dictionary The <code>ctkDictionary</code> whose key/value pairs are used
  82. * in the match.
  83. * @return <code>true</code> if the <code>ctkDictionary</code>'s values match this
  84. * filter; <code>false</code> otherwise.
  85. */
  86. bool match(const ctkDictionary& dictionary) const;
  87. /**
  88. * Filter using a <code>ctkDictionary</code>. This <code>ctkLDAPSearchFilter</code> is executed using
  89. * the specified <code>ctkDictionary</code>'s keys and values. The keys are looked
  90. * up in a normal manner respecting case.
  91. *
  92. * @param dictionary The <code>ctkDictionary</code> whose key/value pairs are used
  93. * in the match.
  94. * @return <code>true</code> if the <code>ctkDictionary</code>'s values match this
  95. * filter; <code>false</code> otherwise.
  96. */
  97. bool matchCase(const ctkDictionary& dictionary) const;
  98. /**
  99. * Returns this <code>ctkLDAPSearchFilter</code>'s filter string.
  100. * <p>
  101. * The filter string is normalized by removing whitespace which does not
  102. * affect the meaning of the filter.
  103. *
  104. * @return This <code>ctkLDAPSearchFilter</code>'s filter string.
  105. */
  106. QString toString() const;
  107. /**
  108. * Compares this <code>ctkLDAPSearchFilter</code> to another <code>ctkLDAPSearchFilter</code>.
  109. *
  110. * <p>
  111. * This implementation returns the result of calling
  112. * <code>this->toString() == other.toString()</code>.
  113. *
  114. * @param other The object to compare against this <code>ctkLDAPSearchFilter</code>.
  115. * @return Returns the result of calling
  116. * <code>this->toString() == other.toString()</code>.
  117. */
  118. bool operator==(const ctkLDAPSearchFilter& other) const;
  119. ctkLDAPSearchFilter& operator=(const ctkLDAPSearchFilter& filter);
  120. protected:
  121. QSharedDataPointer<ctkLDAPSearchFilterData> d;
  122. };
  123. CTK_PLUGINFW_EXPORT QDebug operator<<(QDebug dbg, const ctkLDAPSearchFilter& filter);
  124. #endif // CTKLDAPSEARCHFILTER_H