summaryrefslogtreecommitdiff
path: root/sc/inc/cellvalue.hxx
blob: 0e2987cfc04b968af6bfb77ed8b2a3af7a952201 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * 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/.
 */

#ifndef SC_CELLVALUE_HXX
#define SC_CELLVALUE_HXX

#include "global.hxx"
#include "mtvelements.hxx"

class ScDocument;
class ScFormulaCell;
class EditTextObject;
class ScColumn;
struct ScRefCellValue;

/**
 * Store arbitrary cell value of any kind.  It only stores cell value and
 * nothing else.  It creates a copy of the original cell value, and manages
 * the life cycle of the copied value.
 */
struct SC_DLLPUBLIC ScCellValue
{
    CellType meType;
    union {
        double mfValue;
        OUString* mpString;
        EditTextObject* mpEditText;
        ScFormulaCell* mpFormula;
    };

    ScCellValue();
    ScCellValue( const ScRefCellValue& rCell );
    ScCellValue( double fValue );
    ScCellValue( const OUString& rString );
    ScCellValue( const EditTextObject& rEditText );
    ScCellValue( const ScFormulaCell& rFormula );
    ScCellValue( const ScCellValue& r );
    ~ScCellValue();

    void clear();

    void set( double fValue );
    void set( const OUString& rStr );
    void set( const EditTextObject& rEditText );
    void set( const ScFormulaCell& rFormula );
    void set( ScFormulaCell* pFormula );

    /**
     * Take cell value from specified position in specified document.
     */
    void assign( const ScDocument& rDoc, const ScAddress& rPos );

    void assign( const ScCellValue& rOther, ScDocument& rDestDoc, int nCloneFlags = SC_CLONECELL_DEFAULT );

    /**
     * Set cell value at specified position in specified document.
     */
    void commit( ScDocument& rDoc, const ScAddress& rPos ) const;

    void commit( ScColumn& rColumn, SCROW nRow ) const;

    /**
     * Set cell value at specified position in specified document. But unlike
     * commit(), this method sets the original value to the document without
     * copying.  After this call, the value gets cleared.
     */
    void release( ScDocument& rDoc, const ScAddress& rPos );

    void release( ScColumn& rColumn, SCROW nRow );

    bool hasString() const;

    bool hasNumeric() const;

    bool isEmpty() const;

    bool equalsWithoutFormat( const ScCellValue& r ) const;

    ScCellValue& operator= ( const ScCellValue& r );
    ScCellValue& operator= ( const ScRefCellValue& r );

    void swap( ScCellValue& r );
};

/**
 * This is very similar to ScCellValue, except that it references the
 * original value instead of copying it.  As such, don't hold an instance of
 * this class any longer than necessary, and absolutely not after the
 * original cell has been destroyed.
 */
struct SC_DLLPUBLIC ScRefCellValue
{
    CellType meType;
    union {
        double mfValue;
        const OUString* mpString;
        const EditTextObject* mpEditText;
        ScFormulaCell* mpFormula;
    };

    ScRefCellValue();
    ScRefCellValue( double fValue );
    ScRefCellValue( const OUString* pString );
    ScRefCellValue( const EditTextObject* pEditText );
    ScRefCellValue( ScFormulaCell* pFormula );
    ScRefCellValue( const ScRefCellValue& r );
    ~ScRefCellValue();

    void clear();

    /**
     * Take cell value from specified position in specified document.
     */
    void assign( ScDocument& rDoc, const ScAddress& rPos );

    void assign( const sc::CellStoreType::const_iterator& itPos, size_t nOffset );

    /**
     * Set cell value at specified position in specified document.
     */
    void commit( ScDocument& rDoc, const ScAddress& rPos ) const;

    void commit( ScColumn& rColumn, SCROW nRow ) const;

    bool hasString() const;

    bool hasNumeric() const;

    double getValue();

    /** Retrieve string value.

        @param  pDoc
                Needed to resolve EditCells' field contents, obtain a
                ScFieldEditEngine from that document. May be NULL if there is
                no ScDocument in the calling context but then the document
                specific fields can not be resolved. See
                ScEditUtil::GetString().
     */
    OUString getString( const ScDocument* pDoc );

    bool isEmpty() const;

    bool hasEmptyValue();

    bool equalsWithoutFormat( const ScRefCellValue& r ) const;

    ScRefCellValue& operator= ( const ScRefCellValue& r );

    void swap( ScRefCellValue& r );
};

#endif

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