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 #ifndef INCLUDED_SC_SOURCE_FILTER_INC_XERECORD_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_INC_XERECORD_HXX
22 
23 #include "xlconst.hxx"
24 #include "xestream.hxx"
25 #include "xlstream.hxx"
27 #include <rtl/ref.hxx>
28 
29 // Base classes to export Excel records =======================================
30 
39 {
40 public:
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 {
74 public:
76  virtual ~XclExpDelegatingRecord() override;
77 
78  virtual void SaveXml( XclExpXmlStream& rStrm ) override;
79 private:
81 };
82 
84 {
85 public:
86  explicit XclExpXmlElementRecord(sal_Int32 nElement);
87  virtual ~XclExpXmlElementRecord() override;
88 
89 protected:
90  sal_Int32 mnElement;
91 };
92 
94 {
95 public:
96  explicit XclExpXmlStartElementRecord(sal_Int32 nElement);
97  virtual ~XclExpXmlStartElementRecord() override;
98 
100  virtual void SaveXml( XclExpXmlStream& rStrm ) override;
101 };
102 
104 {
105 public:
106  explicit XclExpXmlEndElementRecord(sal_Int32 nElement);
107  virtual ~XclExpXmlEndElementRecord() override;
108 
110  virtual void SaveXml( XclExpXmlStream& rStrm ) override;
111 };
112 
114 {
115 public:
116  explicit XclExpXmlStartSingleElementRecord(sal_Int32 nElement);
117  virtual ~XclExpXmlStartSingleElementRecord() override;
118 
120  virtual void SaveXml( XclExpXmlStream& rStrm ) override;
121 };
122 
124 {
125 public:
127  virtual ~XclExpXmlEndSingleElementRecord() override;
128 
130  virtual void SaveXml( XclExpXmlStream& rStrm ) override;
131 };
132 
143 {
144 public:
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 
172 protected:
175  virtual void WriteBody( XclExpStream& rStrm );
176 
177 private:
178  std::size_t mnRecSize;
179  sal_uInt16 mnRecId;
180 };
181 
184 {
185 public:
187  inline explicit XclExpEmptyRecord( sal_uInt16 nRecId );
188 };
189 
190 inline XclExpEmptyRecord::XclExpEmptyRecord( sal_uInt16 nRecId ) :
191  XclExpRecord( nRecId, 0 )
192 {
193 }
194 
197 template< typename Type >
199 {
200 public:
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 
218 private:
220  virtual void WriteBody( XclExpStream& rStrm ) override { rStrm << maValue; }
221  // inlining prevents warning in wntmsci10
222 
223 private:
225  sal_Int32 mnAttribute;
226 };
227 
228 template< typename Type >
230 {
231  if( mnAttribute == -1 )
232  return;
233  rStrm.WriteAttributes(mnAttribute, OUString::number(maValue));
234 }
235 
236 template<>
238 
239 template< typename Type >
241 {
242  mnAttribute = nId;
243  return this;
244 }
245 
248 
251 
255 {
256 public:
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 
267 private:
269  virtual void WriteBody( XclExpStream& rStrm ) override;
270 
271 private:
272  bool mbValue;
273  sal_Int32 mnAttribute;
274 };
275 
278 {
279 public:
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 
289 private:
291  virtual void WriteBody( XclExpStream& rStrm ) override;
292 
293 private:
294  const void* mpData;
295 };
296 
297 // Future records =============================================================
298 
300 {
301 public:
302  explicit XclExpFutureRecord( XclFutureRecType eRecType,
303  sal_uInt16 nRecId, std::size_t nRecSize );
304 
306  virtual void Save( XclExpStream& rStrm ) override;
307 
308 private:
310 };
311 
312 // List of records ============================================================
313 
320 template< typename RecType = XclExpRecordBase >
322 {
323 public:
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() ); }
352  void AppendRecord( RecordRefType xRec ) &&
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()); }
365  void AppendNewRecord( RecordRefType xRec ) &&
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 
389 private:
390  typedef ::std::vector< RecordRefType > RecordVec;
391  RecordVec maRecs;
392 };
393 
396 {
397 public:
398  explicit XclExpSubStream( sal_uInt16 nSubStrmType );
399 
401  virtual void Save( XclExpStream& rStrm ) override;
402 
403 private:
404  sal_uInt16 mnSubStrmType;
405 };
406 
407 #endif
408 
409 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetValue(const Type &rValue)
Sets a new record value.
Definition: xerecord.hxx:210
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:301
rtl::Reference< RecType > RecordRefType
Definition: xerecord.hxx:324
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:375
virtual ~XclExpXmlElementRecord() override
Definition: xerecord.cxx:66
void ReplaceRecord(RecordRefType const &xRec, size_t nPos)
Definition: xerecord.hxx:357
A list of Excel record objects.
Definition: xerecord.hxx:321
XclExpXmlStartElementRecord(sal_Int32 nElement)
Definition: xerecord.cxx:70
sal_Int32 mnAttribute
The record data.
Definition: xerecord.hxx:273
Represents a complete substream of records enclosed into a pair of BOF/EOF records.
Definition: xerecord.hxx:395
This class is used to export Excel record streams.
Definition: xestream.hxx:73
virtual void WriteBody(XclExpStream &rStrm) override
Writes the body of the record.
Definition: xerecord.hxx:220
virtual void SaveXml(XclExpXmlStream &rStrm) override
Definition: xerecord.hxx:382
RecordVec maRecs
Definition: xerecord.hxx:391
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:250
void AppendRecord(RecType *pRec)
Appends a record to the list.
Definition: xerecord.hxx:348
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:208
void SetRecSize(std::size_t nRecSize)
Sets a new record size prediction.
Definition: xerecord.hxx:163
virtual ~XclExpXmlEndSingleElementRecord() override
Definition: xerecord.cxx:121
std::size_t GetRecSize() const
Returns the current record size prediction.
Definition: xerecord.hxx:158
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:355
XclFutureRecType
Enumerates different header types of future records.
Definition: xlconst.hxx:242
sal_uInt16 GetRecId() const
Returns the current record ID.
Definition: xerecord.hxx:156
XclExpRecordBase & operator=(XclExpRecordBase &&) noexcept
Definition: xerecord.hxx:50
RecType * GetLastRecord() const
Returns reference to the last existing record or empty reference, if list is empty.
Definition: xerecord.hxx:339
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
Record which exports a memory data array.
Definition: xerecord.hxx:277
XclExpSubStream(sal_uInt16 nSubStrmType)
Definition: xerecord.cxx:216
XclExpRecordBase & operator=(XclExpRecordBase const &)
Definition: xerecord.hxx:48
Base class for all Excel records.
Definition: xerecord.hxx:38
bool HasRecord(size_t nPos) const
Returns true, if the passed index points to an exiting record.
Definition: xerecord.hxx:330
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:204
XclExpRecordBase(XclExpRecordBase &&)
Definition: xerecord.hxx:46
void AppendRecord(RecordRefType xRec)&&
Definition: xerecord.hxx:352
A record with a single value of type Type.
Definition: xerecord.hxx:198
void AppendNewRecord(RecordRefType xRec)&&
Definition: xerecord.hxx:365
void RemoveRecord(size_t nPos)
Removes the record at the specified position from the list.
Definition: xerecord.hxx:369
XclExpXmlElementRecord(sal_Int32 nElement)
Definition: xerecord.cxx:61
const sal_uInt16 EXC_ID_UNKNOWN
Definition: xlstream.hxx:36
void AppendNewRecord(RecordRefType const &xRec)
Definition: xerecord.hxx:363
void InsertRecord(RecType *pRec, size_t nPos)
Inserts a record at the specified position into the list.
Definition: xerecord.hxx:343
virtual void SaveXml(XclExpXmlStream &rStrm) override
Ends the element nElement.
Definition: xerecord.cxx:96
void InsertRecord(RecordRefType pRec, size_t nPos)
Definition: xerecord.hxx:345
XclExpRecordBase * mpRecord
Definition: xerecord.hxx:80
void AppendRecord(const RecordRefType &xRec)
Definition: xerecord.hxx:350
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:336
virtual void SaveXml(XclExpXmlStream &rStrm) override
Definition: xerecord.cxx:171
sal_uInt16 mnRecId
The predicted record size.
Definition: xerecord.hxx:179
virtual ~XclExpXmlStartSingleElementRecord() override
Definition: xerecord.cxx:107
void AppendNewRecord(RecType *pRec)
Appends a newly created record to the list.
Definition: xerecord.hxx:361
bool GetBool() const
Returns the Boolean value of the record.
Definition: xerecord.hxx:263
XclFutureRecType meRecType
Definition: xerecord.hxx:309
XclExpValueRecord< sal_uInt16 > XclExpUInt16Record
A record containing an unsigned 16-bit value.
Definition: xerecord.hxx:247
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:333
XclExpRecordBase(XclExpRecordBase const &)
Definition: xerecord.hxx:44
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:183
void SaveXml(XclExpXmlStream &rStrm) override
Write the OOXML attribute and its value.
Definition: xerecord.hxx:229
void RemoveAllRecords()
Removes all records from the list.
Definition: xerecord.hxx:372
sal_uInt16 mnSubStrmType
Definition: xerecord.hxx:404
XclExpEmptyRecord(sal_uInt16 nRecId)
Definition: xerecord.hxx:190
std::size_t mnRecSize
Definition: xerecord.hxx:178
size_t GetSize() const
Definition: xerecord.hxx:327
virtual ~XclExpXmlEndElementRecord() override
Definition: xerecord.cxx:92
const void * mpData
Definition: xerecord.hxx:294
XclExpValueRecord * SetAttribute(sal_Int32 nId)
Sets the OOXML attribute this record corresponds to.
Definition: xerecord.hxx:240
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:225
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:326
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:161
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:142
Record which contains a Boolean value.
Definition: xerecord.hxx:254
::std::vector< RecordRefType > RecordVec
Definition: xerecord.hxx:390
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:259
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:165