/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ #ifndef INCLUDED_SAX_FSHELPER_HXX #define INCLUDED_SAX_FSHELPER_HXX #include #include #include #include #include #include #include #include #include #include namespace com::sun::star::io { class XOutputStream; } namespace sax_fastparser { class FastAttributeList; } constexpr sal_Int32 FSNS(sal_Int32 namespc, sal_Int32 element) { return (namespc << 16) | element; } namespace sax_fastparser { enum class MergeMarks { APPEND = 0, PREPEND = 1, POSTPONE = 2}; class FastSaxSerializer; class SAX_DLLPUBLIC FastSerializerHelper { public: FastSerializerHelper( const css::uno::Reference< css::io::XOutputStream >& xOutputStream, bool bWriteHeader ); ~FastSerializerHelper(); /// Start an element. After the first argument there can be a number of (attribute, value) pairs. template void startElement(sal_Int32 elementTokenId, sal_Int32 attribute, const char* value, Args &&... args) { if (value) pushAttributeValue(attribute, value); startElement(elementTokenId, std::forward(args)...); } template void startElement(sal_Int32 elementTokenId, sal_Int32 attribute, const std::optional& value, Args&&... args) { if (value) pushAttributeValue(attribute, *value); startElement(elementTokenId, std::forward(args)...); } template void startElement(sal_Int32 elementTokenId, sal_Int32 attribute, const std::optional& value, Args&&... args) { std::optional opt; if (value) opt = value->toUtf8(); startElement(elementTokenId, attribute, opt, std::forward(args)...); } void startElement(sal_Int32 elementTokenId); /// Start an element. After the first two arguments there can be a number of (attribute, value) pairs. template void startElementNS(sal_Int32 namespaceTokenId, sal_Int32 elementTokenId, Args &&... args) { startElement(FSNS(namespaceTokenId, elementTokenId), std::forward(args)...); } /// Create a single element. After the first argument there can be a number of (attribute, value) pairs. template void singleElement(sal_Int32 elementTokenId, sal_Int32 attribute, const char* value, Args &&... args) { if (value) pushAttributeValue(attribute, value); singleElement(elementTokenId, std::forward(args)...); } template void singleElement(sal_Int32 elementTokenId, sal_Int32 attribute, const std::optional& value, Args&&... args) { if (value) pushAttributeValue(attribute, *value); singleElement(elementTokenId, std::forward(args)...); } template void singleElement(sal_Int32 elementTokenId, sal_Int32 attribute, const std::optional& value, Args&&... args) { std::optional opt; if (value) opt = value->toUtf8(); singleElement(elementTokenId, attribute, opt, std::forward(args)...); } void singleElement(sal_Int32 elementTokenId); /// Create a single element. After the first two arguments there can be a number of (attribute, value) pairs. template void singleElementNS(sal_Int32 namespaceTokenId, sal_Int32 elementTokenId, Args &&... args) { singleElement(FSNS(namespaceTokenId, elementTokenId), std::forward(args)...); } void endElement(sal_Int32 elementTokenId); void endElementNS(sal_Int32 namespaceTokenId, sal_Int32 elementTokenId) { endElement( FSNS( namespaceTokenId, elementTokenId ) ); } void singleElement(sal_Int32 elementTokenId, const rtl::Reference& xAttrList); void singleElementNS(sal_Int32 namespaceTokenId, sal_Int32 elementTokenId, rtl::Reference const & xAttrList) { singleElement(FSNS( namespaceTokenId, elementTokenId), xAttrList); } void startElement(sal_Int32 elementTokenId, const rtl::Reference& xAttrList); void startElementNS(sal_Int32 namespaceTokenId, sal_Int32 elementTokenId, rtl::Reference const & xAttrList) { startElement( FSNS( namespaceTokenId, elementTokenId ), xAttrList ); } FastSerializerHelper* write(const char* value); FastSerializerHelper* write(const OString& value); FastSerializerHelper* write(std::u16string_view value); FastSerializerHelper* write(sal_Int32 value); FastSerializerHelper* write(sal_Int64 value); FastSerializerHelper* write(double value); FastSerializerHelper* writeEscaped(const char* value); FastSerializerHelper* writeEscaped(std::u16string_view value); FastSerializerHelper* writeId(sal_Int32 tokenId); css::uno::Reference< css::io::XOutputStream > const & getOutputStream() const; static rtl::Reference createAttrList(); void mark(sal_Int32 nTag, const css::uno::Sequence< sal_Int32 >& rOrder = css::uno::Sequence< sal_Int32 >() ); void mergeTopMarks(sal_Int32 nTag, MergeMarks eMergeType = MergeMarks::APPEND ); private: void pushAttributeValue( sal_Int32 attribute, const char* value ); void pushAttributeValue( sal_Int32 attribute, const OString& value ); FastSaxSerializer* mpSerializer; }; typedef std::shared_ptr< FastSerializerHelper > FSHelperPtr; // Helpers to make intention to pass optional attributes to *Element functions explicit, instead of // using `(condition) ? value.toUtf8().getStr() : nullptr` syntax. inline const char* UseIf(const char* s, bool bUse) { return bUse ? s : nullptr; } // OString, OUString template std::optional UseIf(const TString& s, bool bUse) { return bUse ? std::optional(s) : std::optional(); } } #endif // INCLUDED_SAX_FSHELPER_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ '>distro/lhm/libreoffice-7-6+backports LibreOffice 核心代码仓库文档基金会
summaryrefslogtreecommitdiff
AgeCommit message (Expand)Author
2016-07-28Add various uui dependencyGiuseppe Castagno
2016-06-09tdf#94698 cleanup Makefiles. Get rid of udkapi and offapiGleb Mishchenko
2015-02-27gbuild: CppunitTest: always use unittest configurationMichael Stahl
2014-11-23Remaining fixes for sc.subsequentcheckMiklos Vajna
2014-10-22Replace DISABLE_SCRIPTING with HAVE_FEATURE_SCRIPTINGTor Lillqvist
2014-06-26sort libraries and components in sc test makefilesMarkus Mohrhard
2014-06-04DeInitVCL at end of testsStephan Bergmann
2014-05-04sc: Fix bunch of testsMaxim Monastirsky
2014-04-18Try making it possible to use --disable-avmedia for desktop platforms tooTor Lillqvist
2013-12-11fdo#60698: Merge fastsax and sax_shared into expwrapMarcos Paulo de Souza
2013-10-18fdo#60698: Move fileaccess module to ucbMarcos Paulo de Souza
2013-10-01gbuild: use .xcd configuration files from instdirMatúš Kukan
2013-04-22Move to MPLv2 license headers, with ESC decision and author's permission.Michael Meeks
2013-04-05new module i18nlangtagEike Rathke
2013-03-07fdo#46808 use document::DocumentRevisionListPersistence constructorNoel Grandin
2013-01-26gbuild: do not copy boost headers aroundMichael Stahl
2012-10-01No vbaobj component if DISABLE_SCRIPTINGTor Lillqvist
2012-09-28gbuild: invert handling of standard system libraries:Michael Stahl
2012-09-28gbuild: replace direct gb_STDLIBS use with ...Michael Stahl
2012-09-28gbuild: split uwinapi out of gb_STDLIBSMichael Stahl
2012-08-21add more runtime deps on resource files for unit-testsMatúš Kukan
2012-08-10gbuild: missing dep on $(OUTDIR)/unittest/registry for testsMatúš Kukan
2012-04-12move dependency on localedata_en to i18npoolMatúš Kukan
2012-04-08rename gb_CppunitTest_uses_ureDavid Tardon
2012-04-08compile- and run-time use of UNO must be splitDavid Tardon
2012-04-08clean upDavid Tardon
2012-04-08simplify use of configuration from unit testsDavid Tardon
2012-04-08always use --protector for UNO testsDavid Tardon
2012-04-08drop uses_ureDavid Tardon
2012-04-08let use_api handle the use of type rdbs at runtimeDavid Tardon
2012-04-08gbuild: "use" vs. "add":Michael Stahl
2012-04-02always pass --headless to cppunitsLuboš Luňák
2012-03-10gbuild: get rid of realpath in gb_Foo_set_includeMatúš Kukan