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 
28 // Base classes to export Excel records =======================================
29 
38 {
39 public:
41 
42  // this class is stored both ref-counted and by value
48  { return *this; }
50  { return *this; }
51 
52  virtual ~XclExpRecordBase();
53 
55  virtual void Save( XclExpStream& rStrm );
56  virtual void SaveXml( XclExpXmlStream& rStrm );
57 };
58 
59 /*namespace std
60 {
61  template<typename T,
62  typename = typename std::enable_if<
63  std::is_base_of<XclExpRecordBase,T>::value
64  >::type>
65  class shared_ptr
66  {
67  shared_ptr() {}
68  };
69 };*/
70 
72 {
73 public:
75  virtual ~XclExpDelegatingRecord() override;
76 
77  virtual void SaveXml( XclExpXmlStream& rStrm ) override;
78 private:
80 };
81 
83 {
84 public:
85  explicit XclExpXmlElementRecord(sal_Int32 nElement);
86  virtual ~XclExpXmlElementRecord() override;
87 
88 protected:
89  sal_Int32 mnElement;
90 };
91 
93 {
94 public:
95  explicit XclExpXmlStartElementRecord(sal_Int32 nElement);
96  virtual ~XclExpXmlStartElementRecord() override;
97 
99  virtual void SaveXml( XclExpXmlStream& rStrm ) override;
100 };
101 
103 {
104 public:
105  explicit XclExpXmlEndElementRecord(sal_Int32 nElement);
106  virtual ~XclExpXmlEndElementRecord() override;
107 
109  virtual void SaveXml( XclExpXmlStream& rStrm ) override;
110 };
111 
113 {
114 public:
115  explicit XclExpXmlStartSingleElementRecord(sal_Int32 nElement);
116  virtual ~XclExpXmlStartSingleElementRecord() override;
117 
119  virtual void SaveXml( XclExpXmlStream& rStrm ) override;
120 };
121 
123 {
124 public:
126  virtual ~XclExpXmlEndSingleElementRecord() override;
127 
129  virtual void SaveXml( XclExpXmlStream& rStrm ) override;
130 };
131 
142 {
143 public:
146  explicit XclExpRecord(
147  sal_uInt16 nRecId = EXC_ID_UNKNOWN,
148  std::size_t nRecSize = 0 );
149 
150  XclExpRecord(XclExpRecord const &) = default;
151 
152  virtual ~XclExpRecord() override;
153 
155  sal_uInt16 GetRecId() const { return mnRecId; }
157  std::size_t GetRecSize() const { return mnRecSize; }
158 
160  void SetRecId( sal_uInt16 nRecId ) { mnRecId = nRecId; }
162  void SetRecSize( std::size_t nRecSize ) { mnRecSize = nRecSize; }
164  void AddRecSize( std::size_t nRecSize ) { mnRecSize += nRecSize; }
166  void SetRecHeader( sal_uInt16 nRecId, std::size_t nRecSize );
167 
169  virtual void Save( XclExpStream& rStrm ) override;
170 
171 protected:
174  virtual void WriteBody( XclExpStream& rStrm );
175 
176 private:
177  std::size_t mnRecSize;
178  sal_uInt16 mnRecId;
179 };
180 
183 {
184 public:
186  inline explicit XclExpEmptyRecord( sal_uInt16 nRecId );
187 };
188 
189 inline XclExpEmptyRecord::XclExpEmptyRecord( sal_uInt16 nRecId ) :
190  XclExpRecord( nRecId, 0 )
191 {
192 }
193 
196 template< typename Type >
198 {
199 public:
203  explicit XclExpValueRecord( sal_uInt16 nRecId, const Type& rValue, std::size_t nSize = sizeof( Type ) ) :
204  XclExpRecord( nRecId, nSize ), maValue( rValue ), mnAttribute( -1 ) {}
205 
207  const Type& GetValue() const { return maValue; }
209  void SetValue( const Type& rValue ) { maValue = rValue; }
210 
212  XclExpValueRecord* SetAttribute( sal_Int32 nId );
213 
215  void SaveXml( XclExpXmlStream& rStrm ) override;
216 
217 private:
219  virtual void WriteBody( XclExpStream& rStrm ) override { rStrm << maValue; }
220  // inlining prevents warning in wntmsci10
221 
222 private:
224  sal_Int32 mnAttribute;
225 };
226 
227 template< typename Type >
229 {
230  if( mnAttribute == -1 )
231  return;
232  rStrm.WriteAttributes(mnAttribute, OUString::number(maValue));
233 }
234 
235 template<>
237 
238 template< typename Type >
240 {
241  mnAttribute = nId;
242  return this;
243 }
244 
247 
250 
254 {
255 public:
258  explicit XclExpBoolRecord( sal_uInt16 nRecId, bool bValue, sal_Int32 nAttribute = -1 ) :
259  XclExpRecord( nRecId, 2 ), mbValue( bValue ), mnAttribute( nAttribute ) {}
260 
262  bool GetBool() const { return mbValue; }
263 
264  virtual void SaveXml( XclExpXmlStream& rStrm ) override;
265 
266 private:
268  virtual void WriteBody( XclExpStream& rStrm ) override;
269 
270 private:
271  bool mbValue;
272  sal_Int32 mnAttribute;
273 };
274 
277 {
278 public:
282  explicit XclExpDummyRecord(
283  sal_uInt16 nRecId, const void* pRecData, std::size_t nRecSize );
284 
286  void SetData( const void* pRecData, std::size_t nRecSize );
287 
288 private:
290  virtual void WriteBody( XclExpStream& rStrm ) override;
291 
292 private:
293  const void* mpData;
294 };
295 
296 // Future records =============================================================
297 
299 {
300 public:
301  explicit XclExpFutureRecord( XclFutureRecType eRecType,
302  sal_uInt16 nRecId, std::size_t nRecSize );
303 
305  virtual void Save( XclExpStream& rStrm ) override;
306 
307 private:
309 };
310 
311 // List of records ============================================================
312 
319 template< typename RecType = XclExpRecordBase >
321 {
322 public:
324 
325  bool IsEmpty() const { return maRecs.empty(); }
326  size_t GetSize() const { return maRecs.size(); }
327 
329  bool HasRecord( size_t nPos ) const
330  { return nPos < maRecs.size(); }
332  RecType* GetRecord( size_t nPos ) const
333  { return nPos < maRecs.size() ? maRecs[ nPos ].get() : nullptr; }
335  RecType* GetFirstRecord() const
336  { return maRecs.empty() ? nullptr : maRecs.front().get(); }
338  RecType* GetLastRecord() const
339  { return maRecs.empty() ? nullptr : maRecs.back().get(); }
340 
342  void InsertRecord( RecType* pRec, size_t nPos )
343  { assert(pRec); maRecs.insert( maRecs.begin() + ::std::min( nPos, maRecs.size() ), pRec ); }
344  void InsertRecord( RecordRefType pRec, size_t nPos )
345  { assert(pRec); maRecs.insert( maRecs.begin() + ::std::min( nPos, maRecs.size() ), std::move(pRec) ); }
347  void AppendRecord( RecType* pRec )
348  { if (pRec) maRecs.push_back( pRec ); }
349  void AppendRecord( const RecordRefType& xRec )
350  { if (xRec) maRecs.push_back( xRec.get() ); }
351  void AppendRecord( RecordRefType xRec ) &&
352  { if (xRec) maRecs.push_back( std::move(xRec) ); }
354  void ReplaceRecord( RecType* pRec, size_t nPos )
355  { if (pRec) maRecs[nPos] = pRec; else RemoveRecord( nPos ); }
356  void ReplaceRecord( RecordRefType const & xRec, size_t nPos )
357  { ReplaceRecord(xRec.get(), nPos); }
358 
360  void AppendNewRecord( RecType* pRec )
361  { assert(pRec); maRecs.push_back( pRec ); }
362  void AppendNewRecord( RecordRefType const & xRec )
363  { AppendNewRecord(xRec.get()); }
364  void AppendNewRecord( RecordRefType xRec ) &&
365  { assert(xRec); maRecs.append(std::move(xRec)); }
366 
368  void RemoveRecord( size_t nPos )
369  { maRecs.erase( maRecs.begin() + nPos ); }
371  void RemoveAllRecords() { maRecs.clear(); }
372 
374  virtual void Save( XclExpStream& rStrm ) override
375  {
376  // inlining prevents warning in wntmsci10
377  for( typename RecordVec::iterator aIt = maRecs.begin(), aEnd = maRecs.end(); aIt != aEnd; ++aIt )
378  (*aIt)->Save( rStrm );
379  }
380 
381  virtual void SaveXml( XclExpXmlStream& rStrm ) override
382  {
383  // inlining prevents warning in wntmsci10
384  for( typename RecordVec::iterator aIt = maRecs.begin(), aEnd = maRecs.end(); aIt != aEnd; ++aIt )
385  (*aIt)->SaveXml( rStrm );
386  }
387 
388 private:
389  typedef ::std::vector< RecordRefType > RecordVec;
390  RecordVec maRecs;
391 };
392 
395 {
396 public:
397  explicit XclExpSubStream( sal_uInt16 nSubStrmType );
398 
400  virtual void Save( XclExpStream& rStrm ) override;
401 
402 private:
403  sal_uInt16 mnSubStrmType;
404 };
405 
406 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetValue(const Type &rValue)
Sets a new record value.
Definition: xerecord.hxx:209
XclExpDummyRecord(sal_uInt16 nRecId, const void *pRecData, std::size_t nRecSize)
Definition: xerecord.cxx:181
void WriteAttributes(sal_Int32 nAttribute, Str &&value, Args &&...rest)
Definition: xestream.hxx:300
rtl::Reference< RecType > RecordRefType
Definition: xerecord.hxx:323
virtual void Save(XclExpStream &rStrm) override
Writes the complete substream, including leading BOF and trailing EOF.
Definition: xerecord.cxx:221
Type
virtual void Save(XclExpStream &rStrm) override
Writes the complete record list.
Definition: xerecord.hxx:374
virtual ~XclExpXmlElementRecord() override
Definition: xerecord.cxx:66
void ReplaceRecord(RecordRefType const &xRec, size_t nPos)
Definition: xerecord.hxx:356
A list of Excel record objects.
Definition: xerecord.hxx:320
XclExpXmlStartElementRecord(sal_Int32 nElement)
Definition: xerecord.cxx:70
sal_Int32 mnAttribute
The record data.
Definition: xerecord.hxx:272
Represents a complete substream of records enclosed into a pair of BOF/EOF records.
Definition: xerecord.hxx:394
This class is used to export Excel record streams.
Definition: xestream.hxx:72
virtual void WriteBody(XclExpStream &rStrm) override
Writes the body of the record.
Definition: xerecord.hxx:219
virtual void SaveXml(XclExpXmlStream &rStrm) override
Definition: xerecord.hxx:381
RecordVec maRecs
Definition: xerecord.hxx:390
void SetData(const void *pRecData, std::size_t nRecSize)
Sets a data array.
Definition: xerecord.cxx:187
XclExpValueRecord< double > XclExpDoubleRecord
A record containing a double value.
Definition: xerecord.hxx:249
void AppendRecord(RecType *pRec)
Appends a record to the list.
Definition: xerecord.hxx:347
XclExpFutureRecord(XclFutureRecType eRecType, sal_uInt16 nRecId, std::size_t nRecSize)
Definition: xerecord.cxx:200
const Type & GetValue() const
Returns the value of the record.
Definition: xerecord.hxx:207
void SetRecSize(std::size_t nRecSize)
Sets a new record size prediction.
Definition: xerecord.hxx:162
virtual ~XclExpXmlEndSingleElementRecord() override
Definition: xerecord.cxx:121
std::size_t GetRecSize() const
Returns the current record size prediction.
Definition: xerecord.hxx:157
virtual void WriteBody(XclExpStream &rStrm) override
Writes the body of the record.
Definition: xerecord.cxx:166
void ReplaceRecord(RecType *pRec, size_t nPos)
Replaces the record at the specified position from the list with the passed record.
Definition: xerecord.hxx:354
XclFutureRecType
Enumerates different header types of future records.
Definition: xlconst.hxx:236
sal_uInt16 GetRecId() const
Returns the current record ID.
Definition: xerecord.hxx:155
XclExpRecordBase & operator=(XclExpRecordBase &&) noexcept
Definition: xerecord.hxx:49
RecType * GetLastRecord() const
Returns reference to the last existing record or empty reference, if list is empty.
Definition: xerecord.hxx:338
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
Record which exports a memory data array.
Definition: xerecord.hxx:276
XclExpSubStream(sal_uInt16 nSubStrmType)
Definition: xerecord.cxx:216
XclExpRecordBase & operator=(XclExpRecordBase const &)
Definition: xerecord.hxx:47
Base class for all Excel records.
Definition: xerecord.hxx:37
bool HasRecord(size_t nPos) const
Returns true, if the passed index points to an exiting record.
Definition: xerecord.hxx:329
virtual void Save(XclExpStream &rStrm)
Overwrite this method to do any operation while saving the record.
Definition: xerecord.cxx:36
XclExpValueRecord(sal_uInt16 nRecId, const Type &rValue, std::size_t nSize=sizeof(Type))
Definition: xerecord.hxx:203
XclExpRecordBase(XclExpRecordBase &&)
Definition: xerecord.hxx:45
void AppendRecord(RecordRefType xRec)&&
Definition: xerecord.hxx:351
A record with a single value of type Type.
Definition: xerecord.hxx:197
void AppendNewRecord(RecordRefType xRec)&&
Definition: xerecord.hxx:364
void RemoveRecord(size_t nPos)
Removes the record at the specified position from the list.
Definition: xerecord.hxx:368
XclExpXmlElementRecord(sal_Int32 nElement)
Definition: xerecord.cxx:61
const sal_uInt16 EXC_ID_UNKNOWN
Definition: xlstream.hxx:35
void AppendNewRecord(RecordRefType const &xRec)
Definition: xerecord.hxx:362
void InsertRecord(RecType *pRec, size_t nPos)
Inserts a record at the specified position into the list.
Definition: xerecord.hxx:342
virtual void SaveXml(XclExpXmlStream &rStrm) override
Ends the element nElement.
Definition: xerecord.cxx:96
void InsertRecord(RecordRefType pRec, size_t nPos)
Definition: xerecord.hxx:344
XclExpRecordBase * mpRecord
Definition: xerecord.hxx:79
void AppendRecord(const RecordRefType &xRec)
Definition: xerecord.hxx:349
virtual ~XclExpRecordBase()
Definition: xerecord.cxx:32
RecType * GetFirstRecord() const
Returns reference to the first existing record or empty reference, if list is empty.
Definition: xerecord.hxx:335
virtual void SaveXml(XclExpXmlStream &rStrm) override
Definition: xerecord.cxx:171
sal_uInt16 mnRecId
The predicted record size.
Definition: xerecord.hxx:178
virtual ~XclExpXmlStartSingleElementRecord() override
Definition: xerecord.cxx:107
void AppendNewRecord(RecType *pRec)
Appends a newly created record to the list.
Definition: xerecord.hxx:360
bool GetBool() const
Returns the Boolean value of the record.
Definition: xerecord.hxx:262
XclFutureRecType meRecType
Definition: xerecord.hxx:308
XclExpValueRecord< sal_uInt16 > XclExpUInt16Record
A record containing an unsigned 16-bit value.
Definition: xerecord.hxx:246
virtual void SaveXml(XclExpXmlStream &rStrm) override
Ends the single element nElement.
Definition: xerecord.cxx:125
virtual void WriteBody(XclExpStream &rStrm)
Writes the body of the record (without record header).
Definition: xerecord.cxx:146
RecType * GetRecord(size_t nPos) const
Returns reference to an existing record or empty reference on error.
Definition: xerecord.hxx:332
XclExpRecordBase(XclExpRecordBase const &)
Definition: xerecord.hxx:43
void SetRecHeader(sal_uInt16 nRecId, std::size_t nRecSize)
Sets record ID and size with one call.
Definition: xerecord.cxx:140
XclExpRecord(sal_uInt16 nRecId=EXC_ID_UNKNOWN, std::size_t nRecSize=0)
Definition: xerecord.cxx:130
XclExpDelegatingRecord(XclExpRecordBase *pRecord)
Definition: xerecord.cxx:44
A record without body.
Definition: xerecord.hxx:182
void SaveXml(XclExpXmlStream &rStrm) override
Write the OOXML attribute and its value.
Definition: xerecord.hxx:228
void RemoveAllRecords()
Removes all records from the list.
Definition: xerecord.hxx:371
sal_uInt16 mnSubStrmType
Definition: xerecord.hxx:403
XclExpEmptyRecord(sal_uInt16 nRecId)
Definition: xerecord.hxx:189
std::size_t mnRecSize
Definition: xerecord.hxx:177
size_t GetSize() const
Definition: xerecord.hxx:326
virtual ~XclExpXmlEndElementRecord() override
Definition: xerecord.cxx:92
const void * mpData
Definition: xerecord.hxx:293
XclExpValueRecord * SetAttribute(sal_Int32 nId)
Sets the OOXML attribute this record corresponds to.
Definition: xerecord.hxx:239
virtual void Save(XclExpStream &rStrm) override
Writes the extended record header and calls WriteBody().
Definition: xerecord.cxx:206
virtual ~XclExpXmlStartElementRecord() override
Definition: xerecord.cxx:75
virtual ~XclExpDelegatingRecord() override
Definition: xerecord.cxx:49
sal_Int32 mnAttribute
The record data.
Definition: xerecord.hxx:224
XclExpXmlEndElementRecord(sal_Int32 nElement)
Definition: xerecord.cxx:87
virtual void WriteBody(XclExpStream &rStrm) override
Writes the body of the record.
Definition: xerecord.cxx:193
bool IsEmpty() const
Definition: xerecord.hxx:325
virtual void SaveXml(XclExpXmlStream &rStrm) override
Definition: xerecord.cxx:55
virtual void Save(XclExpStream &rStrm) override
Writes the record header and calls WriteBody().
Definition: xerecord.cxx:150
void SvStream & rStrm
XclExpXmlStartSingleElementRecord(sal_Int32 nElement)
Definition: xerecord.cxx:101
void SetRecId(sal_uInt16 nRecId)
Sets a new record ID.
Definition: xerecord.hxx:160
virtual void SaveXml(XclExpXmlStream &rStrm) override
Starts the single element nElement.
Definition: xerecord.cxx:111
virtual void SaveXml(XclExpXmlStream &rStrm)
Definition: xerecord.cxx:40
double maValue
Base class for single records with any content.
Definition: xerecord.hxx:141
Record which contains a Boolean value.
Definition: xerecord.hxx:253
::std::vector< RecordRefType > RecordVec
Definition: xerecord.hxx:389
virtual void SaveXml(XclExpXmlStream &rStrm) override
Starts the element nElement.
Definition: xerecord.cxx:79
XclExpBoolRecord(sal_uInt16 nRecId, bool bValue, sal_Int32 nAttribute=-1)
Definition: xerecord.hxx:258
virtual ~XclExpRecord() override
Definition: xerecord.cxx:136
void AddRecSize(std::size_t nRecSize)
Adds a size value to the record size prediction.
Definition: xerecord.hxx:164