Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
usLDAPProp.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 "usLDAPProp.h"
23 
24 #include <stdexcept>
25 
26 US_BEGIN_NAMESPACE
27 
28 LDAPPropExpr::LDAPPropExpr(const std::string& expr)
29  : m_ldapExpr(expr)
30 {}
31 
32 LDAPPropExpr& LDAPPropExpr::operator!()
33 {
34  if (m_ldapExpr.empty()) return *this;
35 
36  m_ldapExpr = "(!" + m_ldapExpr + ")";
37  return *this;
38 }
39 
40 LDAPPropExpr::operator std::string() const
41 {
42  return m_ldapExpr;
43 }
44 
45 bool LDAPPropExpr::IsNull() const
46 {
47  return m_ldapExpr.empty();
48 }
49 
50 
51 LDAPProp::LDAPProp(const std::string& property)
52  : m_property(property)
53 {
54  if (m_property.empty()) throw std::invalid_argument("property must not be empty");
55 }
56 
57 LDAPPropExpr LDAPProp::operator==(const std::string& s) const
58 {
59  if (s.empty()) return LDAPPropExpr(s);
60  return LDAPPropExpr("(" + m_property + "=" + s + ")");
61 }
62 
63 LDAPPropExpr LDAPProp::operator==(const us::Any& any) const
64 {
65  return operator==(any.ToString());
66 }
67 
68 LDAPProp::operator LDAPPropExpr () const
69 {
70  return LDAPPropExpr("(" + m_property + "=*)");
71 }
72 
73 LDAPPropExpr LDAPProp::operator!() const
74 {
75  return LDAPPropExpr("(!(" + m_property + "=*))");
76 }
77 
78 LDAPPropExpr LDAPProp::operator!=(const std::string& s) const
79 {
80  if (s.empty()) return LDAPPropExpr(s);
81  return LDAPPropExpr("(!(" + m_property + "=" + s + "))");
82 }
83 
84 LDAPPropExpr LDAPProp::operator!=(const us::Any& any) const
85 {
86  return operator!=(any.ToString());
87 }
88 
89 LDAPPropExpr LDAPProp::operator>=(const std::string& s) const
90 {
91  if (s.empty()) return LDAPPropExpr(s);
92  return LDAPPropExpr("(" + m_property + ">=" + s + ")");
93 }
94 
95 LDAPPropExpr LDAPProp::operator>=(const us::Any& any) const
96 {
97  return operator>=(any.ToString());
98 }
99 
100 LDAPPropExpr LDAPProp::operator<=(const std::string& s) const
101 {
102  if (s.empty()) return LDAPPropExpr(s);
103  return LDAPPropExpr("(" + m_property + "<=" + s + ")");
104 }
105 
106 LDAPPropExpr LDAPProp::operator<=(const us::Any& any) const
107 {
108  return operator<=(any.ToString());
109 }
110 
111 LDAPPropExpr LDAPProp::Approx(const std::string& s) const
112 {
113  if (s.empty()) return LDAPPropExpr(s);
114  return LDAPPropExpr("(" + m_property + "~=" + s + ")");
115 }
116 
117 LDAPPropExpr LDAPProp::Approx(const us::Any& any) const
118 {
119  return Approx(any.ToString());
120 }
121 
122 US_END_NAMESPACE
123 
124 us::LDAPPropExpr operator&&(const us::LDAPPropExpr& left, const us::LDAPPropExpr& right)
125 {
126  if (left.IsNull()) return right;
127  if (right.IsNull()) return left;
128  return us::LDAPPropExpr("(&" + static_cast<std::string>(left) + static_cast<std::string>(right) + ")");
129 }
130 
131 us::LDAPPropExpr operator||(const us::LDAPPropExpr& left, const us::LDAPPropExpr& right)
132 {
133  if (left.IsNull()) return right;
134  if (right.IsNull()) return left;
135  return us::LDAPPropExpr("(|" + static_cast<std::string>(left) + static_cast<std::string>(right) + ")");
136 }
us::LDAPPropExpr operator&&(const us::LDAPPropExpr &left, const us::LDAPPropExpr &right)
Definition: usLDAPProp.cpp:124
us::LDAPPropExpr operator||(const us::LDAPPropExpr &left, const us::LDAPPropExpr &right)
Definition: usLDAPProp.cpp:131
LDAPPropExpr Approx(const std::string &s) const
Definition: usLDAPProp.cpp:111
LDAPPropExpr operator==(const std::string &s) const
Definition: usLDAPProp.cpp:57
LDAPPropExpr operator!() const
Definition: usLDAPProp.cpp:73
LDAPProp(const std::string &property)
Definition: usLDAPProp.cpp:51
LDAPPropExpr operator>=(const std::string &s) const
Definition: usLDAPProp.cpp:89
LDAPPropExpr operator<=(const std::string &s) const
Definition: usLDAPProp.cpp:100
LDAPPropExpr operator!=(const std::string &s) const
Definition: usLDAPProp.cpp:78
Definition: usAny.h:163
std::string ToString() const
Definition: usAny.h:257