bump product version to 7.2.5.1
[LibreOffice.git] / connectivity / source / drivers / macab / macabcondition.cxx
blob41e087b2c4210e88cd4fae8a8c584e6d94098731
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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)
34 : MacabCondition(),
35 m_bValue(bValue)
39 bool MacabConditionConstant::isAlwaysTrue() const
41 return m_bValue;
44 bool MacabConditionConstant::isAlwaysFalse() const
46 return !m_bValue;
49 bool MacabConditionConstant::eval(const MacabRecord *) const
51 return m_bValue;
54 MacabConditionColumn::MacabConditionColumn(
55 const MacabHeader *header, std::u16string_view sColumnName)
56 : MacabCondition(),
57 m_nFieldNumber(header->getColumnNumber(sColumnName))
61 bool MacabConditionColumn::isAlwaysTrue() const
63 // Sometimes true, sometimes false
64 return false;
67 bool MacabConditionColumn::isAlwaysFalse() const
69 // Sometimes true, sometimes false
70 return 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);
82 if(aValue == nullptr)
83 return true;
84 else if(aValue->value == nullptr)
85 return true;
86 else
87 return false;
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)
101 return false;
102 else if(aValue->value == nullptr)
103 return false;
104 else
105 return true;
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)
124 return false;
126 macabfield *aValue2 = MacabRecord::createMacabField(m_sMatchString,aValue->type);
128 if(aValue2 == nullptr)
129 return false;
131 sal_Int32 nReturn = MacabRecord::compareFields(aValue, aValue2);
133 delete aValue2;
134 return nReturn == 0;
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)
147 return false;
149 macabfield *aValue2 = MacabRecord::createMacabField(m_sMatchString,aValue->type);
151 if(aValue2 == nullptr)
152 return false;
154 sal_Int32 nReturn = MacabRecord::compareFields(aValue, aValue2);
156 delete aValue2;
157 return nReturn != 0;
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)
170 return false;
172 OUString sName = MacabRecord::fieldToString(aValue);
174 return match(m_sMatchString, sName, '\0');
177 MacabConditionBoolean::MacabConditionBoolean(MacabCondition *pLeft, MacabCondition *pRight)
178 : MacabCondition(),
179 m_pLeft(pLeft),
180 m_pRight(pRight)
184 MacabConditionBoolean::~MacabConditionBoolean()
186 delete m_pLeft;
187 delete m_pRight;
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;
214 return false;
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;
241 return true;
244 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */