Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
usLDAPFilter.cpp
Go to the documentation of this file.
1 /*=============================================================================
2 
3  Library: CppMicroServices
4 
5  Copyright (c) German Cancer Research Center,
6  Division of Medical and Biological Informatics
7 
8  Licensed under the Apache License, Version 2.0 (the "License");
9  you may not use this file except in compliance with the License.
10  You may obtain a copy of the License at
11 
12  http://www.apache.org/licenses/LICENSE-2.0
13 
14  Unless required by applicable law or agreed to in writing, software
15  distributed under the License is distributed on an "AS IS" BASIS,
16  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  See the License for the specific language governing permissions and
18  limitations under the License.
19 
20 =============================================================================*/
21 
22 #include "usLDAPFilter.h"
23 #include "usLDAPExpr_p.h"
24 #include "usServicePropertiesImpl_p.h"
25 #include "usServiceReference.h"
26 #include "usServiceReferenceBasePrivate.h"
27 
28 #include <stdexcept>
29 
30 US_BEGIN_NAMESPACE
31 
32 class LDAPFilterData : public SharedData
33 {
34 public:
35 
36  LDAPFilterData() : ldapExpr()
37  {}
38 
39  LDAPFilterData(const std::string& filter)
40  : ldapExpr(filter)
41  {}
42 
43  LDAPFilterData(const LDAPFilterData& other)
44  : SharedData(other), ldapExpr(other.ldapExpr)
45  {}
46 
47  LDAPExpr ldapExpr;
48 };
49 
50 LDAPFilter::LDAPFilter()
51  : d(0)
52 {
53 }
54 
55 LDAPFilter::LDAPFilter(const std::string& filter)
56  : d(0)
57 {
58  try
59  {
60  d = new LDAPFilterData(filter);
61  }
62  catch (const std::exception& e)
63  {
64  throw std::invalid_argument(e.what());
65  }
66 }
67 
69  : d(other.d)
70 {
71 }
72 
74 {
75 }
76 
77 LDAPFilter::operator bool_type() const
78 {
79  return d.ConstData() != 0 ? &LDAPFilter::d : NULL;
80 }
81 
82 bool LDAPFilter::Match(const ServiceReferenceBase& reference) const
83 {
84  return d->ldapExpr.Evaluate(reference.d->GetProperties(), true);
85 }
86 
87 bool LDAPFilter::Match(const ServiceProperties& dictionary) const
88 {
89  return d->ldapExpr.Evaluate(ServicePropertiesImpl(dictionary), false);
90 }
91 
92 bool LDAPFilter::MatchCase(const ServiceProperties& dictionary) const
93 {
94  return d->ldapExpr.Evaluate(ServicePropertiesImpl(dictionary), true);
95 }
96 
97 std::string LDAPFilter::ToString() const
98 {
99  return d->ldapExpr.ToString();
100 }
101 
102 bool LDAPFilter::operator==(const LDAPFilter& other) const
103 {
104  return d->ldapExpr.ToString() == other.d->ldapExpr.ToString();
105 }
106 
108 {
109  d = filter.d;
110 
111  return *this;
112 }
113 
114 US_END_NAMESPACE
115 
116 US_USE_NAMESPACE
117 
118 std::ostream& operator<<(std::ostream& os, const LDAPFilter& filter)
119 {
120  return os << filter.ToString();
121 }
bool MatchCase(const ServiceProperties &dictionary) const
LDAPFilter & operator=(const LDAPFilter &filter)
US_Core_EXPORT std::ostream & operator<<(std::ostream &os, ModuleEvent::Type eventType)
SharedDataPointer< LDAPFilterData > d
Definition: usLDAPFilter.h:165
bool operator==(const LDAPFilter &other) const
US_UNORDERED_MAP_TYPE< std::string, Any > ServiceProperties
std::string ToString() const
bool Match(const ServiceReferenceBase &reference) const