reportformula.hxx 3.96 KB
Newer Older
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */
19

20 21
#ifndef INCLUDED_REPORTDESIGN_INC_REPORTFORMULA_HXX
#define INCLUDED_REPORTDESIGN_INC_REPORTFORMULA_HXX
22 23 24 25

#include "dllapi.h"

#include <osl/diagnose.h>
26
#include <rtl/ustring.hxx>
27

28

29 30 31
namespace rptui
{

32

33
    //= ReportFormula
34

35 36 37 38 39 40 41 42 43 44 45 46 47
    class REPORTDESIGN_DLLPUBLIC ReportFormula
    {
    public:
        enum BindType
        {
            Expression,
            Field,

            Invalid
        };

    private:
        BindType            m_eType;
48 49
        OUString     m_sCompleteFormula;
        OUString     m_sUndecoratedContent;
50 51 52

    public:
        /// constructs a ReportFormula object from a string
53
        ReportFormula( const OUString& _rFormula );
54 55

        /// constructs a ReportFormula by BindType
56
        ReportFormula( const BindType _eType, const OUString& _rFieldOrExpression );
57 58
        ~ReportFormula();

59
        /// returns whether the object denotes a valid formula
60
        bool        isValid() const;
61 62

        /// returns the type of the binding represented by the formula
63
        BindType    getType() const { return m_eType; }
64 65

        /// returns the complete formula represented by the object
66
        const OUString&
67
                    getCompleteFormula() const { return m_sCompleteFormula; }
68 69 70 71 72 73 74 75 76

        /** gets the <em>undecorated formula</em> content

            If the formula denotes a field binding, the <em>undecorated content</em> is the
            field name.

            If the formula denotes an expression, then the <em>undecorated content</em> is the expression
            itself.
        */
77
        const OUString& getUndecoratedContent() const { return m_sUndecoratedContent; }
78 79

        /// convenience alias for <code>getUndecoratedContent</code>, which asserts (in a non-product build) when used on an expression
80
        inline OUString const & getFieldName() const;
81

82 83 84
        /**
            @returns "=" + getFieldName()
        */
85
        OUString getEqualUndecoratedContent() const;
86

87
        /// convenience alias for <code>getUndecoratedContent</code>, which asserts (in a non-product build) when used on a field
88
        inline OUString const & getExpression() const;
89 90 91 92

        /** returns a bracketed field name of the formula denotes a field reference,
            or the undecorated expression if the formula denotes an expression.

93
            Effectively, this means the method returns the complete formula, stripped by the prefix
94 95
            which indicates a field or a expression.
        */
96
        OUString getBracketedFieldOrExpression() const;
97 98

    private:
99
        void    impl_construct( const OUString& _rFormula );
100 101
    };

102

103
    inline OUString const & ReportFormula::getFieldName() const
104 105 106 107 108
    {
        OSL_PRECOND( getType() == Field, "ReportFormula::getFieldName: not bound to a field!" );
        return getUndecoratedContent();
    }

109

110
    inline OUString const & ReportFormula::getExpression() const
111 112 113 114 115
    {
        OSL_PRECOND( getType() == Expression, "ReportFormula::getExpression: not bound to an expression!" );
        return getUndecoratedContent();
    }

116

117
} // namespace rptui
118

119

120
#endif // INCLUDED_REPORTDESIGN_INC_REPORTFORMULA_HXX
121 122

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */