LCOV - code coverage report
Current view: top level - include/sax - fastattribs.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 5 5 100.0 %
Date: 2015-06-13 12:38:46 Functions: 7 7 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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_SAX_FASTATTRIBS_HXX
      21             : #define INCLUDED_SAX_FASTATTRIBS_HXX
      22             : 
      23             : #include <com/sun/star/xml/sax/XFastAttributeList.hpp>
      24             : #include <com/sun/star/xml/sax/XFastTokenHandler.hpp>
      25             : #include <com/sun/star/xml/Attribute.hpp>
      26             : #include <com/sun/star/xml/FastAttribute.hpp>
      27             : 
      28             : #include <cppuhelper/implbase1.hxx>
      29             : #include <sax/saxdllapi.h>
      30             : 
      31             : #include <map>
      32             : #include <vector>
      33             : 
      34             : namespace sax_fastparser
      35             : {
      36             : 
      37       64802 : struct UnknownAttribute
      38             : {
      39             :     OUString maNamespaceURL;
      40             :     OString maName;
      41             :     OString maValue;
      42             : 
      43             :     UnknownAttribute( const OUString& rNamespaceURL, const OString& rName, const OString& value );
      44             :     UnknownAttribute( const OString& rName, const OString& value );
      45             : 
      46             :     void FillAttribute( ::com::sun::star::xml::Attribute* pAttrib ) const;
      47             : };
      48             : 
      49             : typedef std::vector< UnknownAttribute > UnknownAttributeList;
      50             : 
      51             : /// A native C++ interface to tokenisation
      52       34660 : class SAX_DLLPUBLIC FastTokenHandlerBase
      53             : {
      54             :  public:
      55             :     virtual ~FastTokenHandlerBase();
      56             :     virtual sal_Int32 getTokenDirect( const char *pToken, sal_Int32 nLength ) const = 0;
      57             : 
      58             :     /**
      59             :      * Client method to attempt the use of this interface if possible.
      60             :      * @xTokenHandler - the UNO handle for the token lookup interface
      61             :      * @pTokenHandler - a dynamic_cast version of @xTokenHandler to this interface
      62             :      * @pStr - string buffer to lookup
      63             :      * @nLength - optional length of chars in that buffer
      64             :      *
      65             :      * @return Tokenized form of pStr
      66             :      */
      67             :     static sal_Int32 getTokenFromChars(
      68             :                          const css::uno::Reference<
      69             :                              css::xml::sax::XFastTokenHandler > &xTokenHandler,
      70             :                          FastTokenHandlerBase *pTokenHandler /* can be NULL */,
      71             :                          const char *pStr, size_t nLength = 0 );
      72             : };
      73             : 
      74             : class SAX_DLLPUBLIC FastAttributeList : public ::cppu::WeakImplHelper1< ::com::sun::star::xml::sax::XFastAttributeList >
      75             : {
      76             : public:
      77             :     FastAttributeList( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastTokenHandler >& xTokenHandler,
      78             :                        FastTokenHandlerBase *pOptHandlerBase = NULL );
      79             :     virtual ~FastAttributeList();
      80             : 
      81             :     void clear();
      82             :     void add( sal_Int32 nToken, const sal_Char* pValue );
      83             :     void add( sal_Int32 nToken, const sal_Char* pValue, size_t nValueLength );
      84             :     void add( sal_Int32 nToken, const OString& rValue );
      85             :     void addNS( sal_Int32 nNamespaceToken, sal_Int32 nToken, const OString& rValue );
      86             :     void addUnknown( const OUString& rNamespaceURL, const OString& rName, const OString& value );
      87             :     void addUnknown( const OString& rName, const OString& value );
      88      141476 :     const std::vector< sal_Int32 >&  getFastAttributeTokens() const { return maAttributeTokens; }
      89     3220148 :     const char* getFastAttributeValue(size_t nIndex) const { return mpChunk + maAttributeValues[nIndex]; }
      90     2778330 :     sal_Int32 AttributeValueLength(size_t i) const { return maAttributeValues[i + 1] - maAttributeValues[i] - 1; }
      91             : 
      92             :     // performance sensitive shortcuts to avoid allocation ...
      93             :     bool getAsInteger( sal_Int32 nToken, sal_Int32 &rInt);
      94             :     bool getAsDouble( sal_Int32 nToken, double &rDouble);
      95             :     bool getAsChar( sal_Int32 nToken, const char*& rPos ) const;
      96             : 
      97             :     // XFastAttributeList
      98             :     virtual sal_Bool SAL_CALL hasAttribute( ::sal_Int32 Token ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      99             :     virtual ::sal_Int32 SAL_CALL getValueToken( ::sal_Int32 Token ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     100             :     virtual ::sal_Int32 SAL_CALL getOptionalValueToken( ::sal_Int32 Token, ::sal_Int32 Default ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     101             :     virtual OUString SAL_CALL getValue( ::sal_Int32 Token ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     102             :     virtual OUString SAL_CALL getOptionalValue( ::sal_Int32 Token ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     103             :     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::xml::Attribute > SAL_CALL getUnknownAttributes(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     104             :     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::xml::FastAttribute > SAL_CALL getFastAttributes() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     105             : 
     106             : private:
     107             :     sal_Char *mpChunk; ///< buffer to store all attribute values - null terminated strings
     108             :     sal_Int32 mnChunkLength; ///< size of allocated memory for mpChunk
     109             :     // maAttributeValues stores pointers, relative to mpChunk, for each attribute value string
     110             :     // length of the string is maAttributeValues[n+1] - maAttributeValues[n] - 1
     111             :     // maAttributeValues[0] == 0
     112             :     std::vector< sal_Int32 > maAttributeValues;
     113             :     std::vector< sal_Int32 > maAttributeTokens;
     114             :     UnknownAttributeList maUnknownAttributes;
     115             :     ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastTokenHandler > mxTokenHandler;
     116             :     FastTokenHandlerBase *mpTokenHandler;
     117             : };
     118             : 
     119             : }
     120             : 
     121             : #endif
     122             : 
     123             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11