bump product version to 6.3.0.0.beta1
[LibreOffice.git] / include / sax / fshelper.hxx
blob7876e48a6c6c50cbe345e1a1f1c992d1d3c81121
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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_SAX_FSHELPER_HXX
21 #define INCLUDED_SAX_FSHELPER_HXX
23 #include <com/sun/star/xml/sax/XFastAttributeList.hpp>
24 #include <com/sun/star/uno/Reference.hxx>
25 #include <com/sun/star/uno/Sequence.hxx>
26 #include <sax/saxdllapi.h>
27 #include <memory>
28 #include <utility>
30 namespace com { namespace sun { namespace star { namespace io { class XOutputStream; } } } }
31 namespace sax_fastparser { class FastAttributeList; }
33 #define FSNS(namespc, element) ((namespc << 16) | element)
35 namespace sax_fastparser {
37 enum class MergeMarks { APPEND = 0, PREPEND = 1, POSTPONE = 2};
39 typedef css::uno::Reference< css::xml::sax::XFastAttributeList > XFastAttributeListRef;
41 class FastSaxSerializer;
43 class SAX_DLLPUBLIC FastSerializerHelper
45 public:
47 FastSerializerHelper( const css::uno::Reference< css::io::XOutputStream >& xOutputStream, bool bWriteHeader );
49 ~FastSerializerHelper();
51 /// Start an element. After the first argument there can be a number of (attribute, value) pairs.
52 template<typename... Args>
53 void startElement(sal_Int32 elementTokenId, sal_Int32 attribute, const char* value, Args &&... args)
55 if (value)
56 pushAttributeValue(attribute, value);
57 startElement(elementTokenId, std::forward<Args>(args)...);
59 template<typename... Args>
60 void startElement(sal_Int32 elementTokenId, sal_Int32 attribute, const OString& value, Args &&... args)
62 pushAttributeValue(attribute, value);
63 startElement(elementTokenId, std::forward<Args>(args)...);
65 void startElement(sal_Int32 elementTokenId);
67 /// Start an element. After the first two arguments there can be a number of (attribute, value) pairs.
68 template<typename... Args>
69 void startElementNS(sal_Int32 namespaceTokenId, sal_Int32 elementTokenId, sal_Int32 attribute, const char* value, Args &&... args)
71 if (value)
72 pushAttributeValue(attribute, value);
73 startElementNS(namespaceTokenId, elementTokenId, std::forward<Args>(args)...);
75 template<typename... Args>
76 void startElementNS(sal_Int32 namespaceTokenId, sal_Int32 elementTokenId, sal_Int32 attribute, const OString& value, Args &&... args)
78 pushAttributeValue(attribute, value);
79 startElementNS(namespaceTokenId, elementTokenId, std::forward<Args>(args)...);
81 void startElementNS(sal_Int32 namespaceTokenId, sal_Int32 elementTokenId)
83 startElement(FSNS(namespaceTokenId, elementTokenId));
86 /// Create a single element. After the first argument there can be a number of (attribute, value) pairs.
87 template<typename... Args>
88 void singleElement(sal_Int32 elementTokenId, sal_Int32 attribute, const char* value, Args &&... args)
90 if (value)
91 pushAttributeValue(attribute, value);
92 singleElement(elementTokenId, std::forward<Args>(args)...);
94 template<typename... Args>
95 void singleElement(sal_Int32 elementTokenId, sal_Int32 attribute, const OString& value, Args &&... args)
97 pushAttributeValue(attribute, value);
98 singleElement(elementTokenId, std::forward<Args>(args)...);
100 void singleElement(sal_Int32 elementTokenId);
102 /// Create a single element. After the first two arguments there can be a number of (attribute, value) pairs.
103 template<typename... Args>
104 void singleElementNS(sal_Int32 namespaceTokenId, sal_Int32 elementTokenId, sal_Int32 attribute, const char* value, Args &&... args)
106 if (value)
107 pushAttributeValue(attribute, value);
108 singleElementNS(namespaceTokenId, elementTokenId, std::forward<Args>(args)...);
110 template<typename... Args>
111 void singleElementNS(sal_Int32 namespaceTokenId, sal_Int32 elementTokenId, sal_Int32 attribute, const OString& value, Args &&... args)
113 pushAttributeValue(attribute, value);
114 singleElementNS(namespaceTokenId, elementTokenId, std::forward<Args>(args)...);
116 void singleElementNS(sal_Int32 namespaceTokenId, sal_Int32 elementTokenId)
118 singleElement(FSNS(namespaceTokenId, elementTokenId));
121 void endElement(sal_Int32 elementTokenId);
122 void endElementNS(sal_Int32 namespaceTokenId, sal_Int32 elementTokenId)
123 { endElement( FSNS( namespaceTokenId, elementTokenId ) ); }
125 void singleElement(sal_Int32 elementTokenId, const XFastAttributeListRef& xAttrList);
126 void singleElementNS(sal_Int32 namespaceTokenId, sal_Int32 elementTokenId, XFastAttributeListRef const & xAttrList)
127 { singleElement(FSNS( namespaceTokenId, elementTokenId), xAttrList); }
129 void startElement(sal_Int32 elementTokenId, const XFastAttributeListRef& xAttrList);
130 void startElementNS(sal_Int32 namespaceTokenId, sal_Int32 elementTokenId, XFastAttributeListRef const & xAttrList)
131 { startElement( FSNS( namespaceTokenId, elementTokenId ), xAttrList ); }
133 FastSerializerHelper* write(const char* value);
134 FastSerializerHelper* write(const OUString& value);
135 FastSerializerHelper* write(sal_Int32 value);
136 FastSerializerHelper* write(sal_Int64 value);
137 FastSerializerHelper* write(double value);
139 FastSerializerHelper* writeEscaped(const char* value);
140 FastSerializerHelper* writeEscaped(const OUString& value);
142 FastSerializerHelper* writeId(sal_Int32 tokenId);
144 css::uno::Reference< css::io::XOutputStream > const & getOutputStream() const;
146 static FastAttributeList *createAttrList();
148 void mark(sal_Int32 nTag,
149 const css::uno::Sequence< sal_Int32 >& rOrder =
150 css::uno::Sequence< sal_Int32 >() );
151 void mergeTopMarks(sal_Int32 nTag,
152 MergeMarks eMergeType = MergeMarks::APPEND );
154 private:
155 void pushAttributeValue( sal_Int32 attribute, const char* value );
156 void pushAttributeValue( sal_Int32 attribute, const OString& value );
158 FastSaxSerializer* mpSerializer;
161 typedef std::shared_ptr< FastSerializerHelper > FSHelperPtr;
165 #endif // INCLUDED_SAX_FSHELPER_HXX
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */