LibreOffice Module sc (master) 1
xerecord.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 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#pragma once
21
22#include "xlconst.hxx"
23#include "xestream.hxx"
24#include "xlstream.hxx"
26#include <rtl/ref.hxx>
27#include <algorithm>
28
29// Base classes to export Excel records =======================================
30
39{
40public:
42
43 // this class is stored both ref-counted and by value
49 { return *this; }
51 { return *this; }
52
53 virtual ~XclExpRecordBase();
54
56 virtual void Save( XclExpStream& rStrm );
57 virtual void SaveXml( XclExpXmlStream& rStrm );
58};
59
60/*namespace std
61{
62 template<typename T,
63 typename = typename std::enable_if<
64 std::is_base_of<XclExpRecordBase,T>::value
65 >::type>
66 class shared_ptr
67 {
68 shared_ptr() {}
69 };
70};*/
71
73{
74public:
76 virtual ~XclExpDelegatingRecord() override;
77
78 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
79private:
81};
82
84{
85public:
86 explicit XclExpXmlElementRecord(sal_Int32 nElement);
87 virtual ~XclExpXmlElementRecord() override;
88
89protected:
90 sal_Int32 mnElement;
91};
92
94{
95public:
96 explicit XclExpXmlStartElementRecord(sal_Int32 nElement);
97 virtual ~XclExpXmlStartElementRecord() override;
98
100 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
101};
102
104{
105public:
106 explicit XclExpXmlEndElementRecord(sal_Int32 nElement);
107 virtual ~XclExpXmlEndElementRecord() override;
108
110 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
111};
112
114{
115public:
116 explicit XclExpXmlStartSingleElementRecord(sal_Int32 nElement);
117 virtual ~XclExpXmlStartSingleElementRecord() override;
118
120 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
121};
122
124{
125public:
127 virtual ~XclExpXmlEndSingleElementRecord() override;
128
130 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
131};
132
143{
144public:
147 explicit XclExpRecord(
148 sal_uInt16 nRecId = EXC_ID_UNKNOWN,
149 std::size_t nRecSize = 0 );
150
151 XclExpRecord(XclExpRecord const &) = default;
152
153 virtual ~XclExpRecord() override;
154
156 sal_uInt16 GetRecId() const { return mnRecId; }
158 std::size_t GetRecSize() const { return mnRecSize; }
159
161 void SetRecId( sal_uInt16 nRecId ) { mnRecId = nRecId; }
163 void SetRecSize( std::size_t nRecSize ) { mnRecSize = nRecSize; }
165 void AddRecSize( std::size_t nRecSize ) { mnRecSize += nRecSize; }
167 void SetRecHeader( sal_uInt16 nRecId, std::size_t nRecSize );
168
170 virtual void Save( XclExpStream& rStrm ) override;
171
172protected:
175 virtual void WriteBody( XclExpStream& rStrm );
176
177private:
178 std::size_t mnRecSize;
179 sal_uInt16 mnRecId;
180};
181
184{
185public:
187 inline explicit XclExpEmptyRecord( sal_uInt16 nRecId );
188};
189
190inline XclExpEmptyRecord::XclExpEmptyRecord( sal_uInt16 nRecId ) :
191 XclExpRecord( nRecId, 0 )
192{
193}
194
197template< typename Type >
199{
200public:
204 explicit XclExpValueRecord( sal_uInt16 nRecId, const Type& rValue, std::size_t nSize = sizeof( Type ) ) :
205 XclExpRecord( nRecId, nSize ), maValue( rValue ), mnAttribute( -1 ) {}
206
208 const Type& GetValue() const { return maValue; }
210 void SetValue( const Type& rValue ) { maValue = rValue; }
211
213 XclExpValueRecord* SetAttribute( sal_Int32 nId );
214
216 void SaveXml( XclExpXmlStream& rStrm ) override;
217
218private:
220 virtual void WriteBody( XclExpStream& rStrm ) override { rStrm << maValue; }
221 // inlining prevents warning in wntmsci10
222
223private:
225 sal_Int32 mnAttribute;
226};
227
228template< typename Type >
230{
231 if( mnAttribute == -1 )
232 return;
233 rStrm.WriteAttributes(mnAttribute, OUString::number(maValue));
234}
235
236template<>
238
239template< typename Type >
241{
242 mnAttribute = nId;
243 return this;
244}
245
248
251
255{
256public:
259 explicit XclExpBoolRecord( sal_uInt16 nRecId, bool bValue, sal_Int32 nAttribute = -1 ) :
260 XclExpRecord( nRecId, 2 ), mbValue( bValue ), mnAttribute( nAttribute ) {}
261
263 bool GetBool() const { return mbValue; }
264
265 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
266
267private:
269 virtual void WriteBody( XclExpStream& rStrm ) override;
270
271private:
272 bool mbValue;
273 sal_Int32 mnAttribute;
274};
275
278{
279public:
283 explicit XclExpDummyRecord(
284 sal_uInt16 nRecId, const void* pRecData, std::size_t nRecSize );
285
287 void SetData( const void* pRecData, std::size_t nRecSize );
288
289private:
291 virtual void WriteBody( XclExpStream& rStrm ) override;
292
293private:
294 const void* mpData;
295};
296
297// Future records =============================================================
298
300{
301public:
302 explicit XclExpFutureRecord( XclFutureRecType eRecType,
303 sal_uInt16 nRecId, std::size_t nRecSize );
304
306 virtual void Save( XclExpStream& rStrm ) override;
307
308private:
310};
311
312// List of records ============================================================
313
320template< typename RecType = XclExpRecordBase >
322{
323public:
325
326 bool IsEmpty() const { return maRecs.empty(); }
327 size_t GetSize() const { return maRecs.size(); }
328
330 bool HasRecord( size_t nPos ) const
331 { return nPos < maRecs.size(); }
333 RecType* GetRecord( size_t nPos ) const
334 { return nPos < maRecs.size() ? maRecs[ nPos ].get() : nullptr; }
336 RecType* GetFirstRecord() const
337 { return maRecs.empty() ? nullptr : maRecs.front().get(); }
339 RecType* GetLastRecord() const
340 { return maRecs.empty() ? nullptr : maRecs.back().get(); }
341
343 void InsertRecord( RecType* pRec, size_t nPos )
344 { assert(pRec); maRecs.insert( maRecs.begin() + ::std::min( nPos, maRecs.size() ), pRec ); }
345 void InsertRecord( RecordRefType pRec, size_t nPos )
346 { assert(pRec); maRecs.insert( maRecs.begin() + ::std::min( nPos, maRecs.size() ), std::move(pRec) ); }
348 void AppendRecord( RecType* pRec )
349 { if (pRec) maRecs.push_back( pRec ); }
350 void AppendRecord( const RecordRefType& xRec )
351 { if (xRec) maRecs.push_back( xRec.get() ); }
353 { if (xRec) maRecs.push_back( std::move(xRec) ); }
355 void ReplaceRecord( RecType* pRec, size_t nPos )
356 { if (pRec) maRecs[nPos] = pRec; else RemoveRecord( nPos ); }
357 void ReplaceRecord( RecordRefType const & xRec, size_t nPos )
358 { ReplaceRecord(xRec.get(), nPos); }
359
361 void AppendNewRecord( RecType* pRec )
362 { assert(pRec); maRecs.push_back( pRec ); }
363 void AppendNewRecord( RecordRefType const & xRec )
364 { AppendNewRecord(xRec.get()); }
366 { assert(xRec); maRecs.append(std::move(xRec)); }
367
369 void RemoveRecord( size_t nPos )
370 { maRecs.erase( maRecs.begin() + nPos ); }
372 void RemoveAllRecords() { maRecs.clear(); }
373
375 virtual void Save( XclExpStream& rStrm ) override
376 {
377 // inlining prevents warning in wntmsci10
378 for( typename RecordVec::iterator aIt = maRecs.begin(), aEnd = maRecs.end(); aIt != aEnd; ++aIt )
379 (*aIt)->Save( rStrm );
380 }
381
382 virtual void SaveXml( XclExpXmlStream& rStrm ) override
383 {
384 // inlining prevents warning in wntmsci10
385 for( typename RecordVec::iterator aIt = maRecs.begin(), aEnd = maRecs.end(); aIt != aEnd; ++aIt )
386 (*aIt)->SaveXml( rStrm );
387 }
388
395 void InvalidateRecord( size_t nPos ) { maRecs[ nPos ] = nullptr; }
397 {
398 maRecs.erase(
399 std::remove_if( maRecs.begin(), maRecs.end(), [](const RecordRefType& xRec) { return xRec == nullptr; } ),
400 maRecs.end());
401 }
402
403private:
404 typedef ::std::vector< RecordRefType > RecordVec;
406};
407
410{
411public:
412 explicit XclExpSubStream( sal_uInt16 nSubStrmType );
413
415 virtual void Save( XclExpStream& rStrm ) override;
416
417private:
418 sal_uInt16 mnSubStrmType;
419};
420
421/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Record which contains a Boolean value.
Definition: xerecord.hxx:255
XclExpBoolRecord(sal_uInt16 nRecId, bool bValue, sal_Int32 nAttribute=-1)
Definition: xerecord.hxx:259
sal_Int32 mnAttribute
The record data.
Definition: xerecord.hxx:273
virtual void WriteBody(XclExpStream &rStrm) override
Writes the body of the record.
Definition: xerecord.cxx:166
bool GetBool() const
Returns the Boolean value of the record.
Definition: xerecord.hxx:263
virtual void SaveXml(XclExpXmlStream &rStrm) override
Definition: xerecord.cxx:171
XclExpRecordBase * mpRecord
Definition: xerecord.hxx:80
virtual ~XclExpDelegatingRecord() override
Definition: xerecord.cxx:49
XclExpDelegatingRecord(XclExpRecordBase *pRecord)
Definition: xerecord.cxx:44
virtual void SaveXml(XclExpXmlStream &rStrm) override
Definition: xerecord.cxx:55
Record which exports a memory data array.
Definition: xerecord.hxx:278
void SetData(const void *pRecData, std::size_t nRecSize)
Sets a data array.
Definition: xerecord.cxx:187
virtual void WriteBody(XclExpStream &rStrm) override
Writes the body of the record.
Definition: xerecord.cxx:193
XclExpDummyRecord(sal_uInt16 nRecId, const void *pRecData, std::size_t nRecSize)
Definition: xerecord.cxx:181
const void * mpData
Definition: xerecord.hxx:294
A record without body.
Definition: xerecord.hxx:184
XclExpEmptyRecord(sal_uInt16 nRecId)
Definition: xerecord.hxx:190
XclExpFutureRecord(XclFutureRecType eRecType, sal_uInt16 nRecId, std::size_t nRecSize)
Definition: xerecord.cxx:200
XclFutureRecType meRecType
Definition: xerecord.hxx:309
virtual void Save(XclExpStream &rStrm) override
Writes the extended record header and calls WriteBody().
Definition: xerecord.cxx:206
Base class for all Excel records.
Definition: xerecord.hxx:39
virtual void SaveXml(XclExpXmlStream &rStrm)
Definition: xerecord.cxx:40
XclExpRecordBase & operator=(XclExpRecordBase const &)
Definition: xerecord.hxx:48
XclExpRecordBase & operator=(XclExpRecordBase &&) noexcept
Definition: xerecord.hxx:50
virtual ~XclExpRecordBase()
Definition: xerecord.cxx:32
XclExpRecordBase(XclExpRecordBase &&)
Definition: xerecord.hxx:46
virtual void Save(XclExpStream &rStrm)
Overwrite this method to do any operation while saving the record.
Definition: xerecord.cxx:36
XclExpRecordBase(XclExpRecordBase const &)
Definition: xerecord.hxx:44
A list of Excel record objects.
Definition: xerecord.hxx:322
void AppendRecord(const RecordRefType &xRec)
Definition: xerecord.hxx:350
RecType * GetLastRecord() const
Returns reference to the last existing record or empty reference, if list is empty.
Definition: xerecord.hxx:339
void AppendRecord(RecordRefType xRec) &&
Definition: xerecord.hxx:352
void AppendNewRecord(RecordRefType xRec) &&
Definition: xerecord.hxx:365
RecType * GetFirstRecord() const
Returns reference to the first existing record or empty reference, if list is empty.
Definition: xerecord.hxx:336
void ReplaceRecord(RecordRefType const &xRec, size_t nPos)
Definition: xerecord.hxx:357
virtual void SaveXml(XclExpXmlStream &rStrm) override
Definition: xerecord.hxx:382
rtl::Reference< RecType > RecordRefType
Definition: xerecord.hxx:324
RecordVec maRecs
Definition: xerecord.hxx:405
void AppendNewRecord(RecType *pRec)
Appends a newly created record to the list.
Definition: xerecord.hxx:361
bool HasRecord(size_t nPos) const
Returns true, if the passed index points to an exiting record.
Definition: xerecord.hxx:330
::std::vector< RecordRefType > RecordVec
Definition: xerecord.hxx:404
size_t GetSize() const
Definition: xerecord.hxx:327
void RemoveRecord(size_t nPos)
Removes the record at the specified position from the list.
Definition: xerecord.hxx:369
bool IsEmpty() const
Definition: xerecord.hxx:326
void InvalidateRecord(size_t nPos)
Optimization for repeated removal.
Definition: xerecord.hxx:395
void InsertRecord(RecType *pRec, size_t nPos)
Inserts a record at the specified position into the list.
Definition: xerecord.hxx:343
void ReplaceRecord(RecType *pRec, size_t nPos)
Replaces the record at the specified position from the list with the passed record.
Definition: xerecord.hxx:355
void RemoveAllRecords()
Removes all records from the list.
Definition: xerecord.hxx:372
void AppendNewRecord(RecordRefType const &xRec)
Definition: xerecord.hxx:363
virtual void Save(XclExpStream &rStrm) override
Writes the complete record list.
Definition: xerecord.hxx:375
void InsertRecord(RecordRefType pRec, size_t nPos)
Definition: xerecord.hxx:345
void AppendRecord(RecType *pRec)
Appends a record to the list.
Definition: xerecord.hxx:348
void RemoveInvalidatedRecords()
Definition: xerecord.hxx:396
RecType * GetRecord(size_t nPos) const
Returns reference to an existing record or empty reference on error.
Definition: xerecord.hxx:333
Base class for single records with any content.
Definition: xerecord.hxx:143
virtual void Save(XclExpStream &rStrm) override
Writes the record header and calls WriteBody().
Definition: xerecord.cxx:150
XclExpRecord(sal_uInt16 nRecId=EXC_ID_UNKNOWN, std::size_t nRecSize=0)
Definition: xerecord.cxx:130
sal_uInt16 GetRecId() const
Returns the current record ID.
Definition: xerecord.hxx:156
sal_uInt16 mnRecId
The predicted record size.
Definition: xerecord.hxx:179
void SetRecHeader(sal_uInt16 nRecId, std::size_t nRecSize)
Sets record ID and size with one call.
Definition: xerecord.cxx:140
virtual void WriteBody(XclExpStream &rStrm)
Writes the body of the record (without record header).
Definition: xerecord.cxx:146
void AddRecSize(std::size_t nRecSize)
Adds a size value to the record size prediction.
Definition: xerecord.hxx:165
void SetRecSize(std::size_t nRecSize)
Sets a new record size prediction.
Definition: xerecord.hxx:163
void SetRecId(sal_uInt16 nRecId)
Sets a new record ID.
Definition: xerecord.hxx:161
XclExpRecord(XclExpRecord const &)=default
virtual ~XclExpRecord() override
Definition: xerecord.cxx:136
std::size_t GetRecSize() const
Returns the current record size prediction.
Definition: xerecord.hxx:158
std::size_t mnRecSize
Definition: xerecord.hxx:178
This class is used to export Excel record streams.
Definition: xestream.hxx:73
Represents a complete substream of records enclosed into a pair of BOF/EOF records.
Definition: xerecord.hxx:410
sal_uInt16 mnSubStrmType
Definition: xerecord.hxx:418
XclExpSubStream(sal_uInt16 nSubStrmType)
Definition: xerecord.cxx:216
virtual void Save(XclExpStream &rStrm) override
Writes the complete substream, including leading BOF and trailing EOF.
Definition: xerecord.cxx:221
A record with a single value of type Type.
Definition: xerecord.hxx:199
const Type & GetValue() const
Returns the value of the record.
Definition: xerecord.hxx:208
sal_Int32 mnAttribute
The record data.
Definition: xerecord.hxx:225
XclExpValueRecord * SetAttribute(sal_Int32 nId)
Sets the OOXML attribute this record corresponds to.
Definition: xerecord.hxx:240
virtual void WriteBody(XclExpStream &rStrm) override
Writes the body of the record.
Definition: xerecord.hxx:220
XclExpValueRecord(sal_uInt16 nRecId, const Type &rValue, std::size_t nSize=sizeof(Type))
Definition: xerecord.hxx:204
void SetValue(const Type &rValue)
Sets a new record value.
Definition: xerecord.hxx:210
void SaveXml(XclExpXmlStream &rStrm) override
Write the OOXML attribute and its value.
Definition: xerecord.hxx:229
virtual ~XclExpXmlElementRecord() override
Definition: xerecord.cxx:66
XclExpXmlElementRecord(sal_Int32 nElement)
Definition: xerecord.cxx:61
XclExpXmlEndElementRecord(sal_Int32 nElement)
Definition: xerecord.cxx:87
virtual ~XclExpXmlEndElementRecord() override
Definition: xerecord.cxx:92
virtual void SaveXml(XclExpXmlStream &rStrm) override
Ends the element nElement.
Definition: xerecord.cxx:96
virtual ~XclExpXmlEndSingleElementRecord() override
Definition: xerecord.cxx:121
virtual void SaveXml(XclExpXmlStream &rStrm) override
Ends the single element nElement.
Definition: xerecord.cxx:125
virtual void SaveXml(XclExpXmlStream &rStrm) override
Starts the element nElement.
Definition: xerecord.cxx:79
XclExpXmlStartElementRecord(sal_Int32 nElement)
Definition: xerecord.cxx:70
virtual ~XclExpXmlStartElementRecord() override
Definition: xerecord.cxx:75
XclExpXmlStartSingleElementRecord(sal_Int32 nElement)
Definition: xerecord.cxx:101
virtual void SaveXml(XclExpXmlStream &rStrm) override
Starts the single element nElement.
Definition: xerecord.cxx:111
virtual ~XclExpXmlStartSingleElementRecord() override
Definition: xerecord.cxx:107
double maValue
sal_uInt16 nPos
Type
void SvStream & rStrm
sal_Int16 nId
XclExpValueRecord< double > XclExpDoubleRecord
A record containing a double value.
Definition: xerecord.hxx:250
XclExpValueRecord< sal_uInt16 > XclExpUInt16Record
A record containing an unsigned 16-bit value.
Definition: xerecord.hxx:247
XclFutureRecType
Enumerates different header types of future records.
Definition: xlconst.hxx:237
const sal_uInt16 EXC_ID_UNKNOWN
Definition: xlstream.hxx:35