LibreOffice Module connectivity (master) 1
macabcondition.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21#include "macabcondition.hxx"
22#include "MacabHeader.hxx"
23#include "MacabRecord.hxx"
25
26using namespace ::connectivity::macab;
27using namespace ::com::sun::star::sdbc;
28
29MacabCondition::~MacabCondition()
30{
31}
32
33MacabConditionConstant::MacabConditionConstant(const bool bValue)
35 m_bValue(bValue)
36{
37}
38
40{
41 return m_bValue;
42}
43
45{
46 return !m_bValue;
47}
48
50{
51 return m_bValue;
52}
53
55 const MacabHeader *header, std::u16string_view sColumnName)
57 m_nFieldNumber(header->getColumnNumber(sColumnName))
58{
59}
60
62{
63 // Sometimes true, sometimes false
64 return false;
65}
66
68{
69 // Sometimes true, sometimes false
70 return false;
71}
72
73MacabConditionNull::MacabConditionNull(const MacabHeader *header, std::u16string_view sColumnName)
74 : MacabConditionColumn(header, sColumnName)
75{
76}
77
78bool MacabConditionNull::eval(const MacabRecord *aRecord) const
79{
80 macabfield *aValue = aRecord->get(m_nFieldNumber);
81
82 if(aValue == nullptr)
83 return true;
84 else if(aValue->value == nullptr)
85 return true;
86 else
87 return false;
88}
89
91 const MacabHeader *header, std::u16string_view sColumnName)
92 : MacabConditionColumn(header, sColumnName)
93{
94}
95
96bool MacabConditionNotNull::eval(const MacabRecord *aRecord) const
97{
98 macabfield *aValue = aRecord->get(m_nFieldNumber);
99
100 if(aValue == nullptr)
101 return false;
102 else if(aValue->value == nullptr)
103 return false;
104 else
105 return true;
106}
107
108MacabConditionCompare::MacabConditionCompare(const MacabHeader *header, std::u16string_view sColumnName, const OUString &sMatchString)
109 : MacabConditionColumn(header, sColumnName),
110 m_sMatchString(sMatchString)
111{
112}
113
114MacabConditionEqual::MacabConditionEqual(const MacabHeader *header, std::u16string_view sColumnName, const OUString &sMatchString)
115 : MacabConditionCompare(header, sColumnName, sMatchString)
116{
117}
118
119bool MacabConditionEqual::eval(const MacabRecord *aRecord) const
120{
121 macabfield *aValue = aRecord->get(m_nFieldNumber);
122
123 if(aValue == nullptr)
124 return false;
125
127
128 if(aValue2 == nullptr)
129 return false;
130
131 sal_Int32 nReturn = MacabRecord::compareFields(aValue, aValue2);
132
133 delete aValue2;
134 return nReturn == 0;
135}
136
137MacabConditionDifferent::MacabConditionDifferent(const MacabHeader *header, std::u16string_view sColumnName, const OUString &sMatchString)
138 : MacabConditionCompare(header, sColumnName, sMatchString)
139{
140}
141
143{
144 macabfield *aValue = aRecord->get(m_nFieldNumber);
145
146 if(aValue == nullptr)
147 return false;
148
150
151 if(aValue2 == nullptr)
152 return false;
153
154 sal_Int32 nReturn = MacabRecord::compareFields(aValue, aValue2);
155
156 delete aValue2;
157 return nReturn != 0;
158}
159
160MacabConditionSimilar::MacabConditionSimilar(const MacabHeader *header, std::u16string_view sColumnName, const OUString &sMatchString)
161 : MacabConditionCompare(header, sColumnName, sMatchString)
162{
163}
164
165bool MacabConditionSimilar::eval(const MacabRecord *aRecord) const
166{
167 macabfield *aValue = aRecord->get(m_nFieldNumber);
168
169 if(aValue == nullptr)
170 return false;
171
172 OUString sName = MacabRecord::fieldToString(aValue);
173
174 return match(m_sMatchString, sName, '\0');
175}
176
178 : MacabCondition(),
179 m_pLeft(pLeft),
180 m_pRight(pRight)
181{
182}
183
185{
186 delete m_pLeft;
187 delete m_pRight;
188}
189
191 : MacabConditionBoolean(pLeft, pRight)
192{
193}
194
196{
198}
199
201{
203}
204
205bool MacabConditionOr::eval(const MacabRecord *aRecord) const
206{
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;
210
211 if (m_pLeft->eval(aRecord)) return true;
212 if (m_pRight->eval(aRecord)) return true;
213
214 return false;
215}
216
218 : MacabConditionBoolean(pLeft, pRight)
219{
220}
221
223{
225}
226
228{
230}
231
232bool MacabConditionAnd::eval(const MacabRecord *aRecord) const
233{
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;
237
238 if (!m_pLeft->eval(aRecord)) return false;
239 if (!m_pRight->eval(aRecord)) return false;
240
241 return true;
242}
243
244/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr sal_Int8 header[]
MacabConditionAnd(MacabCondition *pLeft, MacabCondition *pRight)
virtual bool isAlwaysTrue() const override
virtual bool isAlwaysFalse() const override
virtual bool eval(const MacabRecord *aRecord) const override
MacabConditionBoolean(MacabCondition *pLeft, MacabCondition *pRight)
virtual bool isAlwaysTrue() const override
virtual bool isAlwaysFalse() const override
MacabConditionColumn(const MacabHeader *header, std::u16string_view sColumnName)
MacabConditionCompare(const MacabHeader *header, std::u16string_view sColumnName, const OUString &sMatchString)
virtual bool isAlwaysFalse() const override
virtual bool eval(const MacabRecord *aRecord) const override
virtual bool isAlwaysTrue() const override
MacabConditionDifferent(const MacabHeader *header, std::u16string_view sColumnName, const OUString &sMatchString)
virtual bool eval(const MacabRecord *aRecord) const override
MacabConditionEqual(const MacabHeader *header, std::u16string_view sColumnName, const OUString &sMatchString)
virtual bool eval(const MacabRecord *aRecord) const override
virtual bool eval(const MacabRecord *aRecord) const override
MacabConditionNotNull(const MacabHeader *header, std::u16string_view sColumnName)
virtual bool eval(const MacabRecord *aRecord) const override
MacabConditionNull(const MacabHeader *header, std::u16string_view sColumnName)
virtual bool isAlwaysFalse() const override
virtual bool eval(const MacabRecord *aRecord) const override
MacabConditionOr(MacabCondition *pLeft, MacabCondition *pRight)
virtual bool isAlwaysTrue() const override
MacabConditionSimilar(const MacabHeader *header, std::u16string_view sColumnName, const OUString &sMatchString)
virtual bool eval(const MacabRecord *aRecord) const override
virtual bool isAlwaysFalse() const =0
virtual bool isAlwaysTrue() const =0
virtual bool eval(const MacabRecord *aRecord) const =0
macabfield * get(const sal_Int32 i) const
static macabfield * createMacabField(const OUString &_newFieldString, const ABPropertyType _abtype)
static OUString fieldToString(const macabfield *_aField)
static sal_Int32 compareFields(const macabfield *_field1, const macabfield *_field2)
OUString sName
bool match(const sal_Unicode *pWild, const sal_Unicode *pStr, const sal_Unicode cEscape)
Definition: CommonTools.cxx:51