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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_OOX_DUMP_DUMPERBASE_HXX
21 #define INCLUDED_OOX_DUMP_DUMPERBASE_HXX
28 #include <string_view>
32 #include <com/sun/star/uno/Reference.hxx>
33 #include <com/sun/star/uno/Sequence.hxx>
34 #include <com/sun/star/util/DateTime.hpp>
35 #include <oox/helper/binaryinputstream.hxx>
36 #include <oox/helper/binarystreambase.hxx>
37 #include <oox/helper/storagebase.hxx>
38 #include <rtl/string.hxx>
39 #include <rtl/textenc.h>
40 #include <rtl/ustring.hxx>
41 #include <rtl/ustrbuf.hxx>
42 #include <sal/types.h>
46 namespace com::sun::star
{
47 namespace io
{ class XInputStream
; }
48 namespace io
{ class XOutputStream
; }
49 namespace io
{ class XTextOutputStream2
; }
50 namespace uno
{ class XComponentContext
; }
54 class TextInputStream
;
64 inline constexpr OUString OOX_DUMP_UNUSED
= u
"unused"_ustr
;
65 inline constexpr OUString OOX_DUMP_UNKNOWN
= u
"?unknown"_ustr
;
67 #define OOX_DUMP_ERRASCII( ascii ) "?err:" ascii
69 #define OOX_DUMP_ERR_NOMAP "no-map"
70 inline constexpr OUString OOX_DUMP_ERR_NONAME
= u
"no-name"_ustr
;
71 #define OOX_DUMP_ERR_STREAM "stream-error"
73 #define OOX_DUMP_DUMPEXT ".dump"
75 const sal_Unicode OOX_DUMP_STRQUOTE
= '\'';
76 const sal_Unicode OOX_DUMP_FMLASTRQUOTE
= '"';
77 const sal_Unicode OOX_DUMP_ADDRABS
= '$';
78 const sal_Unicode OOX_DUMP_R1C1ROW
= 'R';
79 const sal_Unicode OOX_DUMP_R1C1COL
= 'C';
80 const sal_Unicode OOX_DUMP_R1C1OPEN
= '[';
81 const sal_Unicode OOX_DUMP_R1C1CLOSE
= ']';
82 const sal_Unicode OOX_DUMP_RANGESEP
= ':';
83 const sal_Unicode OOX_DUMP_BASECLASS
= 'B';
84 const sal_Unicode OOX_DUMP_FUNCSEP
= ',';
85 const sal_Unicode OOX_DUMP_LISTSEP
= ',';
86 const sal_Unicode OOX_DUMP_TABSEP
= '!';
87 const sal_Unicode OOX_DUMP_ARRAYSEP
= ';';
88 const sal_Unicode OOX_DUMP_EMPTYVALUE
= '~';
89 const sal_Unicode OOX_DUMP_CMDPROMPT
= '?';
90 const sal_Unicode OOX_DUMP_PLACEHOLDER
= '\x01';
92 typedef ::std::pair
< OUString
, OUString
> OUStringPair
;
94 typedef ::std::vector
< OUString
> OUStringVector
;
95 typedef ::std::vector
< sal_Int64
> Int64Vector
;
98 /** Static helper functions for system file and stream access. */
99 class InputOutputHelper
102 // file names -------------------------------------------------------------
104 static OUString
convertFileNameToUrl( const OUString
& rFileName
);
105 static sal_Int32
getFileNamePos( std::u16string_view rFileUrl
);
106 static std::u16string_view
getFileNameExtension( std::u16string_view rFileUrl
);
108 // input streams ----------------------------------------------------------
110 static css::uno::Reference
< css::io::XInputStream
>
112 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
113 const OUString
& rFileName
);
115 // output streams ---------------------------------------------------------
117 static css::uno::Reference
< css::io::XOutputStream
>
119 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
120 const OUString
& rFileName
);
122 static css::uno::Reference
< css::io::XTextOutputStream2
>
123 openTextOutputStream(
124 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
125 const css::uno::Reference
< css::io::XOutputStream
>& rxOutStrm
,
126 rtl_TextEncoding eTextEnc
);
128 static css::uno::Reference
< css::io::XTextOutputStream2
>
129 openTextOutputStream(
130 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
131 const OUString
& rFileName
,
132 rtl_TextEncoding eTextEnc
);
136 class BinaryInputStreamRef
: public ::oox::BinaryInputStreamRef
139 BinaryInputStreamRef() {}
141 /*implicit*/ BinaryInputStreamRef( std::shared_ptr
<BinaryInputStream
> const & pInStrm
) :
142 ::oox::BinaryInputStreamRef( pInStrm
) {}
144 /*implicit*/ BinaryInputStreamRef( const css::uno::Reference
< css::io::XInputStream
>& rxInStrm
) :
145 ::oox::BinaryInputStreamRef( std::make_shared
<BinaryXInputStream
>( rxInStrm
, true ) ) {}
147 template< typename StreamType
>
148 /*implicit*/ BinaryInputStreamRef( const std::shared_ptr
< StreamType
>& rxInStrm
) :
149 ::oox::BinaryInputStreamRef( rxInStrm
) {}
153 /** Specifiers for atomic data types. */
156 DATATYPE_VOID
, ///< No data type.
157 DATATYPE_INT8
, ///< Signed 8-bit integer.
158 DATATYPE_UINT8
, ///< Unsigned 8-bit integer.
159 DATATYPE_INT16
, ///< Signed 16-bit integer.
160 DATATYPE_UINT16
, ///< Unsigned 16-bit integer.
161 DATATYPE_INT32
, ///< Signed 32-bit integer.
162 DATATYPE_UINT32
, ///< Unsigned 32-bit integer.
163 DATATYPE_INT64
, ///< Signed 64-bit integer.
164 DATATYPE_UINT64
, ///< Unsigned 64-bit integer.
165 DATATYPE_FLOAT
, ///< Floating-point, single precision.
166 DATATYPE_DOUBLE
///< Floating-point, double precision.
170 /** Specifiers for the output format of values. */
173 FORMATTYPE_NONE
, ///< No numeric format (e.g. show name only).
174 FORMATTYPE_DEC
, ///< Decimal.
175 FORMATTYPE_HEX
, ///< Hexadecimal.
176 FORMATTYPE_SHORTHEX
, ///< Hexadecimal, as short as possible (no leading zeros).
177 FORMATTYPE_BIN
, ///< Binary.
178 FORMATTYPE_FIX
, ///< Fixed-point.
179 FORMATTYPE_BOOL
///< Boolean ('true' or 'false').
183 /** Describes the output format of a data item.
185 Data items are written in the following format:
187 <NAME>=<VALUE>=<NAME-FROM-LIST>
189 NAME is the name of the data item. The name is contained in the member
190 maItemName. If the name is empty, only the value is written (without a
191 leading equality sign).
193 VALUE is the numeric value of the data item. Its format is dependent on the
194 output format given in the member meFmtType. If the format type is
195 FORMATTYPE_NONE, no value is written.
197 NAME-FROM-LIST is a symbolic name for the current value of the data item.
198 Various types of name lists produce different names for values, which can
199 be used for enumerations or names for single bits in bitfields (see class
200 NameListBase and derived classes). The name of the list is given in the
201 member maListName. If it is empty, no name is written for the value.
205 DataType meDataType
; ///< Data type of the item.
206 FormatType meFmtType
; ///< Output format for the value.
207 OUString maItemName
; ///< Name of the item.
208 OUString maListName
; ///< Name of a name list to be used for this item.
210 explicit ItemFormat();
212 void set( DataType eDataType
, FormatType eFmtType
, const OUString
& rItemName
);
214 /** Initializes the struct from a vector of strings containing the item format.
216 The vector must contain at least 2 strings. The struct is filled from
217 the strings in the vector in the following order:
218 1) Data type (one of: [u]int8, [u]int16, [u]int32, [u]int64, float, double).
219 2) Format type (one of: dec, hex, shorthex, bin, fix, bool, unused, unknown).
220 3) Item name (optional).
221 4) Name list name (optional).
223 @return Iterator pointing to the first unhandled string.
225 OUStringVector::const_iterator
parse( const OUStringVector
& rFormatVec
);
227 /** Initializes the struct from a string containing the item format.
229 The string must have the following format:
230 DATATYPE,FORMATTYPE[,ITEMNAME[,LISTNAME]]
232 DATATYPE is the data type of the item (see above for possible values).
233 FORMATTYPE is the format type of the item (see above for possible values).
234 ITEMNAME is the name of the item (optional).
235 LISTNAME is the name of a name list (optional).
237 @return List containing remaining unhandled format strings.
239 OUStringVector
parse( std::u16string_view rFormatStr
);
243 /** Static helper functions for formatted output to strings. */
247 // append string to string ------------------------------------------------
249 static void appendChar( OUStringBuffer
& rStr
, sal_Unicode cChar
, sal_Int32 nCount
);
250 static void appendString( OUStringBuffer
& rStr
, std::u16string_view rData
, sal_Int32 nWidth
, sal_Unicode cFill
= ' ' );
252 // append decimal ---------------------------------------------------------
254 static void appendDec( OUStringBuffer
& rStr
, sal_uInt8 nData
, sal_Int32 nWidth
= 0, sal_Unicode cFill
= ' ' );
255 static void appendDec( OUStringBuffer
& rStr
, sal_Int8 nData
, sal_Int32 nWidth
= 0, sal_Unicode cFill
= ' ' );
256 static void appendDec( OUStringBuffer
& rStr
, sal_uInt16 nData
, sal_Int32 nWidth
= 0, sal_Unicode cFill
= ' ' );
257 static void appendDec( OUStringBuffer
& rStr
, sal_Int16 nData
, sal_Int32 nWidth
= 0, sal_Unicode cFill
= ' ' );
258 static void appendDec( OUStringBuffer
& rStr
, sal_uInt32 nData
, sal_Int32 nWidth
= 0, sal_Unicode cFill
= ' ' );
259 static void appendDec( OUStringBuffer
& rStr
, sal_Int32 nData
, sal_Int32 nWidth
= 0, sal_Unicode cFill
= ' ' );
260 static void appendDec( OUStringBuffer
& rStr
, sal_uInt64 nData
, sal_Int32 nWidth
= 0, sal_Unicode cFill
= ' ' );
261 static void appendDec( OUStringBuffer
& rStr
, sal_Int64 nData
, sal_Int32 nWidth
= 0, sal_Unicode cFill
= ' ' );
262 static void appendDec( OUStringBuffer
& rStr
, double fData
, sal_Int32 nWidth
= 0, sal_Unicode cFill
= ' ' );
264 // append hexadecimal -----------------------------------------------------
266 static void appendHex( OUStringBuffer
& rStr
, sal_uInt8 nData
, bool bPrefix
= true );
267 static void appendHex( OUStringBuffer
& rStr
, sal_Int8 nData
, bool bPrefix
= true );
268 static void appendHex( OUStringBuffer
& rStr
, sal_uInt16 nData
, bool bPrefix
= true );
269 static void appendHex( OUStringBuffer
& rStr
, sal_Int16 nData
, bool bPrefix
= true );
270 static void appendHex( OUStringBuffer
& rStr
, sal_uInt32 nData
, bool bPrefix
= true );
271 static void appendHex( OUStringBuffer
& rStr
, sal_Int32 nData
, bool bPrefix
= true );
272 static void appendHex( OUStringBuffer
& rStr
, sal_uInt64 nData
, bool bPrefix
= true );
273 static void appendHex( OUStringBuffer
& rStr
, sal_Int64 nData
, bool bPrefix
= true );
274 static void appendHex( OUStringBuffer
& rStr
, double fData
, bool bPrefix
= true );
276 // append shortened hexadecimal -------------------------------------------
278 static void appendShortHex( OUStringBuffer
& rStr
, sal_uInt8 nData
, bool bPrefix
= true );
279 static void appendShortHex( OUStringBuffer
& rStr
, sal_Int8 nData
, bool bPrefix
= true );
280 static void appendShortHex( OUStringBuffer
& rStr
, sal_uInt16 nData
, bool bPrefix
= true );
281 static void appendShortHex( OUStringBuffer
& rStr
, sal_Int16 nData
, bool bPrefix
= true );
282 static void appendShortHex( OUStringBuffer
& rStr
, sal_uInt32 nData
, bool bPrefix
= true );
283 static void appendShortHex( OUStringBuffer
& rStr
, sal_Int32 nData
, bool bPrefix
= true );
284 static void appendShortHex( OUStringBuffer
& rStr
, sal_uInt64 nData
, bool bPrefix
= true );
285 static void appendShortHex( OUStringBuffer
& rStr
, sal_Int64 nData
, bool bPrefix
= true );
286 static void appendShortHex( OUStringBuffer
& rStr
, double fData
, bool bPrefix
= true );
288 // append binary ----------------------------------------------------------
290 static void appendBin( OUStringBuffer
& rStr
, sal_uInt8 nData
, bool bDots
= true );
291 static void appendBin( OUStringBuffer
& rStr
, sal_Int8 nData
, bool bDots
= true );
292 static void appendBin( OUStringBuffer
& rStr
, sal_uInt16 nData
, bool bDots
= true );
293 static void appendBin( OUStringBuffer
& rStr
, sal_Int16 nData
, bool bDots
= true );
294 static void appendBin( OUStringBuffer
& rStr
, sal_uInt32 nData
, bool bDots
= true );
295 static void appendBin( OUStringBuffer
& rStr
, sal_Int32 nData
, bool bDots
= true );
296 static void appendBin( OUStringBuffer
& rStr
, sal_uInt64 nData
, bool bDots
= true );
297 static void appendBin( OUStringBuffer
& rStr
, sal_Int64 nData
, bool bDots
= true );
298 static void appendBin( OUStringBuffer
& rStr
, double fData
, bool bDots
= true );
300 // append fixed-point decimal ---------------------------------------------
302 template< typename Type
>
303 static void appendFix( OUStringBuffer
& rStr
, Type nData
, sal_Int32 nWidth
= 0 );
305 // append formatted value -------------------------------------------------
307 static void appendBool( OUStringBuffer
& rStr
, bool bData
);
308 template< typename Type
>
309 static void appendValue( OUStringBuffer
& rStr
, Type nData
, FormatType eFmtType
);
311 // encoded text output ----------------------------------------------------
313 static void appendCChar( OUStringBuffer
& rStr
, sal_Unicode cChar
, bool bPrefix
= true );
314 static void appendEncChar( OUStringBuffer
& rStr
, sal_Unicode cChar
, sal_Int32 nCount
, bool bPrefix
= true );
315 static void appendEncString( OUStringBuffer
& rStr
, std::u16string_view rData
, bool bPrefix
= true );
317 // token list -------------------------------------------------------------
319 static void appendToken( OUStringBuffer
& rStr
, std::u16string_view rToken
, sal_Unicode cSep
= OOX_DUMP_LISTSEP
);
321 static void appendIndex( OUStringBuffer
& rStr
, sal_Int64 nIdx
);
323 static std::u16string_view
getToken( std::u16string_view rData
, sal_Int32
& rnPos
, sal_Unicode cSep
= OOX_DUMP_LISTSEP
);
325 /** Encloses the passed string with the passed characters. Uses cOpen, if cClose is NUL. */
326 static void enclose( OUStringBuffer
& rStr
, sal_Unicode cOpen
, sal_Unicode cClose
= '\0' );
328 // string conversion ------------------------------------------------------
330 static std::u16string_view
trimSpaces( std::u16string_view rStr
);
331 static OUString
trimTrailingNul( const OUString
& rStr
);
333 static OString
convertToUtf8( std::u16string_view rStr
);
334 static DataType
convertToDataType( std::u16string_view rStr
);
335 static FormatType
convertToFormatType( std::u16string_view rStr
);
337 static bool convertFromDec( sal_Int64
& ornData
, std::u16string_view rData
);
338 static bool convertFromHex( sal_Int64
& ornData
, std::u16string_view rData
);
340 static bool convertStringToInt( sal_Int64
& ornData
, std::u16string_view rData
);
341 static bool convertStringToDouble( double& orfData
, std::u16string_view rData
);
342 static bool convertStringToBool( std::u16string_view rData
);
344 static OUStringPair
convertStringToPair( const OUString
& rString
, sal_Unicode cSep
= '=' );
346 // string to list conversion ----------------------------------------------
348 static void convertStringToStringList( OUStringVector
& orVec
, std::u16string_view rData
, bool bIgnoreEmpty
);
349 static void convertStringToIntList( Int64Vector
& orVec
, std::u16string_view rData
, bool bIgnoreEmpty
);
353 template< typename Type
>
354 void StringHelper::appendFix( OUStringBuffer
& rStr
, Type nData
, sal_Int32 nWidth
)
356 appendDec( rStr
, static_cast< double >( nData
) / std::pow( 2.0, 4.0 * sizeof( Type
) ), nWidth
);
359 template< typename Type
>
360 void StringHelper::appendValue( OUStringBuffer
& rStr
, Type nData
, FormatType eFmtType
)
364 case FORMATTYPE_DEC
: appendDec( rStr
, nData
); break;
365 case FORMATTYPE_HEX
: appendHex( rStr
, nData
); break;
366 case FORMATTYPE_SHORTHEX
: appendShortHex( rStr
, nData
); break;
367 case FORMATTYPE_BIN
: appendBin( rStr
, nData
); break;
368 case FORMATTYPE_FIX
: appendFix( rStr
, nData
); break;
369 case FORMATTYPE_BOOL
: appendBool( rStr
, static_cast<bool>(nData
) ); break; // avoid loplugin:pointerbool warning
375 class String
: public OUString
379 /*implicit*/ String( const OUString
& rStr
) : OUString( rStr
) {}
380 /*implicit*/ String( const char* pcStr
) : OUString( OUString::createFromAscii( pcStr
? pcStr
: "" ) ) {}
381 /*implicit*/ String( sal_Unicode cChar
) : OUString( cChar
) {}
383 bool has() const { return getLength() > 0; }
384 OUString
operator()( const char* pcDefault
) const { if( has() ) return *this; return String( pcDefault
); }
387 const String EMPTY_STRING
;
390 /** Base class for all dumper classes.
392 Derived classes implement the virtual function implIsValid(). It should
393 check all members the other functions rely on. If the function
394 implIsValid() returns true, all references and pointers can be used without
397 Overview of all classes in this header file based on this Base class:
403 | +----> ConstList ------> MultiList
405 | +----> FlagsList ------> CombiList
407 | +----> UnitConverter
409 +----> SharedConfigData
415 +----> StorageIterator
419 +----> StorageObjectBase
421 +----> OutputObjectBase
423 | +----> InputObjectBase
425 | +----> BinaryStreamObject
427 | +----> TextStreamObjectBase
429 | | +----> TextStreamObject
431 | | +----> XmlStreamObject
433 | +----> RecordObjectBase
435 | +----> SequenceRecordObjectBase
444 Base(Base
const &) = default;
445 Base(Base
&&) = default;
446 Base
& operator =(Base
const &) = default;
447 Base
& operator =(Base
&&) = default;
449 bool isValid() const { return implIsValid(); }
450 static bool isValid( const std::shared_ptr
< Base
>& rxBase
) { return rxBase
&& rxBase
->isValid(); }
455 virtual bool implIsValid() const = 0;
462 virtual ~ConfigItemBase();
463 void readConfigBlock( TextInputStream
& rStrm
);
468 virtual void implProcessConfigItemStr(
469 TextInputStream
& rStrm
,
470 const OUString
& rKey
,
471 const OUString
& rData
);
473 virtual void implProcessConfigItemInt(
474 TextInputStream
& rStrm
,
476 const OUString
& rData
);
478 void readConfigBlockContents(
479 TextInputStream
& rStrm
);
482 enum LineType
{ LINETYPE_DATA
, LINETYPE_END
};
484 static LineType
readConfigLine(
485 TextInputStream
& rStrm
,
489 void processConfigItem(
490 TextInputStream
& rStrm
,
491 const OUString
& rKey
,
492 const OUString
& rData
);
496 class SharedConfigData
;
500 typedef std::shared_ptr
< NameListBase
> NameListRef
;
502 /** Base class of all classes providing names for specific values (name lists).
504 The idea is to provide a unique interface for all different methods to
505 write specific names for any values. This can be enumerations (dedicated
506 names for a subset of values), or names for bits in bit fields. Classes
507 derived from this base class implement the specific behaviour for the
510 class NameListBase
: public Base
, public ConfigItemBase
513 typedef ::std::map
< sal_Int64
, OUString
> OUStringMap
;
514 typedef OUStringMap::const_iterator const_iterator
;
517 virtual ~NameListBase() override
;
519 /** Sets a name for the specified key. */
520 void setName( sal_Int64 nKey
, const String
& rName
);
522 /** Include all names of the passed list. */
523 void includeList( const NameListRef
& rxList
);
525 /** Returns true, if the map contains an entry for the passed key. */
526 template< typename Type
>
527 bool hasName( Type nKey
) const
528 { return maMap
.count( static_cast< sal_Int64
>( nKey
) ) != 0; }
530 /** Returns the name for the passed key. */
531 template< typename Type
>
532 OUString
getName( const Config
& rCfg
, Type nKey
) const
533 { return implGetName( rCfg
, static_cast< sal_Int64
>( nKey
) ); }
535 /** Returns a display name for the passed double value. */
536 OUString
getName( const Config
& rCfg
, double fValue
) const
537 { return implGetNameDbl( rCfg
, fValue
); }
539 /** Returns a map iterator pointing to the first contained name. */
540 const_iterator
begin() const { return maMap
.begin(); }
541 /** Returns a map iterator pointing one past the last contained name. */
542 const_iterator
end() const { return maMap
.end(); }
545 explicit NameListBase( const SharedConfigData
& rCfgData
) : mrCfgData( rCfgData
) {}
547 virtual bool implIsValid() const override
;
549 virtual void implProcessConfigItemStr(
550 TextInputStream
& rStrm
,
551 const OUString
& rKey
,
552 const OUString
& rData
) override
;
554 virtual void implProcessConfigItemInt(
555 TextInputStream
& rStrm
,
557 const OUString
& rData
) override
;
559 /** Derived classes set the name for the passed key. */
560 virtual void implSetName( sal_Int64 nKey
, const OUString
& rName
) = 0;
561 /** Derived classes generate and return the name for the passed key. */
562 virtual OUString
implGetName( const Config
& rCfg
, sal_Int64 nKey
) const = 0;
563 /** Derived classes generate and return the name for the passed double value. */
564 virtual OUString
implGetNameDbl( const Config
& rCfg
, double fValue
) const = 0;
565 /** Derived classes insert all names and other settings from the passed list. */
566 virtual void implIncludeList( const NameListBase
& rList
) = 0;
568 /** Inserts the passed name into the internal map. */
569 void insertRawName( sal_Int64 nKey
, const OUString
& rName
);
570 /** Returns the name for the passed key, or 0, if nothing found. */
571 const OUString
* findRawName( sal_Int64 nKey
) const;
574 /** Includes name lists, given in a comma separated list of names of the lists. */
575 void include( std::u16string_view rListKeys
);
576 /** Excludes names from the list, given in a comma separated list of their keys. */
577 void exclude( std::u16string_view rKeys
);
581 const SharedConfigData
& mrCfgData
;
585 class ConstList
: public NameListBase
588 explicit ConstList( const SharedConfigData
& rCfgData
);
590 /** Enables or disables automatic quotation of returned names. */
591 void setQuoteNames( bool bQuoteNames
) { mbQuoteNames
= bQuoteNames
; }
594 virtual void implProcessConfigItemStr(
595 TextInputStream
& rStrm
,
596 const OUString
& rKey
,
597 const OUString
& rData
) override
;
599 /** Sets the name for the passed key. */
600 virtual void implSetName( sal_Int64 nKey
, const OUString
& rName
) override
;
601 /** Returns the name for the passed key, or the default name, if key is not contained. */
602 virtual OUString
implGetName( const Config
& rCfg
, sal_Int64 nKey
) const override
;
603 /** Returns the name for the passed double value. */
604 virtual OUString
implGetNameDbl( const Config
& rCfg
, double fValue
) const override
;
605 /** Inserts all names from the passed list. */
606 virtual void implIncludeList( const NameListBase
& rList
) override
;
614 class MultiList
: public ConstList
617 explicit MultiList( const SharedConfigData
& rCfgData
);
619 void setNamesFromVec( sal_Int64 nStartKey
, const OUStringVector
& rNames
);
622 virtual void implProcessConfigItemStr(
623 TextInputStream
& rStrm
,
624 const OUString
& rKey
,
625 const OUString
& rData
) override
;
627 virtual void implSetName( sal_Int64 nKey
, const OUString
& rName
) override
;
634 class FlagsList
: public NameListBase
637 explicit FlagsList( const SharedConfigData
& rCfgData
);
639 /** Returns the flags to be ignored on output. */
640 sal_Int64
getIgnoreFlags() const { return mnIgnore
; }
641 /** Sets flags to be ignored on output. */
642 void setIgnoreFlags( sal_Int64 nIgnore
) { mnIgnore
= nIgnore
; }
645 virtual void implProcessConfigItemStr(
646 TextInputStream
& rStrm
,
647 const OUString
& rKey
,
648 const OUString
& rData
) override
;
650 /** Sets the name for the passed key. */
651 virtual void implSetName( sal_Int64 nKey
, const OUString
& rName
) override
;
652 /** Returns the name for the passed key. */
653 virtual OUString
implGetName( const Config
& rCfg
, sal_Int64 nKey
) const override
;
654 /** Returns the name for the passed double value. */
655 virtual OUString
implGetNameDbl( const Config
& rCfg
, double fValue
) const override
;
656 /** Inserts all flags from the passed list. */
657 virtual void implIncludeList( const NameListBase
& rList
) override
;
664 class CombiList
: public FlagsList
667 explicit CombiList( const SharedConfigData
& rCfgData
);
670 /** Sets the name for the passed key. */
671 virtual void implSetName( sal_Int64 nKey
, const OUString
& rName
) override
;
672 /** Returns the name for the passed key. */
673 virtual OUString
implGetName( const Config
& rCfg
, sal_Int64 nKey
) const override
;
674 /** Inserts all flags from the passed list. */
675 virtual void implIncludeList( const NameListBase
& rList
) override
;
678 struct ExtItemFormatKey
681 ::std::pair
< sal_Int64
, sal_Int64
> maFilter
;
682 explicit ExtItemFormatKey( sal_Int64 nKey
) : mnKey( nKey
), maFilter( 0, 0 ) {}
683 bool operator<( const ExtItemFormatKey
& rRight
) const;
686 struct ExtItemFormat
: public ItemFormat
689 ExtItemFormat() : mbShiftValue( true ) {}
691 typedef ::std::map
< ExtItemFormatKey
, ExtItemFormat
> ExtItemFormatMap
;
692 ExtItemFormatMap maFmtMap
;
696 class UnitConverter
: public NameListBase
699 explicit UnitConverter( const SharedConfigData
& rCfgData
);
701 void setUnitName( const String
& rUnitName
) { maUnitName
= rUnitName
; }
702 void setFactor( double fFactor
) { mfFactor
= fFactor
; }
705 /** Sets the name for the passed key. */
706 virtual void implSetName( sal_Int64 nKey
, const OUString
& rName
) override
;
707 /** Returns the converted value with appended unit name. */
708 virtual OUString
implGetName( const Config
& rCfg
, sal_Int64 nKey
) const override
;
709 /** Returns the converted value with appended unit name. */
710 virtual OUString
implGetNameDbl( const Config
& rCfg
, double fValue
) const override
;
711 /** Empty implementation. */
712 virtual void implIncludeList( const NameListBase
& rList
) override
;
720 class NameListWrapper
724 /*implicit*/ NameListWrapper( const OUString
& rListName
) : maName( rListName
) {}
725 /*implicit*/ NameListWrapper( const char* pcListName
) : maName( pcListName
) {}
726 /*implicit*/ NameListWrapper( NameListRef xList
) : mxList(std::move( xList
)) {}
728 bool isEmpty() const { return !mxList
&& !maName
.has(); }
729 const NameListRef
& getNameList( const Config
& rCfg
) const;
733 mutable NameListRef mxList
;
736 const NameListWrapper NO_LIST
;
742 ::std::map
< sal_Int64
, ItemFormat
> maMap
;
746 explicit ItemFormatMap( const NameListRef
& rxNameList
) { insertFormats( rxNameList
); }
748 ::std::map
< sal_Int64
, ItemFormat
>::const_iterator
end() const { return maMap
.end(); }
749 ::std::map
< sal_Int64
, ItemFormat
>::const_iterator
find(sal_Int64 nId
) const
751 return maMap
.find(nId
);
754 void insertFormats( const NameListRef
& rxNameList
);
758 class SharedConfigData
: public Base
, public ConfigItemBase
761 explicit SharedConfigData(
762 const OUString
& rFileName
,
763 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
764 StorageRef xRootStrg
,
765 OUString aSysFileName
);
767 virtual ~SharedConfigData() override
;
769 const css::uno::Reference
< css::uno::XComponentContext
>& getContext() const { return mxContext
; }
770 const StorageRef
& getRootStorage() const { return mxRootStrg
; }
771 const OUString
& getSysFileName() const { return maSysFileName
; }
773 const OUString
* getOption( const OUString
& rKey
) const;
775 template< typename ListType
>
776 std::shared_ptr
< ListType
> createNameList( const OUString
& rListName
);
777 void setNameList( const OUString
& rListName
, const NameListRef
& rxList
);
778 void eraseNameList( const OUString
& rListName
);
779 NameListRef
getNameList( const OUString
& rListName
) const;
782 virtual bool implIsValid() const override
;
783 virtual void implProcessConfigItemStr(
784 TextInputStream
& rStrm
,
785 const OUString
& rKey
,
786 const OUString
& rData
) override
;
789 bool readConfigFile( const OUString
& rFileUrl
);
790 template< typename ListType
>
791 void readNameList( TextInputStream
& rStrm
, const OUString
& rListName
);
792 void createShortList( std::u16string_view rData
);
793 void createUnitConverter( std::u16string_view rData
);
796 typedef ::std::set
< OUString
> ConfigFileSet
;
797 typedef ::std::map
< OUString
, OUString
> ConfigDataMap
;
798 typedef ::std::map
< OUString
, NameListRef
> NameListMap
;
800 css::uno::Reference
< css::uno::XComponentContext
> mxContext
;
801 StorageRef mxRootStrg
;
802 OUString maSysFileName
;
803 ConfigFileSet maConfigFiles
;
804 ConfigDataMap maConfigData
;
805 NameListMap maNameLists
;
806 OUString maConfigPath
;
811 template< typename ListType
>
812 std::shared_ptr
< ListType
> SharedConfigData::createNameList( const OUString
& rListName
)
814 std::shared_ptr
< ListType
> xList
;
815 if( !rListName
.isEmpty() )
817 xList
= std::make_shared
<ListType
>( *this );
818 setNameList( rListName
, xList
);
823 template< typename ListType
>
824 void SharedConfigData::readNameList( TextInputStream
& rStrm
, const OUString
& rListName
)
826 NameListRef xList
= createNameList
< ListType
>( rListName
);
828 xList
->readConfigBlock( rStrm
);
832 class Config
: public Base
836 const char* pcEnvVar
,
837 const ::oox::core::FilterBase
& rFilter
);
839 const char* pcEnvVar
,
840 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
841 const StorageRef
& rxRootStrg
,
842 const OUString
& rSysFileName
);
844 virtual ~Config() override
;
846 Config(Config
const &) = default;
847 Config(Config
&&) = default;
848 Config
& operator =(Config
const &) = default;
849 Config
& operator =(Config
&&) = default;
851 const css::uno::Reference
< css::uno::XComponentContext
>& getContext() const { return mxCfgData
->getContext(); }
852 const StorageRef
& getRootStorage() const { return mxCfgData
->getRootStorage(); }
853 const OUString
& getSysFileName() const { return mxCfgData
->getSysFileName(); }
855 const OUString
& getStringOption( const String
& rKey
, const OUString
& rDefault
) const;
856 bool getBoolOption( const String
& rKey
, bool bDefault
) const;
857 template< typename Type
>
858 Type
getIntOption( const String
& rKey
, Type nDefault
) const;
860 bool isDumperEnabled() const;
861 bool isImportEnabled() const;
863 template< typename ListType
>
864 std::shared_ptr
< ListType
> createNameList( const String
& rListName
);
865 void eraseNameList( const String
& rListName
);
866 NameListRef
getNameList( const String
& rListName
) const;
868 /** Returns the name for the passed key from the passed name list. */
869 template< typename Type
>
870 OUString
getName( const NameListWrapper
& rListWrp
, Type nKey
) const;
871 /** Returns true, if the passed name list contains an entry for the passed key. */
872 template< typename Type
>
873 bool hasName( const NameListWrapper
& rListWrp
, Type nKey
) const;
878 const char* pcEnvVar
,
879 const ::oox::core::FilterBase
& rFilter
);
881 const char* pcEnvVar
,
882 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
883 const StorageRef
& rxRootStrg
,
884 const OUString
& rSysFileName
);
886 virtual bool implIsValid() const override
;
887 const OUString
* implGetOption( const OUString
& rKey
) const;
890 std::shared_ptr
< SharedConfigData
> mxCfgData
;
893 typedef std::shared_ptr
< Config
> ConfigRef
;
896 template< typename Type
>
897 Type
Config::getIntOption( const String
& rKey
, Type nDefault
) const
900 const OUString
* pData
= implGetOption( rKey
);
901 return (pData
&& StringHelper::convertStringToInt( nRawData
, *pData
)) ?
902 static_cast< Type
>( nRawData
) : nDefault
;
905 template< typename ListType
>
906 std::shared_ptr
< ListType
> Config::createNameList( const String
& rListName
)
908 return mxCfgData
->createNameList
< ListType
>( rListName
);
911 template< typename Type
>
912 OUString
Config::getName( const NameListWrapper
& rListWrp
, Type nKey
) const
914 const NameListRef
& xList
= rListWrp
.getNameList( *this );
915 return xList
? xList
->getName( *this, nKey
) : OOX_DUMP_ERR_NOMAP
;
918 template< typename Type
>
919 bool Config::hasName( const NameListWrapper
& rListWrp
, Type nKey
) const
921 const NameListRef
& xList
= rListWrp
.getNameList( *this );
922 return xList
.get() && xList
->hasName( nKey
);
926 class Output
: public Base
930 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
931 const OUString
& rFileName
);
935 void emptyLine( size_t nCount
= 1 );
940 void startTable( sal_Int32 nW1
);
941 void startTable( sal_Int32 nW1
, sal_Int32 nW2
);
942 void startTable( sal_Int32 nW1
, sal_Int32 nW2
, sal_Int32 nW3
, sal_Int32 nW4
);
943 void startTable( size_t nColCount
, const sal_Int32
* pnColWidths
);
945 void tab( size_t nCol
);
948 void resetItemIndex( sal_Int64 nIdx
= 0 );
949 void startItem( const String
& rItemName
);
953 void startMultiItems();
954 void endMultiItems();
956 void writeChar( sal_Unicode cChar
, sal_Int32 nCount
= 1 );
957 void writeAscii( const char* pcStr
);
958 void writeString( std::u16string_view rStr
);
959 void writeArray( const sal_uInt8
* pnData
, std::size_t nSize
, sal_Unicode cSep
= OOX_DUMP_LISTSEP
);
960 void writeBool( bool bData
);
961 void writeDateTime( const css::util::DateTime
& rDateTime
);
963 template< typename Type
>
964 void writeDec( Type nData
, sal_Int32 nWidth
= 0, sal_Unicode cFill
= ' ' )
965 { StringHelper::appendDec( maLine
, nData
, nWidth
, cFill
); }
966 template< typename Type
>
967 void writeHex( Type nData
, bool bPrefix
= true )
968 { StringHelper::appendHex( maLine
, nData
, bPrefix
); }
969 template< typename Type
>
970 void writeShortHex( Type nData
, bool bPrefix
= true )
971 { StringHelper::appendShortHex( maLine
, nData
, bPrefix
); }
972 template< typename Type
>
973 void writeBin( Type nData
, bool bDots
= true )
974 { StringHelper::appendBin( maLine
, nData
, bDots
); }
975 template< typename Type
>
976 void writeFix( Type nData
, sal_Int32 nWidth
)
977 { StringHelper::appendFix( maLine
, nData
, nWidth
); }
978 template< typename Type
>
979 void writeValue( Type nData
, FormatType eFmtType
)
980 { StringHelper::appendValue( maLine
, nData
, eFmtType
); }
981 template< typename Type
>
982 void writeName( const Config
& rCfg
, Type nData
, const NameListWrapper
& rListWrp
)
983 { writeString( rCfg
.getName( rListWrp
, nData
) ); }
987 virtual bool implIsValid() const override
;
990 void writeItemName( const String
& rItemName
);
993 css::uno::Reference
< css::io::XTextOutputStream2
> mxStrm
;
995 OUStringBuffer maLine
;
997 ::std::vector
< sal_Int32
>
1001 size_t mnMultiLevel
;
1002 sal_Int64 mnItemIdx
;
1003 sal_Int32 mnLastItem
;
1006 typedef std::shared_ptr
< Output
> OutputRef
;
1012 explicit IndentGuard( const OutputRef
& rxOut
) : mrOut( *rxOut
) { mrOut
.incIndent(); }
1013 ~IndentGuard() { mrOut
.decIndent(); }
1015 IndentGuard( const IndentGuard
& ) = delete;
1016 IndentGuard
& operator=( const IndentGuard
& ) = delete;
1025 explicit TableGuard( const OutputRef
& rxOut
, sal_Int32 nW1
) :
1026 mrOut( *rxOut
) { mrOut
.startTable( nW1
); }
1027 explicit TableGuard( const OutputRef
& rxOut
, sal_Int32 nW1
, sal_Int32 nW2
) :
1028 mrOut( *rxOut
) { mrOut
.startTable( nW1
, nW2
); }
1029 explicit TableGuard( const OutputRef
& rxOut
, sal_Int32 nW1
, sal_Int32 nW2
, sal_Int32 nW3
, sal_Int32 nW4
) :
1030 mrOut( *rxOut
) { mrOut
.startTable( nW1
, nW2
, nW3
, nW4
); }
1031 explicit TableGuard( const OutputRef
& rxOut
, size_t nColCount
,
1032 const sal_Int32
* pnColWidths
) :
1033 mrOut( *rxOut
) { mrOut
.startTable( nColCount
, pnColWidths
); }
1034 ~TableGuard() { mrOut
.endTable(); }
1035 void tab( size_t nCol
) { mrOut
.tab( nCol
); }
1037 TableGuard( const TableGuard
& ) = delete;
1038 TableGuard
& operator=( const TableGuard
& ) = delete;
1047 explicit ItemGuard( const OutputRef
& rxOut
, const String
& rName
) :
1048 mrOut( *rxOut
) { mrOut
.startItem( rName
); }
1049 ~ItemGuard() { mrOut
.endItem(); }
1050 void cont() { mrOut
.contItem(); }
1052 ItemGuard( const ItemGuard
& ) = delete;
1053 ItemGuard
& operator=( const ItemGuard
& ) = delete;
1059 class MultiItemsGuard
1062 explicit MultiItemsGuard( const OutputRef
& rxOut
) : mrOut( *rxOut
) { mrOut
.startMultiItems(); }
1063 ~MultiItemsGuard() { mrOut
.endMultiItems(); }
1065 MultiItemsGuard( const MultiItemsGuard
& ) = delete;
1066 MultiItemsGuard
& operator=( const MultiItemsGuard
& ) = delete;
1072 class StorageIterator
: public Base
1075 explicit StorageIterator( StorageRef xStrg
);
1076 virtual ~StorageIterator() override
;
1078 StorageIterator
& operator++();
1080 OUString
getName() const;
1081 bool isStream() const;
1082 bool isStorage() const;
1085 virtual bool implIsValid() const override
;
1089 OUStringVector maNames
;
1090 OUStringVector::const_iterator maIt
;
1094 class ObjectBase
: public Base
1097 virtual ~ObjectBase() override
;
1099 ObjectBase(ObjectBase
const &) = default;
1100 ObjectBase(ObjectBase
&&) = default;
1101 ObjectBase
& operator =(ObjectBase
const &) = default;
1102 ObjectBase
& operator =(ObjectBase
&&) = default;
1104 const css::uno::Reference
< css::uno::XComponentContext
>&
1105 getContext() const { return mxConfig
->getContext(); }
1113 void construct( const ConfigRef
& rxConfig
);
1114 void construct( const ObjectBase
& rParent
);
1116 virtual bool implIsValid() const override
;
1117 virtual void implDump();
1120 Config
& cfg() const { return *mxConfig
; }
1126 typedef std::shared_ptr
< ObjectBase
> ObjectRef
;
1129 class StorageObjectBase
: public ObjectBase
1132 StorageObjectBase() {}
1135 using ObjectBase::construct
;
1136 void construct( const ObjectBase
& rParent
, const StorageRef
& rxStrg
, const OUString
& rSysPath
);
1137 void construct( const ObjectBase
& rParent
);
1139 virtual bool implIsValid() const override
;
1140 virtual void implDump() override
;
1142 virtual void implDumpStream(
1143 const css::uno::Reference
< css::io::XInputStream
>& rxStrm
,
1144 const OUString
& rStrgPath
,
1145 const OUString
& rStrmName
,
1146 const OUString
& rSysFileName
);
1148 virtual void implDumpStorage(
1149 const StorageRef
& rxStrg
,
1150 const OUString
& rStrgPath
,
1151 const OUString
& rSysPath
);
1153 virtual void implDumpBaseStream(
1154 const BinaryInputStreamRef
& rxStrm
,
1155 const OUString
& rSysFileName
);
1157 void addPreferredStream( const String
& rStrmName
);
1158 void addPreferredStorage( const String
& rStrgPath
);
1161 static OUString
getSysFileName(
1162 std::u16string_view rStrmName
,
1163 std::u16string_view rSysOutPath
);
1167 const OUString
& rStrgPath
,
1168 const OUString
& rStrmName
,
1169 const OUString
& rSysFileName
);
1170 void extractStorage(
1171 const StorageRef
& rxStrg
,
1172 const OUString
& rStrgPath
,
1173 const OUString
& rSysPath
);
1176 const StorageRef
& rxStrg
,
1177 const OUString
& rStrgPath
,
1178 const OUString
& rItemName
,
1179 std::u16string_view rSysPath
,
1180 bool bIsStrg
, bool bIsStrm
);
1183 struct PreferredItem
1188 explicit PreferredItem( OUString aName
, bool bStorage
) :
1189 maName(std::move( aName
)), mbStorage( bStorage
) {}
1191 typedef ::std::vector
< PreferredItem
> PreferredItemVector
;
1195 PreferredItemVector maPreferred
;
1199 class OutputObjectBase
: public ObjectBase
1202 virtual ~OutputObjectBase() override
;
1204 OutputObjectBase(OutputObjectBase
const &) = default;
1205 OutputObjectBase(OutputObjectBase
&&) = default;
1206 OutputObjectBase
& operator =(OutputObjectBase
const &) = default;
1207 OutputObjectBase
& operator =(OutputObjectBase
&&) = default;
1210 OutputObjectBase() {}
1212 using ObjectBase::construct
;
1213 void construct( const ObjectBase
& rParent
, const OUString
& rSysFileName
);
1214 void construct( const OutputObjectBase
& rParent
);
1216 virtual bool implIsValid() const override
;
1219 void writeEmptyItem( const String
& rName
);
1220 void writeInfoItem( const String
& rName
, const String
& rData
);
1221 void writeCharItem( const String
& rName
, sal_Unicode cData
);
1222 void writeStringItem( const String
& rName
, std::u16string_view rData
);
1223 void writeArrayItem( const String
& rName
, const sal_uInt8
* pnData
, std::size_t nSize
, sal_Unicode cSep
= OOX_DUMP_LISTSEP
);
1224 void writeDateTimeItem( const String
& rName
, const css::util::DateTime
& rDateTime
);
1225 void writeGuidItem( const String
& rName
, const OUString
& rGuid
);
1227 template< typename Type
>
1228 void addNameToItem( Type nData
, const NameListWrapper
& rListWrp
);
1230 template< typename Type
>
1231 void writeNameItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
);
1232 template< typename Type
>
1233 void writeDecItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
= NO_LIST
);
1234 template< typename Type
>
1235 void writeHexItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
= NO_LIST
);
1236 template< typename Type
>
1237 void writeShortHexItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
= NO_LIST
);
1238 template< typename Type
>
1239 void writeBinItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
= NO_LIST
);
1240 template< typename Type
>
1241 void writeFixItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
= NO_LIST
);
1242 template< typename Type
>
1243 void writeDecBoolItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
= NO_LIST
);
1244 template< typename Type
>
1245 void writeValueItem( const String
& rName
, Type nData
, FormatType eFmtType
, const NameListWrapper
& rListWrp
= NO_LIST
);
1247 template< typename Type
>
1248 void writeValueItem( const ItemFormat
& rItemFmt
, Type nData
);
1250 template< typename Type
>
1251 void writeDecPairItem( const String
& rName
, Type nData1
, Type nData2
, sal_Unicode cSep
= ',' );
1252 template< typename Type
>
1253 void writeHexPairItem( const String
& rName
, Type nData1
, Type nData2
, sal_Unicode cSep
= ',' );
1257 OUString maSysFileName
;
1261 template< typename Type
>
1262 void OutputObjectBase::addNameToItem( Type nData
, const NameListWrapper
& rListWrp
)
1264 if( !rListWrp
.isEmpty() )
1267 mxOut
->writeName( cfg(), nData
, rListWrp
);
1271 template< typename Type
>
1272 void OutputObjectBase::writeNameItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
)
1274 ItemGuard
aItem( mxOut
, rName
);
1275 mxOut
->writeName( cfg(), nData
, rListWrp
);
1278 template< typename Type
>
1279 void OutputObjectBase::writeDecItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
)
1281 ItemGuard
aItem( mxOut
, rName
);
1282 mxOut
->writeDec( nData
);
1283 addNameToItem( nData
, rListWrp
);
1286 template< typename Type
>
1287 void OutputObjectBase::writeHexItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
)
1289 ItemGuard
aItem( mxOut
, rName
);
1290 mxOut
->writeHex( nData
);
1291 addNameToItem( nData
, rListWrp
);
1294 template< typename Type
>
1295 void OutputObjectBase::writeShortHexItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
)
1297 ItemGuard
aItem( mxOut
, rName
);
1298 mxOut
->writeShortHex( nData
);
1299 addNameToItem( nData
, rListWrp
);
1302 template< typename Type
>
1303 void OutputObjectBase::writeBinItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
)
1305 ItemGuard
aItem( mxOut
, rName
);
1306 mxOut
->writeBin( nData
);
1307 addNameToItem( nData
, rListWrp
);
1310 template< typename Type
>
1311 void OutputObjectBase::writeFixItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
)
1313 ItemGuard
aItem( mxOut
, rName
);
1314 mxOut
->writeFix( nData
);
1315 addNameToItem( nData
, rListWrp
);
1318 template< typename Type
>
1319 void OutputObjectBase::writeDecBoolItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
)
1321 ItemGuard
aItem( mxOut
, rName
);
1322 mxOut
->writeDec( nData
);
1324 mxOut
->writeBool( nData
!= 0 );
1325 addNameToItem( nData
, rListWrp
);
1328 template< typename Type
>
1329 void OutputObjectBase::writeValueItem( const String
& rName
, Type nData
, FormatType eFmtType
, const NameListWrapper
& rListWrp
)
1331 if( eFmtType
== FORMATTYPE_BOOL
)
1332 writeDecBoolItem( rName
, nData
, rListWrp
);
1335 ItemGuard
aItem( mxOut
, rName
);
1336 mxOut
->writeValue( nData
, eFmtType
);
1337 addNameToItem( nData
, rListWrp
);
1341 template< typename Type
>
1342 void OutputObjectBase::writeValueItem( const ItemFormat
& rItemFmt
, Type nData
)
1344 OString aNameUtf8
= StringHelper::convertToUtf8( rItemFmt
.maItemName
);
1345 writeValueItem( aNameUtf8
.getStr(), nData
, rItemFmt
.meFmtType
, rItemFmt
.maListName
);
1348 template< typename Type
>
1349 void OutputObjectBase::writeDecPairItem( const String
& rName
, Type nData1
, Type nData2
, sal_Unicode cSep
)
1351 ItemGuard
aItem( mxOut
, rName
);
1352 mxOut
->writeDec( nData1
);
1353 mxOut
->writeChar( cSep
);
1354 mxOut
->writeDec( nData2
);
1357 template< typename Type
>
1358 void OutputObjectBase::writeHexPairItem( const String
& rName
, Type nData1
, Type nData2
, sal_Unicode cSep
)
1360 ItemGuard
aItem( mxOut
, rName
);
1361 mxOut
->writeHex( nData1
);
1362 mxOut
->writeChar( cSep
);
1363 mxOut
->writeHex( nData2
);
1367 class InputObjectBase
: public OutputObjectBase
1370 virtual ~InputObjectBase() override
;
1372 InputObjectBase(InputObjectBase
const &) = default;
1373 InputObjectBase(InputObjectBase
&&) = default;
1374 InputObjectBase
& operator =(InputObjectBase
const &) = default;
1375 InputObjectBase
& operator =(InputObjectBase
&&) = default;
1378 InputObjectBase() {}
1380 using OutputObjectBase::construct
;
1381 void construct( const ObjectBase
& rParent
, const BinaryInputStreamRef
& rxStrm
, const OUString
& rSysFileName
);
1382 void construct( const OutputObjectBase
& rParent
, const BinaryInputStreamRef
& rxStrm
);
1383 void construct( const InputObjectBase
& rParent
);
1385 virtual bool implIsValid() const override
;
1387 void skipBlock( sal_Int64 nBytes
, bool bShowSize
= true );
1388 void dumpRawBinary( sal_Int64 nBytes
, bool bShowOffset
, bool bStream
= false );
1390 void dumpBinary( const String
& rName
, sal_Int64 nBytes
, bool bShowOffset
= true );
1391 void dumpRemaining( sal_Int64 nBytes
);
1392 void dumpRemainingTo( sal_Int64 nPos
);
1393 void dumpRemainingStream();
1395 void dumpArray( const String
& rName
, sal_Int32 nBytes
, sal_Unicode cSep
= OOX_DUMP_LISTSEP
);
1396 void dumpUnused( sal_Int32 nBytes
) { dumpArray( OOX_DUMP_UNUSED
, nBytes
); }
1397 void dumpUnknown( sal_Int32 nBytes
) { dumpArray( OOX_DUMP_UNKNOWN
, nBytes
); }
1399 sal_Unicode
dumpUnicode( const String
& rName
);
1401 OUString
dumpCharArray( const String
& rName
, sal_Int32 nLen
, rtl_TextEncoding eTextEnc
, bool bHideTrailingNul
= false );
1402 OUString
dumpUnicodeArray( const String
& rName
, sal_Int32 nLen
, bool bHideTrailingNul
= false );
1404 css::util::DateTime
dumpFileTime( const String
& rName
= EMPTY_STRING
);
1405 OUString
dumpGuid( const String
& rName
= EMPTY_STRING
);
1407 void dumpItem( const ItemFormat
& rItemFmt
);
1409 template< typename Type
>
1410 Type
dumpName( const String
& rName
, const NameListWrapper
& rListWrp
);
1411 template< typename Type
>
1412 Type
dumpDec( const String
& rName
, const NameListWrapper
& rListWrp
= NO_LIST
);
1413 template< typename Type
>
1414 Type
dumpHex( const String
& rName
, const NameListWrapper
& rListWrp
= NO_LIST
);
1415 template< typename Type
>
1416 Type
dumpBin( const String
& rName
, const NameListWrapper
& rListWrp
= NO_LIST
);
1417 template< typename Type
>
1418 Type
dumpFix( const String
& rName
, const NameListWrapper
& rListWrp
= NO_LIST
);
1419 template< typename Type
>
1420 Type
dumpBool( const String
& rName
, const NameListWrapper
& rListWrp
= NO_LIST
);
1421 template< typename Type
>
1422 Type
dumpValue( const ItemFormat
& rItemFmt
);
1424 template< typename Type1
, typename Type2
>
1425 Type1
dumpName( bool bType1
, const String
& rName
, const NameListWrapper
& rListWrp
= NO_LIST
);
1426 template< typename Type1
, typename Type2
>
1427 Type1
dumpDec( bool bType1
, const String
& rName
, const NameListWrapper
& rListWrp
= NO_LIST
);
1428 template< typename Type1
, typename Type2
>
1429 Type1
dumpHex( bool bType1
, const String
& rName
, const NameListWrapper
& rListWrp
= NO_LIST
);
1430 template< typename Type1
, typename Type2
>
1431 Type1
dumpBin( bool bType1
, const String
& rName
, const NameListWrapper
& rListWrp
= NO_LIST
);
1432 template< typename Type1
, typename Type2
>
1433 Type1
dumpFix( bool bType1
, const String
& rName
, const NameListWrapper
& rListWrp
= NO_LIST
);
1434 template< typename Type1
, typename Type2
>
1435 Type1
dumpBool( bool bType1
, const String
& rName
, const NameListWrapper
& rListWrp
= NO_LIST
);
1436 template< typename Type1
, typename Type2
>
1437 Type1
dumpValue( bool bType1
, const ItemFormat
& rItemFmt
);
1439 template< typename Type
>
1440 void dumpDecPair( const String
& rName
, sal_Unicode cSep
= ',' );
1441 template< typename Type
>
1442 void dumpHexPair( const String
& rName
, sal_Unicode cSep
= ',' );
1445 BinaryInputStreamRef mxStrm
;
1449 template< typename Type
>
1450 Type
InputObjectBase::dumpName( const String
& rName
, const NameListWrapper
& rListWrp
)
1452 Type nData
= mxStrm
->readValue
<Type
>();
1453 writeNameItem( rName
, nData
, rListWrp
);
1457 template< typename Type
>
1458 Type
InputObjectBase::dumpDec( const String
& rName
, const NameListWrapper
& rListWrp
)
1460 Type nData
= mxStrm
->readValue
<Type
>();
1461 writeDecItem( rName
, nData
, rListWrp
);
1465 template< typename Type
>
1466 Type
InputObjectBase::dumpHex( const String
& rName
, const NameListWrapper
& rListWrp
)
1468 Type nData
= mxStrm
->readValue
<Type
>();
1469 writeHexItem( rName
, nData
, rListWrp
);
1473 template< typename Type
>
1474 Type
InputObjectBase::dumpBin( const String
& rName
, const NameListWrapper
& rListWrp
)
1476 Type nData
= mxStrm
->readValue
<Type
>();
1477 writeBinItem( rName
, nData
, rListWrp
);
1481 template< typename Type
>
1482 Type
InputObjectBase::dumpFix( const String
& rName
, const NameListWrapper
& rListWrp
)
1484 Type nData
= mxStrm
->readValue
<Type
>();
1485 writeFixItem( rName
, nData
, rListWrp
);
1489 template< typename Type
>
1490 Type
InputObjectBase::dumpBool( const String
& rName
, const NameListWrapper
& rListWrp
)
1492 Type nData
= mxStrm
->readValue
<Type
>();
1493 writeDecBoolItem( rName
, nData
, rListWrp
);
1497 template< typename Type
>
1498 Type
InputObjectBase::dumpValue( const ItemFormat
& rItemFmt
)
1500 Type nData
= mxStrm
->readValue
<Type
>();
1501 writeValueItem( rItemFmt
, nData
);
1505 template< typename Type1
, typename Type2
>
1506 Type1
InputObjectBase::dumpName( bool bType1
, const String
& rName
, const NameListWrapper
& rListWrp
)
1508 return bType1
? dumpName
< Type1
>( rName
, rListWrp
) : static_cast< Type1
>( dumpName
< Type2
>( rName
, rListWrp
) );
1511 template< typename Type1
, typename Type2
>
1512 Type1
InputObjectBase::dumpDec( bool bType1
, const String
& rName
, const NameListWrapper
& rListWrp
)
1514 return bType1
? dumpDec
< Type1
>( rName
, rListWrp
) : static_cast< Type1
>( dumpDec
< Type2
>( rName
, rListWrp
) );
1517 template< typename Type1
, typename Type2
>
1518 Type1
InputObjectBase::dumpHex( bool bType1
, const String
& rName
, const NameListWrapper
& rListWrp
)
1520 return bType1
? dumpHex
< Type1
>( rName
, rListWrp
) : static_cast< Type1
>( dumpHex
< Type2
>( rName
, rListWrp
) );
1523 template< typename Type1
, typename Type2
>
1524 Type1
InputObjectBase::dumpBin( bool bType1
, const String
& rName
, const NameListWrapper
& rListWrp
)
1526 return bType1
? dumpBin
< Type1
>( rName
, rListWrp
) : static_cast< Type1
>( dumpBin
< Type2
>( rName
, rListWrp
) );
1529 template< typename Type1
, typename Type2
>
1530 Type1
InputObjectBase::dumpFix( bool bType1
, const String
& rName
, const NameListWrapper
& rListWrp
)
1532 return bType1
? dumpFix
< Type1
>( rName
, rListWrp
) : static_cast< Type1
>( dumpFix
< Type2
>( rName
, rListWrp
) );
1535 template< typename Type1
, typename Type2
>
1536 Type1
InputObjectBase::dumpBool( bool bType1
, const String
& rName
, const NameListWrapper
& rListWrp
)
1538 return bType1
? dumpBool
< Type1
>( rName
, rListWrp
) : static_cast< Type1
>( dumpBool
< Type2
>( rName
, rListWrp
) );
1541 template< typename Type1
, typename Type2
>
1542 Type1
InputObjectBase::dumpValue( bool bType1
, const ItemFormat
& rItemFmt
)
1544 return bType1
? dumpValue
< Type1
>( rItemFmt
) : static_cast< Type1
>( dumpValue
< Type2
>( rItemFmt
) );
1547 template< typename Type
>
1548 void InputObjectBase::dumpDecPair( const String
& rName
, sal_Unicode cSep
)
1550 Type nData1
, nData2
;
1551 *mxStrm
>> nData1
>> nData2
;
1552 writeDecPairItem( rName
, nData1
, nData2
, cSep
);
1555 template< typename Type
>
1556 void InputObjectBase::dumpHexPair( const String
& rName
, sal_Unicode cSep
)
1558 Type nData1
, nData2
;
1559 *mxStrm
>> nData1
>> nData2
;
1560 writeHexPairItem( rName
, nData1
, nData2
, cSep
);
1564 class BinaryStreamObject final
: public InputObjectBase
1567 explicit BinaryStreamObject(
1568 const ObjectBase
& rParent
,
1569 const BinaryInputStreamRef
& rxStrm
,
1570 const OUString
& rSysFileName
);
1573 void dumpBinaryStream( bool bShowOffset
= true );
1575 virtual void implDump() override
;
1579 class TextStreamObjectBase
: public InputObjectBase
1582 TextStreamObjectBase() {}
1584 using InputObjectBase::construct
;
1586 const ObjectBase
& rParent
,
1587 const BinaryInputStreamRef
& rxStrm
,
1588 rtl_TextEncoding eTextEnc
,
1589 const OUString
& rSysFileName
);
1591 const OutputObjectBase
& rParent
,
1592 const BinaryInputStreamRef
& rxStrm
,
1593 rtl_TextEncoding eTextEnc
);
1595 virtual bool implIsValid() const override
;
1596 virtual void implDump() override
;
1598 virtual void implDumpText( TextInputStream
& rTextStrm
) = 0;
1601 void constructTextStrmObj( rtl_TextEncoding eTextEnc
);
1603 std::shared_ptr
< TextInputStream
> mxTextStrm
;
1607 class TextLineStreamObject final
: public TextStreamObjectBase
1610 explicit TextLineStreamObject(
1611 const ObjectBase
& rParent
,
1612 const BinaryInputStreamRef
& rxStrm
,
1613 rtl_TextEncoding eTextEnc
,
1614 const OUString
& rSysFileName
);
1616 explicit TextLineStreamObject(
1617 const OutputObjectBase
& rParent
,
1618 const BinaryInputStreamRef
& rxStrm
,
1619 rtl_TextEncoding eTextEnc
);
1622 virtual void implDumpText( TextInputStream
& rTextStrm
) override
;
1623 void implDumpLine( std::u16string_view rLine
, sal_uInt32 nLine
);
1627 class XmlStreamObject
: public TextStreamObjectBase
1630 explicit XmlStreamObject(
1631 const ObjectBase
& rParent
,
1632 const BinaryInputStreamRef
& rxStrm
,
1633 const OUString
& rSysFileName
);
1636 virtual void implDumpText( TextInputStream
& rTextStrm
) override
;
1640 class RecordObjectBase
: public InputObjectBase
1643 RecordObjectBase() {}
1645 using InputObjectBase::construct
;
1647 const ObjectBase
& rParent
,
1648 const BinaryInputStreamRef
& rxBaseStrm
,
1649 const OUString
& rSysFileName
,
1650 const BinaryInputStreamRef
& rxRecStrm
,
1651 const String
& rRecNames
,
1652 const String
& rSimpleRecs
);
1654 sal_Int64
getRecId() const { return mnRecId
; }
1655 sal_Int64
getRecSize() const { return mnRecSize
; }
1657 virtual bool implIsValid() const override
;
1658 virtual void implDump() override
;
1660 virtual bool implStartRecord( BinaryInputStream
& rBaseStrm
, sal_Int64
& ornRecPos
, sal_Int64
& ornRecId
, sal_Int64
& ornRecSize
) = 0;
1661 virtual void implWriteExtHeader();
1662 virtual void implDumpRecordBody();
1665 void constructRecObjBase(
1666 const BinaryInputStreamRef
& rxBaseStrm
,
1667 const String
& rRecNames
,
1668 const String
& rSimpleRecs
);
1673 BinaryInputStreamRef mxBaseStrm
;
1674 NameListWrapper maRecNames
;
1675 NameListWrapper maSimpleRecs
;
1678 sal_Int64 mnRecSize
;
1684 class SequenceRecordObjectBase
: public RecordObjectBase
1687 SequenceRecordObjectBase() : mxRecData( std::make_shared
<StreamDataSequence
>() ) {}
1689 using RecordObjectBase::construct
;
1691 const ObjectBase
& rParent
,
1692 const BinaryInputStreamRef
& rxBaseStrm
,
1693 const OUString
& rSysFileName
,
1694 const String
& rRecNames
,
1695 const String
& rSimpleRecs
);
1697 virtual bool implStartRecord( BinaryInputStream
& rBaseStrm
, sal_Int64
& ornRecPos
, sal_Int64
& ornRecId
, sal_Int64
& ornRecSize
) override
;
1698 virtual bool implReadRecordHeader( BinaryInputStream
& rBaseStrm
, sal_Int64
& ornRecId
, sal_Int64
& ornRecSize
) = 0;
1701 std::shared_ptr
< StreamDataSequence
> mxRecData
;
1705 /** Base class for a file dumper. Derived classes implement the implDump()
1706 function to add functionality.
1708 class DumperBase
: public ObjectBase
1711 virtual ~DumperBase() override
;
1713 bool isImportEnabled() const;
1718 using ObjectBase::construct
;
1719 void construct( const ConfigRef
& rxConfig
);
1723 } // namespace oox::dump
1725 #define OOX_DUMP_FILE( DumperClassName ) \
1727 DumperClassName aDumper( *this ); \
1729 if( !aDumper.isImportEnabled() ) \
1730 return aDumper.isValid(); \
1735 #define OOX_DUMP_FILE( DumperClassName ) (void)0
1740 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */