1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef CONDITIONALEXPRESSION_HXX
25 #define CONDITIONALEXPRESSION_HXX
26 
27 #include "dllapi.h"
28 
29 /** === begin UNO includes === **/
30 /** === end UNO includes === **/
31 
32 #include <rtl/ustring.hxx>
33 
34 #include <boost/shared_ptr.hpp>
35 
36 #include <map>
37 
38 //........................................................................
39 namespace rptui
40 {
41 //........................................................................
42 
43     // =============================================================================
44     // = ConditionalExpression
45     // =============================================================================
46     class REPORTDESIGN_DLLPUBLIC ConditionalExpression
47     {
48     private:
49         const ::rtl::OUString       m_sPattern;
50 
51     public:
52         ConditionalExpression( const sal_Char* _pAsciiPattern );
53 
54         /** assembles an expression string from a field data source, and one or two operands
55         */
56         ::rtl::OUString     assembleExpression( const ::rtl::OUString& _rFieldDataSource, const ::rtl::OUString& _rLHS, const ::rtl::OUString& _rRHS ) const;
57 
58         /** matches the given expression string to the expression pattern represented by the object
59             @param  _rExpression
60                 the expression to match
61             @param  _rFieldDataSource
62                 the field data source
63             @param  _out_rLHS
64                 output parameter taking the left hand side operand, if successful
65             @param  _out_rRHS
66                 output parameter taking the right hand side operand, if successful
67             @return
68                 <TRUE/> if and only if the expression string could be successfully matched to
69                 the pattern.
70         */
71         bool                matchExpression( const ::rtl::OUString& _rExpression, const ::rtl::OUString& _rFieldDataSource, ::rtl::OUString& _out_rLHS, ::rtl::OUString& _out_rRHS ) const;
72     };
73 
74     //========================================================================
75     //= ConditionType
76     //========================================================================
77     enum ConditionType
78     {
79         eFieldValueComparison   = 0,
80         eExpression             = 1
81     };
82 
83     //========================================================================
84     //= ComparisonOperation
85     //========================================================================
86     enum ComparisonOperation
87     {
88         eBetween        = 0,
89         eNotBetween     = 1,
90         eEqualTo        = 2,
91         eNotEqualTo     = 3,
92         eGreaterThan    = 4,
93         eLessThan       = 5,
94         eGreaterOrEqual = 6,
95         eLessOrEqual    = 7
96     };
97 
98     typedef ::boost::shared_ptr< ConditionalExpression >                PConditionalExpression;
99     typedef ::std::map< ComparisonOperation, PConditionalExpression >   ConditionalExpressions;
100 
101     // =============================================================================
102     // = ConditionalExpressionFactory
103     // =============================================================================
104     class REPORTDESIGN_DLLPUBLIC ConditionalExpressionFactory
105     {
106     public:
107         /// fills the given map with all ConditionalExpressions which we know
108         static size_t  getKnownConditionalExpressions( ConditionalExpressions& _out_rCondExp );
109 
110     private:
111         ConditionalExpressionFactory();                                                 // never implemented
112         ConditionalExpressionFactory( const ConditionalExpressionFactory& );            // never implemented
113         ConditionalExpressionFactory& operator=( const ConditionalExpressionFactory& ); // never implemented
114     };
115 //........................................................................
116 } // namespace rptui
117 //........................................................................
118 
119 #endif // CONDITIONALEXPRESSION_HXX
120