Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / reportdesign / inc / reportformula.hxx
blob972f8dbe4daa6459f7472a2f76a024d7535dac9c
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 .
20 #ifndef INCLUDED_REPORTDESIGN_INC_REPORTFORMULA_HXX
21 #define INCLUDED_REPORTDESIGN_INC_REPORTFORMULA_HXX
23 #include "dllapi.h"
25 #include <osl/diagnose.h>
26 #include <rtl/ustring.hxx>
29 namespace rptui
33 //= ReportFormula
35 class REPORTDESIGN_DLLPUBLIC ReportFormula
37 public:
38 enum BindType
40 Expression,
41 Field,
43 Invalid
46 private:
47 BindType m_eType;
48 OUString m_sCompleteFormula;
49 OUString m_sUndecoratedContent;
51 public:
52 /// constructs a ReportFormula object from a string
53 ReportFormula( const OUString& _rFormula );
55 /// constructs a ReportFormula by BindType
56 ReportFormula( const BindType _eType, const OUString& _rFieldOrExpression );
57 ~ReportFormula();
59 /// returns whether the object denotes a valid formula
60 bool isValid() const;
62 /// returns the type of the binding represented by the formula
63 BindType getType() const { return m_eType; }
65 /// returns the complete formula represented by the object
66 const OUString&
67 getCompleteFormula() const { return m_sCompleteFormula; }
69 /** gets the <em>undecorated formula</em> content
71 If the formula denotes a field binding, the <em>undecorated content</em> is the
72 field name.
74 If the formula denotes an expression, then the <em>undecorated content</em> is the expression
75 itself.
77 const OUString& getUndecoratedContent() const { return m_sUndecoratedContent; }
79 /// convenience alias for <code>getUndecoratedContent</code>, which asserts (in a non-product build) when used on an expression
80 inline OUString getFieldName() const;
82 /**
83 @returns "=" + getFieldName()
85 OUString getEqualUndecoratedContent() const;
87 /// convenience alias for <code>getUndecoratedContent</code>, which asserts (in a non-product build) when used on a field
88 inline OUString getExpression() const;
90 /** returns a bracketed field name of the formula denotes a field reference,
91 or the undecorated expression if the formula denotes an expression.
93 Effectively, this means the method returns the complete formular, stripped by the prefix
94 which indicates a field or a expression.
96 OUString getBracketedFieldOrExpression() const;
98 private:
99 void impl_construct( const OUString& _rFormula );
103 inline OUString ReportFormula::getFieldName() const
105 OSL_PRECOND( getType() == Field, "ReportFormula::getFieldName: not bound to a field!" );
106 return getUndecoratedContent();
110 inline OUString ReportFormula::getExpression() const
112 OSL_PRECOND( getType() == Expression, "ReportFormula::getExpression: not bound to an expression!" );
113 return getUndecoratedContent();
117 } // namespace rptui
120 #endif // INCLUDED_REPORTDESIGN_INC_REPORTFORMULA_HXX
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */