/*============================================================================= Library: CTK Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =============================================================================*/ #ifndef CTKLDAPSEARCHFILTER_H #define CTKLDAPSEARCHFILTER_H #include "ctkPluginFrameworkExport.h" #include "ctkServiceReference.h" #include "ctkDictionary.h" #include #include class ctkLDAPSearchFilterData; /** * \ingroup PluginFramework * * An RFC 1960-based Filter. * *

* A ctkLDAPSearchFilter can be used numerous times to determine if the match * argument matches the filter string that was used to create the ctkLDAPSearchFilter. *

* Some examples of LDAP filters are: * * \verbatim * "(cn=Babs Jensen)" * "(!(cn=Tim Howes))" * "(&(" + ctkPluginConstants::OBJECTCLASS + "=Person)(|(sn=Jensen)(cn=Babs J*)))" * "(o=univ*of*mich*)" * \endverbatim * * \see "CTK Wiki for a description of the filter string syntax." TODO! * \remarks This class is thread safe. */ class CTK_PLUGINFW_EXPORT ctkLDAPSearchFilter { public: /** * Creates in invalid ctkLDAPSearchFilter object. * Test the validity by using the boolean conversion operator. * *

* Calling methods on an invalid ctkLDAPSearchFilter * will result in undefined behavior. */ ctkLDAPSearchFilter(); /** * Creates a ctkLDAPSearchFilter object. This ctkLDAPSearchFilter * object may be used to match a ctkServiceReference object or a * ctkDictionary object. * *

* If the filter cannot be parsed, an std::invalid_argument will be * thrown with a human readable message where the filter became unparsable. * * @param filter The filter string. * @return A ctkLDAPSearchFilter object encapsulating the filter string. * @throws std::invalid_argument If filter contains an invalid * filter string that cannot be parsed. * @see "Framework specification for a description of the filter string syntax." TODO! */ ctkLDAPSearchFilter(const QString& filter); ctkLDAPSearchFilter(const ctkLDAPSearchFilter& other); ~ctkLDAPSearchFilter(); operator bool() const; /** * Filter using a service's properties. *

* This ctkLDAPSearchFilter is executed using the keys and values of the * referenced service's properties. The keys are looked up in a case * insensitive manner. * * @param reference The reference to the service whose properties are used * in the match. * @return true if the service's properties match this * ctkLDAPSearchFilter false otherwise. */ bool match(const ctkServiceReference& reference) const; /** * Filter using a ctkDictionary with case insensitive key lookup. This * ctkLDAPSearchFilter is executed using the specified ctkDictionary's keys * and values. The keys are looked up in a case insensitive manner. * * @param dictionary The ctkDictionary whose key/value pairs are used * in the match. * @return true if the ctkDictionary's values match this * filter; false otherwise. */ bool match(const ctkDictionary& dictionary) const; /** * Filter using a ctkDictionary. This ctkLDAPSearchFilter is executed using * the specified ctkDictionary's keys and values. The keys are looked * up in a normal manner respecting case. * * @param dictionary The ctkDictionary whose key/value pairs are used * in the match. * @return true if the ctkDictionary's values match this * filter; false otherwise. */ bool matchCase(const ctkDictionary& dictionary) const; /** * Returns this ctkLDAPSearchFilter's filter string. *

* The filter string is normalized by removing whitespace which does not * affect the meaning of the filter. * * @return This ctkLDAPSearchFilter's filter string. */ QString toString() const; /** * Compares this ctkLDAPSearchFilter to another ctkLDAPSearchFilter. * *

* This implementation returns the result of calling * this->toString() == other.toString(). * * @param other The object to compare against this ctkLDAPSearchFilter. * @return Returns the result of calling * this->toString() == other.toString(). */ bool operator==(const ctkLDAPSearchFilter& other) const; ctkLDAPSearchFilter& operator=(const ctkLDAPSearchFilter& filter); protected: QSharedDataPointer d; }; /** * \ingroup PluginFramework */ CTK_PLUGINFW_EXPORT QDebug operator<<(QDebug dbg, const ctkLDAPSearchFilter& filter); #endif // CTKLDAPSEARCHFILTER_H