Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / connectivity / source / drivers / macab / macabcondition.cxx
blob186802670f8bbee37f631aff9f40e9d40483edf0
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 sal_Bool bValue)
34 : MacabCondition(),
35 m_bValue(bValue)
39 sal_Bool MacabConditionConstant::isAlwaysTrue() const
41 return m_bValue;
44 sal_Bool MacabConditionConstant::isAlwaysFalse() const
46 return !m_bValue;
49 sal_Bool MacabConditionConstant::eval(const MacabRecord *) const
51 return m_bValue;
54 MacabConditionColumn::MacabConditionColumn(const MacabHeader *header, const OUString &sColumnName) throw(SQLException)
55 : MacabCondition(),
56 m_nFieldNumber(header->getColumnNumber(sColumnName))
60 sal_Bool MacabConditionColumn::isAlwaysTrue() const
62 // Sometimes true, sometimes false
63 return sal_False;
66 sal_Bool MacabConditionColumn::isAlwaysFalse() const
68 // Sometimes true, sometimes false
69 return sal_False;
72 MacabConditionNull::MacabConditionNull(const MacabHeader *header, const OUString &sColumnName) throw(SQLException)
73 : MacabConditionColumn(header, sColumnName)
77 sal_Bool MacabConditionNull::eval(const MacabRecord *aRecord) const
79 macabfield *aValue = aRecord->get(m_nFieldNumber);
81 if(aValue == NULL)
82 return sal_True;
83 else if(aValue->value == NULL)
84 return sal_True;
85 else
86 return sal_False;
89 MacabConditionNotNull::MacabConditionNotNull(const MacabHeader *header, const OUString &sColumnName) throw(SQLException)
90 : MacabConditionColumn(header, sColumnName)
94 sal_Bool MacabConditionNotNull::eval(const MacabRecord *aRecord) const
96 macabfield *aValue = aRecord->get(m_nFieldNumber);
98 if(aValue == NULL)
99 return sal_False;
100 else if(aValue->value == NULL)
101 return sal_False;
102 else
103 return sal_True;
106 MacabConditionCompare::MacabConditionCompare(const MacabHeader *header, const OUString &sColumnName, const OUString &sMatchString) throw(SQLException)
107 : MacabConditionColumn(header, sColumnName),
108 m_sMatchString(sMatchString)
112 MacabConditionEqual::MacabConditionEqual(const MacabHeader *header, const OUString &sColumnName, const OUString &sMatchString) throw(SQLException)
113 : MacabConditionCompare(header, sColumnName, sMatchString)
117 sal_Bool MacabConditionEqual::eval(const MacabRecord *aRecord) const
119 macabfield *aValue = aRecord->get(m_nFieldNumber);
121 if(aValue == NULL)
122 return sal_False;
124 macabfield *aValue2 = MacabRecord::createMacabField(m_sMatchString,aValue->type);
126 if(aValue2 == NULL)
127 return sal_False;
129 sal_Int32 nReturn = MacabRecord::compareFields(aValue, aValue2);
131 delete aValue2;
132 return nReturn == 0;
135 MacabConditionDifferent::MacabConditionDifferent(const MacabHeader *header, const OUString &sColumnName, const OUString &sMatchString) throw(SQLException)
136 : MacabConditionCompare(header, sColumnName, sMatchString)
140 sal_Bool MacabConditionDifferent::eval(const MacabRecord *aRecord) const
142 macabfield *aValue = aRecord->get(m_nFieldNumber);
144 if(aValue == NULL)
145 return sal_False;
147 macabfield *aValue2 = MacabRecord::createMacabField(m_sMatchString,aValue->type);
149 if(aValue2 == NULL)
150 return sal_False;
152 sal_Int32 nReturn = MacabRecord::compareFields(aValue, aValue2);
154 delete aValue2;
155 return nReturn != 0;
158 MacabConditionSimilar::MacabConditionSimilar(const MacabHeader *header, const OUString &sColumnName, const OUString &sMatchString) throw(SQLException)
159 : MacabConditionCompare(header, sColumnName, sMatchString)
163 sal_Bool MacabConditionSimilar::eval(const MacabRecord *aRecord) const
165 macabfield *aValue = aRecord->get(m_nFieldNumber);
167 if(aValue == NULL)
168 return sal_False;
170 OUString sName = MacabRecord::fieldToString(aValue);
172 return match(m_sMatchString, sName, '\0');
175 MacabConditionBoolean::MacabConditionBoolean(MacabCondition *pLeft, MacabCondition *pRight)
176 : MacabCondition(),
177 m_pLeft(pLeft),
178 m_pRight(pRight)
182 MacabConditionBoolean::~MacabConditionBoolean()
184 delete m_pLeft;
185 delete m_pRight;
188 MacabConditionOr::MacabConditionOr(MacabCondition *pLeft, MacabCondition *pRight)
189 : MacabConditionBoolean(pLeft, pRight)
193 sal_Bool MacabConditionOr::isAlwaysTrue() const
195 return m_pLeft->isAlwaysTrue() || m_pRight->isAlwaysTrue();
198 sal_Bool MacabConditionOr::isAlwaysFalse() const
200 return m_pLeft->isAlwaysFalse() && m_pRight->isAlwaysFalse();
203 sal_Bool MacabConditionOr::eval(const MacabRecord *aRecord) const
205 // We avoid evaluating terms as much as we can
206 if (m_pLeft->isAlwaysTrue() || m_pRight->isAlwaysTrue()) return sal_True;
207 if (m_pLeft->isAlwaysFalse() && m_pRight->isAlwaysFalse()) return sal_False;
209 if (m_pLeft->eval(aRecord)) return sal_True;
210 if (m_pRight->eval(aRecord)) return sal_True;
212 return sal_False;
215 MacabConditionAnd::MacabConditionAnd(MacabCondition *pLeft, MacabCondition *pRight)
216 : MacabConditionBoolean(pLeft, pRight)
220 sal_Bool MacabConditionAnd::isAlwaysTrue() const
222 return m_pLeft->isAlwaysTrue() && m_pRight->isAlwaysTrue();
225 sal_Bool MacabConditionAnd::isAlwaysFalse() const
227 return m_pLeft->isAlwaysFalse() || m_pRight->isAlwaysFalse();
230 sal_Bool MacabConditionAnd::eval(const MacabRecord *aRecord) const
232 // We avoid evaluating terms as much as we can
233 if (m_pLeft->isAlwaysFalse() || m_pRight->isAlwaysFalse()) return sal_False;
234 if (m_pLeft->isAlwaysTrue() && m_pRight->isAlwaysTrue()) return sal_True;
236 if (!m_pLeft->eval(aRecord)) return sal_False;
237 if (!m_pRight->eval(aRecord)) return sal_False;
239 return sal_True;
242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */