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 REPORTFORMULA_HXX
25 #define REPORTFORMULA_HXX
26 
27 #include "dllapi.h"
28 
29 /** === begin UNO includes === **/
30 #include <com/sun/star/uno/Any.hxx>
31 /** === end UNO includes === **/
32 
33 #include <osl/diagnose.h>
34 
35 //........................................................................
36 namespace rptui
37 {
38 //........................................................................
39 
40 	//====================================================================
41 	//= ReportFormula
42 	//====================================================================
43     class REPORTDESIGN_DLLPUBLIC ReportFormula
44 	{
45     public:
46         enum BindType
47         {
48             Expression,
49             Field,
50 
51             Invalid
52         };
53 
54     private:
55         BindType            m_eType;
56         ::rtl::OUString     m_sCompleteFormula;
57         ::rtl::OUString     m_sUndecoratedContent;
58 
59     public:
60         /// constructs a ReportFormula object from a string
61         ReportFormula( const ::rtl::OUString& _rFormula );
62 
63         /// constructs a ReportFormula by BindType
64         ReportFormula( const BindType _eType, const ::rtl::OUString& _rFieldOrExpression );
65         ~ReportFormula();
66 
67         ReportFormula& operator=(class ReportFormula const &);
68 
69         /// returns whether the object denotes a valid formula
70         bool        isValid() const;
71 
72         /// returns the type of the binding represented by the formula
getType() const73         inline BindType    getType() const { return m_eType; }
74 
75         /// returns the complete formula represented by the object
76         const ::rtl::OUString&
77                     getCompleteFormula() const;
78 
79         /** gets the <em>undecorated formula</em> content
80 
81             If the formula denotes a field binding, the <em>undecorated content</em> is the
82             field name.
83 
84             If the formula denotes an expression, then the <em>undecorated content</em> is the expression
85             itself.
86         */
87         const ::rtl::OUString& getUndecoratedContent() const;// { return m_sUndecoratedContent; }
88 
89         /// convenience alias for <code>getUndecoratedContent</code>, which asserts (in a non-product build) when used on an expression
90         inline ::rtl::OUString  getFieldName() const;
91 
92         /**
93             @returns "=" + getFieldName()
94         */
95         ::rtl::OUString getEqualUndecoratedContent() const;
96 
97         /// convenience alias for <code>getUndecoratedContent</code>, which asserts (in a non-product build) when used on a field
98         inline ::rtl::OUString  getExpression() const;
99 
100         /** returns a bracketed field name of the formula denotes a field reference,
101             or the undecorated expression if the formula denotes an expression.
102 
103             Effectively, this means the method returns the complete formular, stripped by the prefix
104             which indicates a field or a expression.
105         */
106         ::rtl::OUString getBracketedFieldOrExpression() const;
107 
108     private:
109         void    impl_construct( const ::rtl::OUString& _rFormula );
110 	};
111 
112 	//--------------------------------------------------------------------
getFieldName() const113     inline ::rtl::OUString ReportFormula::getFieldName() const
114     {
115         OSL_PRECOND( getType() == Field, "ReportFormula::getFieldName: not bound to a field!" );
116         return getUndecoratedContent();
117     }
118 
119 	//--------------------------------------------------------------------
getExpression() const120     inline ::rtl::OUString ReportFormula::getExpression() const
121     {
122         OSL_PRECOND( getType() == Expression, "ReportFormula::getExpression: not bound to an expression!" );
123         return getUndecoratedContent();
124     }
125 
126 //........................................................................
127 } // namespace rptui
128 //........................................................................
129 
130 #endif // REPORTFORMULA_HXX
131