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 #include <type_traits>
29 
30 // Base classes to export Excel records =======================================
31 
40 {
41 public:
43 
44  // this class is stored both ref-counted and by value
50  { return *this; }
52  { return *this; }
53 
54  virtual ~XclExpRecordBase();
55 
57  virtual void Save( XclExpStream& rStrm );
58  virtual void SaveXml( XclExpXmlStream& rStrm );
59 };
60 
61 /*namespace std
62 {
63  template<typename T,
64  typename = typename std::enable_if<
65  std::is_base_of<XclExpRecordBase,T>::value
66  >::type>
67  class shared_ptr
68  {
69  shared_ptr() {}
70  };
71 };*/
72 
74 {
75 public:
77  virtual ~XclExpDelegatingRecord() override;
78 
79  virtual void SaveXml( XclExpXmlStream& rStrm ) override;
80 private:
82 };
83 
85 {
86 public:
87  explicit XclExpXmlElementRecord(sal_Int32 nElement);
88  virtual ~XclExpXmlElementRecord() override;
89 
90 protected:
91  sal_Int32 mnElement;
92 };
93 
95 {
96 public:
97  explicit XclExpXmlStartElementRecord(sal_Int32 nElement);
98  virtual ~XclExpXmlStartElementRecord() override;
99 
101  virtual void SaveXml( XclExpXmlStream& rStrm ) override;
102 };
103 
105 {
106 public:
107  explicit XclExpXmlEndElementRecord(sal_Int32 nElement);
108  virtual ~XclExpXmlEndElementRecord() override;
109 
111  virtual void SaveXml( XclExpXmlStream& rStrm ) override;
112 };
113 
115 {
116 public:
117  explicit XclExpXmlStartSingleElementRecord(sal_Int32 nElement);
118  virtual ~XclExpXmlStartSingleElementRecord() override;
119 
121  virtual void SaveXml( XclExpXmlStream& rStrm ) override;
122 };
123 
125 {
126 public:
128  virtual ~XclExpXmlEndSingleElementRecord() override;
129 
131  virtual void SaveXml( XclExpXmlStream& rStrm ) override;
132 };
133 
144 {
145 public:
148  explicit XclExpRecord(
149  sal_uInt16 nRecId = EXC_ID_UNKNOWN,
150  std::size_t nRecSize = 0 );
151 
152  XclExpRecord(XclExpRecord const &) = default;
153 
154  virtual ~XclExpRecord() override;
155 
157  sal_uInt16 GetRecId() const { return mnRecId; }
159  std::size_t GetRecSize() const { return mnRecSize; }
160 
162  void SetRecId( sal_uInt16 nRecId ) { mnRecId = nRecId; }
164  void SetRecSize( std::size_t nRecSize ) { mnRecSize = nRecSize; }
166  void AddRecSize( std::size_t nRecSize ) { mnRecSize += nRecSize; }
168  void SetRecHeader( sal_uInt16 nRecId, std::size_t nRecSize );
169 
171  virtual void Save( XclExpStream& rStrm ) override;
172 
173 protected:
176  virtual void WriteBody( XclExpStream& rStrm );
177 
178 private:
179  std::size_t mnRecSize;
180  sal_uInt16 mnRecId;
181 };
182 
185 {
186 public:
188  inline explicit XclExpEmptyRecord( sal_uInt16 nRecId );
189 };
190 
191 inline XclExpEmptyRecord::XclExpEmptyRecord( sal_uInt16 nRecId ) :
192  XclExpRecord( nRecId, 0 )
193 {
194 }
195 
198 template< typename Type >
200 {
201 public:
205  explicit XclExpValueRecord( sal_uInt16 nRecId, const Type& rValue, std::size_t nSize = sizeof( Type ) ) :
206  XclExpRecord( nRecId, nSize ), maValue( rValue ), mnAttribute( -1 ) {}
207 
209  const Type& GetValue() const { return maValue; }
211  void SetValue( const Type& rValue ) { maValue = rValue; }
212 
214  XclExpValueRecord* SetAttribute( sal_Int32 nId );
215 
217  void SaveXml( XclExpXmlStream& rStrm ) override;
218 
219 private:
221  virtual void WriteBody( XclExpStream& rStrm ) override { rStrm << maValue; }
222  // inlining prevents warning in wntmsci10
223 
224 private:
226  sal_Int32 mnAttribute;
227 };
228 
229 template< typename Type >
231 {
232  if( mnAttribute == -1 )
233  return;
234  rStrm.WriteAttributes(mnAttribute, OUString::number(maValue));
235 }
236 
237 template<>
239 
240 template< typename Type >
242 {
243  mnAttribute = nId;
244  return this;
245 }
246 
249 
252 
256 {
257 public:
260  explicit XclExpBoolRecord( sal_uInt16 nRecId, bool bValue, sal_Int32 nAttribute = -1 ) :
261  XclExpRecord( nRecId, 2 ), mbValue( bValue ), mnAttribute( nAttribute ) {}
262 
264  bool GetBool() const { return mbValue; }
265 
266  virtual void SaveXml( XclExpXmlStream& rStrm ) override;
267 
268 private:
270  virtual void WriteBody( XclExpStream& rStrm ) override;
271 
272 private:
273  bool mbValue;
274  sal_Int32 mnAttribute;
275 };
276 
279 {
280 public:
284  explicit XclExpDummyRecord(
285  sal_uInt16 nRecId, const void* pRecData, std::size_t nRecSize );
286 
288  void SetData( const void* pRecData, std::size_t nRecSize );
289 
290 private:
292  virtual void WriteBody( XclExpStream& rStrm ) override;
293 
294 private:
295  const void* mpData;
296 };
297 
298 // Future records =============================================================
299 
301 {
302 public:
303  explicit XclExpFutureRecord( XclFutureRecType eRecType,
304  sal_uInt16 nRecId, std::size_t nRecSize );
305 
307  virtual void Save( XclExpStream& rStrm ) override;
308 
309 private:
311 };
312 
313 // List of records ============================================================
314 
321 template< typename RecType = XclExpRecordBase >
323 {
324 public:
326 
327  bool IsEmpty() const { return maRecs.empty(); }
328  size_t GetSize() const { return maRecs.size(); }
329 
331  bool HasRecord( size_t nPos ) const
332  { return nPos < maRecs.size(); }
334  RecType* GetRecord( size_t nPos ) const
335  { return nPos < maRecs.size() ? maRecs[ nPos ].get() : nullptr; }
337  RecType* GetFirstRecord() const
338  { return maRecs.empty() ? nullptr : maRecs.front().get(); }
340  RecType* GetLastRecord() const
341  { return maRecs.empty() ? nullptr : maRecs.back().get(); }
342 
344  void InsertRecord( RecType* pRec, size_t nPos )
345  { assert(pRec); maRecs.insert( maRecs.begin() + ::std::min( nPos, maRecs.size() ), pRec ); }
346  void InsertRecord( RecordRefType pRec, size_t nPos )
347  { assert(pRec); maRecs.insert( maRecs.begin() + ::std::min( nPos, maRecs.size() ), std::move(pRec) ); }
349  void AppendRecord( RecType* pRec )
350  { if (pRec) maRecs.push_back( pRec ); }
351  void AppendRecord( const RecordRefType& xRec )
352  { if (xRec) maRecs.push_back( xRec.get() ); }
353  void AppendRecord( RecordRefType xRec ) &&
354  { if (xRec) maRecs.push_back( std::move(xRec) ); }
356  void ReplaceRecord( RecType* pRec, size_t nPos )
357  { if (pRec) maRecs[nPos] = pRec; else RemoveRecord( nPos ); }
358  void ReplaceRecord( RecordRefType const & xRec, size_t nPos )
359  { ReplaceRecord(xRec.get(), nPos); }
360 
362  void AppendNewRecord( RecType* pRec )
363  { assert(pRec); maRecs.push_back( pRec ); }
364  void AppendNewRecord( RecordRefType const & xRec )
365  { AppendNewRecord(xRec.get()); }
366  void AppendNewRecord( RecordRefType xRec ) &&
367  { assert(xRec); maRecs.append(std::move(xRec)); }
368 
370  void RemoveRecord( size_t nPos )
371  { maRecs.erase( maRecs.begin() + nPos ); }
373  void RemoveAllRecords() { maRecs.clear(); }
374 
376  virtual void Save( XclExpStream& rStrm ) override
377  {
378  // inlining prevents warning in wntmsci10
379  for( typename RecordVec::iterator aIt = maRecs.begin(), aEnd = maRecs.end(); aIt != aEnd; ++aIt )
380  (*aIt)->Save( rStrm );
381  }
382 
383  virtual void SaveXml( XclExpXmlStream& rStrm ) override
384  {
385  // inlining prevents warning in wntmsci10
386  for( typename RecordVec::iterator aIt = maRecs.begin(), aEnd = maRecs.end(); aIt != aEnd; ++aIt )
387  (*aIt)->SaveXml( rStrm );
388  }
389 
390 private:
391  typedef ::std::vector< RecordRefType > RecordVec;
392  RecordVec maRecs;
393 };
394 
397 {
398 public:
399  explicit XclExpSubStream( sal_uInt16 nSubStrmType );
400 
402  virtual void Save( XclExpStream& rStrm ) override;
403 
404 private:
405  sal_uInt16 mnSubStrmType;
406 };
407 
408 #endif
409 
410 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetValue(const Type &rValue)
Sets a new record value.
Definition: xerecord.hxx:211
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:299
rtl::Reference< RecType > RecordRefType
Definition: xerecord.hxx:325
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:376
virtual ~XclExpXmlElementRecord() override
Definition: xerecord.cxx:66
void ReplaceRecord(RecordRefType const &xRec, size_t nPos)
Definition: xerecord.hxx:358
A list of Excel record objects.
Definition: xerecord.hxx:322
XclExpXmlStartElementRecord(sal_Int32 nElement)
Definition: xerecord.cxx:70
sal_Int32 mnAttribute
The record data.
Definition: xerecord.hxx:274
Represents a complete substream of records enclosed into a pair of BOF/EOF records.
Definition: xerecord.hxx:396
This class is used to export Excel record streams.
Definition: xestream.hxx:71
virtual void WriteBody(XclExpStream &rStrm) override
Writes the body of the record.
Definition: xerecord.hxx:221
virtual void SaveXml(XclExpXmlStream &rStrm) override
Definition: xerecord.hxx:383
RecordVec maRecs
Definition: xerecord.hxx:392
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:251
void AppendRecord(RecType *pRec)
Appends a record to the list.
Definition: xerecord.hxx:349
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:209
void SetRecSize(std::size_t nRecSize)
Sets a new record size prediction.
Definition: xerecord.hxx:164
virtual ~XclExpXmlEndSingleElementRecord() override
Definition: xerecord.cxx:121
std::size_t GetRecSize() const
Returns the current record size prediction.
Definition: xerecord.hxx:159
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:356
XclFutureRecType
Enumerates different header types of future records.
Definition: xlconst.hxx:242
sal_uInt16 GetRecId() const
Returns the current record ID.
Definition: xerecord.hxx:157
XclExpRecordBase & operator=(XclExpRecordBase &&) noexcept
Definition: xerecord.hxx:51
RecType * GetLastRecord() const
Returns reference to the last existing record or empty reference, if list is empty.
Definition: xerecord.hxx:340
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
Record which exports a memory data array.
Definition: xerecord.hxx:278
XclExpSubStream(sal_uInt16 nSubStrmType)
Definition: xerecord.cxx:216
XclExpRecordBase & operator=(XclExpRecordBase const &)
Definition: xerecord.hxx:49
Base class for all Excel records.
Definition: xerecord.hxx:39
bool HasRecord(size_t nPos) const
Returns true, if the passed index points to an exiting record.
Definition: xerecord.hxx:331
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:205
XclExpRecordBase(XclExpRecordBase &&)
Definition: xerecord.hxx:47
void AppendRecord(RecordRefType xRec)&&
Definition: xerecord.hxx:353
A record with a single value of type Type.
Definition: xerecord.hxx:199
void AppendNewRecord(RecordRefType xRec)&&
Definition: xerecord.hxx:366
void RemoveRecord(size_t nPos)
Removes the record at the specified position from the list.
Definition: xerecord.hxx:370
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:364
void InsertRecord(RecType *pRec, size_t nPos)
Inserts a record at the specified position into the list.
Definition: xerecord.hxx:344
virtual void SaveXml(XclExpXmlStream &rStrm) override
Ends the element nElement.
Definition: xerecord.cxx:96
void InsertRecord(RecordRefType pRec, size_t nPos)
Definition: xerecord.hxx:346
XclExpRecordBase * mpRecord
Definition: xerecord.hxx:81
void AppendRecord(const RecordRefType &xRec)
Definition: xerecord.hxx:351
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:337
virtual void SaveXml(XclExpXmlStream &rStrm) override
Definition: xerecord.cxx:171
sal_uInt16 mnRecId
The predicted record size.
Definition: xerecord.hxx:180
virtual ~XclExpXmlStartSingleElementRecord() override
Definition: xerecord.cxx:107
void AppendNewRecord(RecType *pRec)
Appends a newly created record to the list.
Definition: xerecord.hxx:362
bool GetBool() const
Returns the Boolean value of the record.
Definition: xerecord.hxx:264
XclFutureRecType meRecType
Definition: xerecord.hxx:310
XclExpValueRecord< sal_uInt16 > XclExpUInt16Record
A record containing an unsigned 16-bit value.
Definition: xerecord.hxx:248
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:334
XclExpRecordBase(XclExpRecordBase const &)
Definition: xerecord.hxx:45
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:184
void SaveXml(XclExpXmlStream &rStrm) override
Write the OOXML attribute and its value.
Definition: xerecord.hxx:230
void RemoveAllRecords()
Removes all records from the list.
Definition: xerecord.hxx:373
sal_uInt16 mnSubStrmType
Definition: xerecord.hxx:405
XclExpEmptyRecord(sal_uInt16 nRecId)
Definition: xerecord.hxx:191
std::size_t mnRecSize
Definition: xerecord.hxx:179
size_t GetSize() const
Definition: xerecord.hxx:328
virtual ~XclExpXmlEndElementRecord() override
Definition: xerecord.cxx:92
const void * mpData
Definition: xerecord.hxx:295
XclExpValueRecord * SetAttribute(sal_Int32 nId)
Sets the OOXML attribute this record corresponds to.
Definition: xerecord.hxx:241
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:226
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:327
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:162
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:143
Record which contains a Boolean value.
Definition: xerecord.hxx:255
::std::vector< RecordRefType > RecordVec
Definition: xerecord.hxx:391
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:260
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:166