1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
13 #include <svl/sharedstring.hxx>
20 struct ScRefCellValue
;
23 struct ColumnBlockPosition
;
27 * Store arbitrary cell value of any kind. It only stores cell value and
28 * nothing else. It creates a copy of the original cell value, and manages
29 * the life cycle of the copied value.
34 /// std::monostate is there to indicate CellType::NONE
35 std::variant
<std::monostate
, double, svl::SharedString
, EditTextObject
*, ScFormulaCell
*> maData
;
37 void reset_to_empty();
40 SC_DLLPUBLIC
ScCellValue();
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
;
47 SC_DLLPUBLIC
~ScCellValue();
49 SC_DLLPUBLIC
void clear() noexcept
;
51 SC_DLLPUBLIC
void set( double fValue
);
52 SC_DLLPUBLIC
void set( const svl::SharedString
& rStr
);
53 void set( const EditTextObject
& rEditText
);
54 SC_DLLPUBLIC
void set( std::unique_ptr
<EditTextObject
> );
55 SC_DLLPUBLIC
void set( ScFormulaCell
* pFormula
);
57 SC_DLLPUBLIC 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
; }
66 * Take cell value from specified position in specified document.
68 void assign( const ScDocument
& rDoc
, const ScAddress
& rPos
);
70 void assign(const ScCellValue
& rOther
, ScDocument
& rDestDoc
, ScCloneFlags nCloneFlags
= ScCloneFlags::Default
);
73 * Set cell value at specified position in specified document.
75 void commit( ScDocument
& rDoc
, const ScAddress
& rPos
) const;
77 void commit( ScColumn
& rColumn
, SCROW nRow
) const;
80 * Set cell value at specified position in specified document. But unlike
81 * commit(), this method sets the original value to the document without
82 * copying. After this call, the value gets cleared.
84 void release( ScDocument
& rDoc
, const ScAddress
& rPos
);
86 void release( ScColumn
& rColumn
, SCROW nRow
, sc::StartListeningType eListenType
= sc::SingleCellListening
);
88 OUString
getString( const ScDocument
& rDoc
) const;
90 SC_DLLPUBLIC
bool isEmpty() const;
92 bool equalsWithoutFormat( const ScCellValue
& r
) const;
94 ScCellValue
& operator= ( const ScCellValue
& r
);
95 ScCellValue
& operator=(ScCellValue
&& r
) noexcept
;
96 ScCellValue
& operator= ( const ScRefCellValue
& r
);
98 void swap( ScCellValue
& r
);
102 * This is very similar to ScCellValue, except that it references the
103 * original value instead of copying it. As such, don't hold an instance of
104 * this class any longer than necessary, and absolutely not after the
105 * original cell has been destroyed.
107 struct SAL_DLLPUBLIC_RTTI ScRefCellValue
113 const svl::SharedString
* mpString
;
114 const EditTextObject
* mpEditText
;
115 ScFormulaCell
* mpFormula
;
119 SC_DLLPUBLIC
ScRefCellValue();
120 SC_DLLPUBLIC
ScRefCellValue( double fValue
);
121 ScRefCellValue( const svl::SharedString
* pString
);
122 ScRefCellValue( const EditTextObject
* pEditText
);
123 ScRefCellValue( ScFormulaCell
* pFormula
);
126 * Take cell value from specified position in specified document.
128 SC_DLLPUBLIC
ScRefCellValue( ScDocument
& rDoc
, const ScAddress
& rPos
);
129 SC_DLLPUBLIC
ScRefCellValue( ScDocument
& rDoc
, const ScAddress
& rPos
, sc::ColumnBlockPosition
& rBlockPos
);
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
; }
137 ScFormulaCell
* getFormula() const { assert(meType
== CELLTYPE_FORMULA
); return mpFormula
; }
140 * Take cell value from specified position in specified document.
142 SC_DLLPUBLIC
void assign( ScDocument
& rDoc
, const ScAddress
& rPos
);
143 void assign( ScDocument
& rDoc
, const ScAddress
& rPos
, sc::ColumnBlockPosition
& rBlockPos
);
146 * Set cell value at specified position in specified document.
148 void commit( ScDocument
& rDoc
, const ScAddress
& rPos
) const;
150 bool hasString() const;
152 SC_DLLPUBLIC
bool hasNumeric() const;
154 bool hasError() const;
159 * Retrieve a numeric value without modifying the states of any objects in
160 * the referenced document store.
162 double getRawValue() const;
165 * Retrieve string value.
167 * Note that this method is NOT thread-safe.
170 * Needed to resolve EditCells' field contents, obtain a
171 * ScFieldEditEngine from that document. May be NULL if there is
172 * no ScDocument in the calling context but then the document
173 * specific fields can not be resolved. See
174 * ScEditUtil::GetString().
176 SC_DLLPUBLIC OUString
getString( const ScDocument
* pDoc
) const;
179 * Retrieve a string value without modifying the states of any objects in
180 * the referenced document store.
182 * This method is thread-safe.
184 OUString
getRawString( const ScDocument
& rDoc
) const;
186 SC_DLLPUBLIC
bool isEmpty() const;
188 bool hasEmptyValue();
190 bool equalsWithoutFormat( const ScRefCellValue
& r
) const;
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */