1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _CONNECTIVITY_MACAB_CONDITION_HXX_
29 #define _CONNECTIVITY_MACAB_CONDITION_HXX_
30 
31 #include "MacabHeader.hxx"
32 #include "MacabRecord.hxx"
33 
34 #ifndef _COMPHELPER_TYPES_H_
35 #include <comphelper/types.hxx>
36 #endif
37 #include <connectivity/dbexception.hxx>
38 
39 namespace connectivity
40 {
41 	namespace macab
42 	{
43 // -----------------------------------------------------------------------------
44 class MacabCondition
45 {
46 	public:
47 		virtual ~MacabCondition();
48 		virtual sal_Bool isAlwaysTrue() const = 0;
49 		virtual sal_Bool isAlwaysFalse() const = 0;
50 		virtual sal_Bool eval(const MacabRecord *aRecord) const = 0;
51 };
52 // -----------------------------------------------------------------------------
53 class MacabConditionConstant : public MacabCondition
54 {
55 	protected:
56 		sal_Bool m_bValue;
57 
58 	public:
59 		MacabConditionConstant(const sal_Bool bValue);
60 		virtual sal_Bool isAlwaysTrue() const;
61 		virtual sal_Bool isAlwaysFalse() const;
62 		virtual sal_Bool eval(const MacabRecord *aRecord) const;
63 };
64 // -----------------------------------------------------------------------------
65 class MacabConditionColumn : public MacabCondition
66 {
67 	protected:
68 		sal_Int32 m_nFieldNumber;
69 
70 	public:
71 		MacabConditionColumn(
72 			const MacabHeader *header,
73 			const ::rtl::OUString &sColumnName) throw(::com::sun::star::sdbc::SQLException);
74 		virtual sal_Bool isAlwaysTrue() const;
75 		virtual sal_Bool isAlwaysFalse() const;
76 };
77 // -----------------------------------------------------------------------------
78 class MacabConditionNull : public MacabConditionColumn
79 {
80 	public:
81 		MacabConditionNull(
82 			const MacabHeader *header,
83 			const ::rtl::OUString &sColumnName) throw(::com::sun::star::sdbc::SQLException);
84 		virtual sal_Bool eval(const MacabRecord *aRecord) const;
85 };
86 // -----------------------------------------------------------------------------
87 class MacabConditionNotNull : public MacabConditionColumn
88 {
89 	public:
90 		MacabConditionNotNull(
91 			const MacabHeader *header,
92 			const ::rtl::OUString &sColumnName) throw(::com::sun::star::sdbc::SQLException);
93 		virtual sal_Bool eval(const MacabRecord *aRecord) const;
94 };
95 // -----------------------------------------------------------------------------
96 class MacabConditionCompare : public MacabConditionColumn
97 {
98 	protected:
99 		const ::rtl::OUString m_sMatchString;
100 
101 	public:
102 		MacabConditionCompare(
103 			const MacabHeader *header,
104 			const ::rtl::OUString &sColumnName,
105 			const ::rtl::OUString &sMatchString) throw(::com::sun::star::sdbc::SQLException);
106 };
107 // -----------------------------------------------------------------------------
108 class MacabConditionEqual : public MacabConditionCompare
109 {
110 	public:
111 		MacabConditionEqual(
112 			const MacabHeader *header,
113 			const ::rtl::OUString &sColumnName,
114 			const ::rtl::OUString &sMatchString) throw(::com::sun::star::sdbc::SQLException);
115 		virtual sal_Bool eval(const MacabRecord *aRecord) const;
116 };
117 // -----------------------------------------------------------------------------
118 class MacabConditionDifferent : public MacabConditionCompare
119 {
120 	public:
121 		MacabConditionDifferent(
122 			const MacabHeader *header,
123 			const ::rtl::OUString &sColumnName,
124 			const ::rtl::OUString &sMatchString) throw(::com::sun::star::sdbc::SQLException);
125 		virtual sal_Bool eval(const MacabRecord *aRecord) const;
126 };
127 // -----------------------------------------------------------------------------
128 class MacabConditionSimilar : public MacabConditionCompare
129 {
130 	public:
131 		MacabConditionSimilar(
132 			const MacabHeader *header,
133 			const ::rtl::OUString &sColumnName,
134 			const ::rtl::OUString &sMatchString) throw(::com::sun::star::sdbc::SQLException);
135 		virtual sal_Bool eval(const MacabRecord *aRecord) const;
136 };
137 // -----------------------------------------------------------------------------
138 class MacabConditionBoolean : public MacabCondition
139 {
140 	protected:
141 		MacabCondition *m_pLeft, *m_pRight;
142 
143 	public:
144 		MacabConditionBoolean(MacabCondition *pLeft, MacabCondition *pRight);
145 		virtual ~MacabConditionBoolean();
146 };
147 // -----------------------------------------------------------------------------
148 class MacabConditionOr : public MacabConditionBoolean
149 {
150 	public:
151 		MacabConditionOr(MacabCondition *pLeft, MacabCondition *pRight);
152 		virtual sal_Bool isAlwaysTrue() const;
153 		virtual sal_Bool isAlwaysFalse() const;
154 		virtual sal_Bool eval(const MacabRecord *aRecord) const;
155 };
156 // -----------------------------------------------------------------------------
157 class MacabConditionAnd : public MacabConditionBoolean
158 {
159 	public:
160 		MacabConditionAnd(MacabCondition *pLeft, MacabCondition *pRight);
161 		virtual sal_Bool isAlwaysTrue() const;
162 		virtual sal_Bool isAlwaysFalse() const;
163 		virtual sal_Bool eval(const MacabRecord *aRecord) const;
164 };
165 // -----------------------------------------------------------------------------
166 	}
167 }
168 
169 #endif // _CONNECTIVITY_MACAB_CONDITION_HXX_
170