LibreOffice Module sc (master) 1
cellvalue.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 */
9
10#pragma once
11
12#include "global.hxx"
13#include <svl/sharedstring.hxx>
14#include <variant>
15
16class ScDocument;
17class ScFormulaCell;
18class EditTextObject;
19class ScColumn;
20struct ScRefCellValue;
21
22namespace sc {
23struct ColumnBlockPosition;
24}
25
32{
33private:
35 std::variant<std::monostate, double, svl::SharedString, EditTextObject*, ScFormulaCell*> maData;
36
37 void reset_to_empty();
38public:
39
41 ScCellValue( const ScRefCellValue& rCell );
42 ScCellValue( double fValue );
43 ScCellValue( const svl::SharedString& rString );
44 ScCellValue( std::unique_ptr<EditTextObject> );
45 ScCellValue( const ScCellValue& r );
46 ScCellValue(ScCellValue&& r) noexcept;
48
49 void clear() noexcept;
50
51 void set( double fValue );
52 void set( const svl::SharedString& rStr );
53 void set( const EditTextObject& rEditText );
54 void set( std::unique_ptr<EditTextObject> );
55 void set( ScFormulaCell* pFormula );
56
57 CellType getType() const;
58 double getDouble() const { return std::get<double>(maData); }
59 ScFormulaCell* getFormula() const { return std::get<ScFormulaCell*>(maData); }
60 const svl::SharedString* getSharedString() const { return &std::get<svl::SharedString>(maData); }
61 EditTextObject* getEditText() const { return std::get<EditTextObject*>(maData); }
62 EditTextObject* releaseEditText() { auto p = getEditText(); maData = static_cast<EditTextObject*>(nullptr); return p; }
63 ScFormulaCell* releaseFormula() { auto p = getFormula(); maData = static_cast<ScFormulaCell*>(nullptr); return p; }
64
68 void assign( const ScDocument& rDoc, const ScAddress& rPos );
69
70 void assign(const ScCellValue& rOther, ScDocument& rDestDoc, ScCloneFlags nCloneFlags = ScCloneFlags::Default);
71
75 void commit( ScDocument& rDoc, const ScAddress& rPos ) const;
76
77 void commit( ScColumn& rColumn, SCROW nRow ) const;
78
84 void release( ScDocument& rDoc, const ScAddress& rPos );
85
86 void release( ScColumn& rColumn, SCROW nRow, sc::StartListeningType eListenType = sc::SingleCellListening );
87
88 OUString getString( const ScDocument& rDoc ) const;
89
90 bool isEmpty() const;
91
92 bool equalsWithoutFormat( const ScCellValue& r ) const;
93
94 ScCellValue& operator= ( const ScCellValue& r );
95 ScCellValue& operator=(ScCellValue&& r) noexcept;
96 ScCellValue& operator= ( const ScRefCellValue& r );
97
98 void swap( ScCellValue& r );
99};
100
108{
109private:
111 union {
112 double mfValue;
116 };
117public:
118
120 ScRefCellValue( double fValue );
121 ScRefCellValue( const svl::SharedString* pString );
122 ScRefCellValue( const EditTextObject* pEditText );
123 ScRefCellValue( ScFormulaCell* pFormula );
124
128 ScRefCellValue( ScDocument& rDoc, const ScAddress& rPos );
129 ScRefCellValue( ScDocument& rDoc, const ScAddress& rPos, sc::ColumnBlockPosition& rBlockPos );
130
131 void clear();
132
133 CellType getType() const { return meType; }
134 double getDouble() const { assert(meType == CELLTYPE_VALUE); return mfValue; }
135 const svl::SharedString* getSharedString() const { assert(meType == CELLTYPE_STRING); return mpString; }
136 const EditTextObject* getEditText() const { assert(meType == CELLTYPE_EDIT); return mpEditText; }
138
142 void assign( ScDocument& rDoc, const ScAddress& rPos );
143 void assign( ScDocument& rDoc, const ScAddress& rPos, sc::ColumnBlockPosition& rBlockPos );
144
148 void commit( ScDocument& rDoc, const ScAddress& rPos ) const;
149
150 bool hasString() const;
151
152 bool hasNumeric() const;
153
154 bool hasError() const;
155
156 double getValue();
157
162 double getRawValue() const;
163
176 OUString getString( const ScDocument* pDoc ) const;
177
184 OUString getRawString( const ScDocument& rDoc ) const;
185
186 bool isEmpty() const;
187
188 bool hasEmptyValue();
189
190 bool equalsWithoutFormat( const ScRefCellValue& r ) const;
191};
192
193/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< ExpressionNode > mpFormula
CellType
Definition: global.hxx:270
@ CELLTYPE_EDIT
Definition: global.hxx:275
@ CELLTYPE_STRING
Definition: global.hxx:273
@ CELLTYPE_FORMULA
Definition: global.hxx:274
@ CELLTYPE_VALUE
Definition: global.hxx:272
ScCloneFlags
Definition: global.hxx:249
@ Default
Default cell clone flags: do not start listening, do not adjust 3D refs to old position,...
void * p
std::vector< sal_Int8, boost::noinit_adaptor< std::allocator< sal_Int8 > > > maData
OUString getString(const Any &_rAny)
def assign(rData, bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper, nUHyper, fFloat, fDouble, eEnum, rStr, xTest, rAny)
css::beans::Optional< css::uno::Any > getValue(std::u16string_view id)
void swap(cow_wrapper< T, P > &a, cow_wrapper< T, P > &b)
CAUTION! The following defines must be in the same namespace as the respective type.
StartListeningType
Definition: types.hxx:124
@ SingleCellListening
Definition: types.hxx:126
These need to be in global namespace just like their respective types are.
#define SC_DLLPUBLIC
Definition: scdllapi.h:27
Store arbitrary cell value of any kind.
Definition: cellvalue.hxx:32
ScFormulaCell * releaseFormula()
Definition: cellvalue.hxx:63
const svl::SharedString * getSharedString() const
Definition: cellvalue.hxx:60
std::variant< std::monostate, double, svl::SharedString, EditTextObject *, ScFormulaCell * > maData
std::monostate is there to indicate CellType::NONE
Definition: cellvalue.hxx:35
EditTextObject * releaseEditText()
Definition: cellvalue.hxx:62
ScFormulaCell * getFormula() const
Definition: cellvalue.hxx:59
EditTextObject * getEditText() const
Definition: cellvalue.hxx:61
This is very similar to ScCellValue, except that it references the original value instead of copying ...
Definition: cellvalue.hxx:108
ScFormulaCell * getFormula() const
Definition: cellvalue.hxx:137
CellType meType
Definition: cellvalue.hxx:110
const EditTextObject * getEditText() const
Definition: cellvalue.hxx:136
double getDouble() const
Definition: cellvalue.hxx:134
const EditTextObject * mpEditText
Definition: cellvalue.hxx:114
const svl::SharedString * mpString
Definition: cellvalue.hxx:113
ScFormulaCell * mpFormula
Definition: cellvalue.hxx:115
const svl::SharedString * getSharedString() const
Definition: cellvalue.hxx:135
CellType getType() const
Definition: cellvalue.hxx:133
Store position data for column array storage.
sal_Int32 SCROW
Definition: types.hxx:17
RedlineType meType