1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "macabcondition.hxx"
22 #include "MacabHeader.hxx"
23 #include "MacabRecord.hxx"
24 #include <connectivity/CommonTools.hxx>
26 using namespace ::connectivity::macab
;
27 using namespace ::com::sun::star::sdbc
;
29 MacabCondition::~MacabCondition()
33 MacabConditionConstant::MacabConditionConstant(const bool bValue
)
39 bool MacabConditionConstant::isAlwaysTrue() const
44 bool MacabConditionConstant::isAlwaysFalse() const
49 bool MacabConditionConstant::eval(const MacabRecord
*) const
54 MacabConditionColumn::MacabConditionColumn(
55 const MacabHeader
*header
, std::u16string_view sColumnName
)
57 m_nFieldNumber(header
->getColumnNumber(sColumnName
))
61 bool MacabConditionColumn::isAlwaysTrue() const
63 // Sometimes true, sometimes false
67 bool MacabConditionColumn::isAlwaysFalse() const
69 // Sometimes true, sometimes false
73 MacabConditionNull::MacabConditionNull(const MacabHeader
*header
, std::u16string_view sColumnName
)
74 : MacabConditionColumn(header
, sColumnName
)
78 bool MacabConditionNull::eval(const MacabRecord
*aRecord
) const
80 macabfield
*aValue
= aRecord
->get(m_nFieldNumber
);
84 else if(aValue
->value
== nullptr)
90 MacabConditionNotNull::MacabConditionNotNull(
91 const MacabHeader
*header
, std::u16string_view sColumnName
)
92 : MacabConditionColumn(header
, sColumnName
)
96 bool MacabConditionNotNull::eval(const MacabRecord
*aRecord
) const
98 macabfield
*aValue
= aRecord
->get(m_nFieldNumber
);
100 if(aValue
== nullptr)
102 else if(aValue
->value
== nullptr)
108 MacabConditionCompare::MacabConditionCompare(const MacabHeader
*header
, std::u16string_view sColumnName
, const OUString
&sMatchString
)
109 : MacabConditionColumn(header
, sColumnName
),
110 m_sMatchString(sMatchString
)
114 MacabConditionEqual::MacabConditionEqual(const MacabHeader
*header
, std::u16string_view sColumnName
, const OUString
&sMatchString
)
115 : MacabConditionCompare(header
, sColumnName
, sMatchString
)
119 bool MacabConditionEqual::eval(const MacabRecord
*aRecord
) const
121 macabfield
*aValue
= aRecord
->get(m_nFieldNumber
);
123 if(aValue
== nullptr)
126 macabfield
*aValue2
= MacabRecord::createMacabField(m_sMatchString
,aValue
->type
);
128 if(aValue2
== nullptr)
131 sal_Int32 nReturn
= MacabRecord::compareFields(aValue
, aValue2
);
137 MacabConditionDifferent::MacabConditionDifferent(const MacabHeader
*header
, std::u16string_view sColumnName
, const OUString
&sMatchString
)
138 : MacabConditionCompare(header
, sColumnName
, sMatchString
)
142 bool MacabConditionDifferent::eval(const MacabRecord
*aRecord
) const
144 macabfield
*aValue
= aRecord
->get(m_nFieldNumber
);
146 if(aValue
== nullptr)
149 macabfield
*aValue2
= MacabRecord::createMacabField(m_sMatchString
,aValue
->type
);
151 if(aValue2
== nullptr)
154 sal_Int32 nReturn
= MacabRecord::compareFields(aValue
, aValue2
);
160 MacabConditionSimilar::MacabConditionSimilar(const MacabHeader
*header
, std::u16string_view sColumnName
, const OUString
&sMatchString
)
161 : MacabConditionCompare(header
, sColumnName
, sMatchString
)
165 bool MacabConditionSimilar::eval(const MacabRecord
*aRecord
) const
167 macabfield
*aValue
= aRecord
->get(m_nFieldNumber
);
169 if(aValue
== nullptr)
172 OUString sName
= MacabRecord::fieldToString(aValue
);
174 return match(m_sMatchString
, sName
, '\0');
177 MacabConditionBoolean::MacabConditionBoolean(MacabCondition
*pLeft
, MacabCondition
*pRight
)
184 MacabConditionBoolean::~MacabConditionBoolean()
190 MacabConditionOr::MacabConditionOr(MacabCondition
*pLeft
, MacabCondition
*pRight
)
191 : MacabConditionBoolean(pLeft
, pRight
)
195 bool MacabConditionOr::isAlwaysTrue() const
197 return m_pLeft
->isAlwaysTrue() || m_pRight
->isAlwaysTrue();
200 bool MacabConditionOr::isAlwaysFalse() const
202 return m_pLeft
->isAlwaysFalse() && m_pRight
->isAlwaysFalse();
205 bool MacabConditionOr::eval(const MacabRecord
*aRecord
) const
207 // We avoid evaluating terms as much as we can
208 if (m_pLeft
->isAlwaysTrue() || m_pRight
->isAlwaysTrue()) return true;
209 if (m_pLeft
->isAlwaysFalse() && m_pRight
->isAlwaysFalse()) return false;
211 if (m_pLeft
->eval(aRecord
)) return true;
212 if (m_pRight
->eval(aRecord
)) return true;
217 MacabConditionAnd::MacabConditionAnd(MacabCondition
*pLeft
, MacabCondition
*pRight
)
218 : MacabConditionBoolean(pLeft
, pRight
)
222 bool MacabConditionAnd::isAlwaysTrue() const
224 return m_pLeft
->isAlwaysTrue() && m_pRight
->isAlwaysTrue();
227 bool MacabConditionAnd::isAlwaysFalse() const
229 return m_pLeft
->isAlwaysFalse() || m_pRight
->isAlwaysFalse();
232 bool MacabConditionAnd::eval(const MacabRecord
*aRecord
) const
234 // We avoid evaluating terms as much as we can
235 if (m_pLeft
->isAlwaysFalse() || m_pRight
->isAlwaysFalse()) return false;
236 if (m_pLeft
->isAlwaysTrue() && m_pRight
->isAlwaysTrue()) return true;
238 if (!m_pLeft
->eval(aRecord
)) return false;
239 if (!m_pRight
->eval(aRecord
)) return false;
244 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */