LCOV - code coverage report
Current view: top level - include/xmloff - nmspmap.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 6 6 100.0 %
Date: 2015-06-13 12:38:46 Functions: 6 6 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_XMLOFF_NMSPMAP_HXX
      21             : #define INCLUDED_XMLOFF_NMSPMAP_HXX
      22             : 
      23             : #include <sal/config.h>
      24             : 
      25             : #include <map>
      26             : #include <unordered_map>
      27             : #include <utility>
      28             : 
      29             : #include <xmloff/dllapi.h>
      30             : #include <sal/types.h>
      31             : #include <rtl/ustring.hxx>
      32             : #include <rtl/ref.hxx>
      33             : #include <cppuhelper/weak.hxx>
      34             : 
      35             : #include <limits.h>
      36             : 
      37             : const sal_uInt16 XML_NAMESPACE_XMLNS  = (USHRT_MAX-2);
      38             : const sal_uInt16 XML_NAMESPACE_NONE  = (USHRT_MAX-1);
      39             : const sal_uInt16 XML_NAMESPACE_UNKNOWN  = (USHRT_MAX);
      40             : const sal_uInt16 XML_NAMESPACE_UNKNOWN_FLAG  = 0x8000;
      41             : 
      42      959841 : class NameSpaceEntry : public cppu::OWeakObject
      43             : {
      44             : public:
      45             :     // sName refers to the full namespace name
      46             :     OUString     sName;
      47             :     // sPrefix is the prefix used to declare a given item to be from a given namespace
      48             :     OUString     sPrefix;
      49             :     // nKey is the unique identifier of a namespace
      50             :     sal_uInt16          nKey;
      51             : };
      52             : 
      53             : struct uInt32lt
      54             : {
      55     3040937 :     bool operator()( const sal_uInt32 &r1, const sal_uInt32 &r2) const
      56             :     {
      57     3040937 :         return r1 < r2;
      58             :     }
      59             : };
      60             : typedef ::std::pair < sal_uInt16, OUString > QNamePair;
      61             : 
      62             : struct QNamePairHash
      63             : {
      64      453038 :     size_t operator()( const QNamePair &r1 ) const
      65             :     {
      66      453038 :         return (size_t) r1.second.hashCode() + r1.first;
      67             :     }
      68             : };
      69             : 
      70             : typedef std::unordered_map < QNamePair, OUString, QNamePairHash > QNameCache;
      71             : typedef std::unordered_map < OUString, ::rtl::Reference <NameSpaceEntry >, OUStringHash > NameSpaceHash;
      72             : typedef std::map < sal_uInt16, ::rtl::Reference < NameSpaceEntry >, uInt32lt > NameSpaceMap;
      73             : 
      74             : class XMLOFF_DLLPUBLIC SvXMLNamespaceMap
      75             : {
      76             :     const OUString       sXMLNS;
      77             :     const OUString       sEmpty;
      78             : 
      79             :     NameSpaceHash               aNameHash;
      80             :     mutable NameSpaceHash       aNameCache;
      81             :     NameSpaceMap                aNameMap;
      82             :     mutable QNameCache          aQNameCache;
      83             :     SAL_DLLPRIVATE sal_uInt16 _Add( const OUString& rPrefix, const OUString &rName, sal_uInt16 nKey );
      84             : 
      85             : public:
      86             : 
      87             :     SvXMLNamespaceMap();
      88             :     ~SvXMLNamespaceMap();
      89             : 
      90             :     SvXMLNamespaceMap( const SvXMLNamespaceMap& );
      91             : 
      92             :     void operator =( const SvXMLNamespaceMap& rCmp );
      93             :     bool operator ==( const SvXMLNamespaceMap& rCmp ) const;
      94             : 
      95             :     sal_uInt16 Add( const OUString& rPrefix,
      96             :                 const OUString& rName,
      97             :                 sal_uInt16 nKey = XML_NAMESPACE_UNKNOWN );
      98             :     sal_uInt16 AddIfKnown( const OUString& rPrefix,
      99             :                 const OUString& rName );
     100             : 
     101             :     sal_uInt16 GetKeyByName( const OUString& rName ) const;
     102             :     const OUString& GetNameByKey( sal_uInt16 nKey ) const;
     103             : 
     104             :     sal_uInt16 GetKeyByPrefix( const OUString& rPrefix ) const;
     105             :     const OUString& GetPrefixByKey( sal_uInt16 nKey ) const;
     106             : 
     107             :     OUString GetQNameByKey( sal_uInt16 nKey,
     108             :                            const OUString& rLocalName,
     109             :                            bool bCache = true) const;
     110             : 
     111             :     OUString GetAttrNameByKey( sal_uInt16 nKey ) const;
     112             : 
     113             :     /* This will replace the version with the unused 5th default parameter */
     114             :     sal_uInt16 _GetKeyByAttrName( const OUString& rAttrName,
     115             :                              OUString *pPrefix,
     116             :                              OUString *pLocalName,
     117             :                              OUString *pNamespace = 0,
     118             :                              bool bCache = true) const;
     119             : 
     120             :     /* This will replace the version with the unused 3rd default parameter */
     121             :     sal_uInt16 _GetKeyByAttrName( const OUString& rAttrName,
     122             :                              OUString *pLocalName = 0,
     123             :                              bool bCache = true) const;
     124             : 
     125             :     sal_uInt16 GetFirstKey() const;
     126             :     sal_uInt16 GetNextKey( sal_uInt16 nOldKey ) const;
     127             : 
     128             :     /* Give access to all namespace definitions, including multiple entries
     129             :        for the same key (needed for saving sheets separately in Calc).
     130             :        This might be replaced by a better interface later. */
     131         394 :     const NameSpaceHash& GetAllEntries() const { return aNameHash; }
     132             : 
     133             :     static bool NormalizeOasisURN( OUString& rName );
     134             :     static bool NormalizeW3URI( OUString& rName );
     135             :     static bool NormalizeURI( OUString& rName );
     136             : 
     137             : /* deprecated */ bool AddAtIndex( sal_uInt16 nIdx, const OUString& rPrefix,
     138             :                      const OUString& rName, sal_uInt16 nKey = XML_NAMESPACE_UNKNOWN );
     139             : /* deprecated */ static sal_uInt16 GetIndexByKey( sal_uInt16 nKey );
     140             : /* deprecated */ sal_uInt16 GetIndexByPrefix( const OUString& rPrefix ) const;
     141             : /* deprecated */ sal_uInt16 GetFirstIndex() const;
     142             : /* deprecated */ sal_uInt16 GetNextIndex( sal_uInt16 nOldIdx ) const;
     143             : /* deprecated */ const OUString& GetPrefixByIndex( sal_uInt16 nIdx ) const;
     144             : /* deprecated */ const OUString& GetNameByIndex( sal_uInt16 nIdx ) const;
     145             : /* deprecated */ OUString GetAttrNameByIndex( sal_uInt16 nIdx ) const;
     146             : /* deprecated */ OUString GetQNameByIndex( sal_uInt16 nIdx,
     147             :                             const OUString& rLocalName ) const;
     148             : /* deprecated */ sal_uInt16 GetKeyByAttrName( const OUString& rAttrName,
     149             :                              OUString *pPrefix,
     150             :                              OUString *pLocalName,
     151             :                              OUString *pNamespace=0,
     152             :                              sal_uInt16 nIdxGuess = USHRT_MAX ) const;
     153             : /* deprecated */ sal_uInt16 GetKeyByAttrName( const OUString& rAttrName,
     154             :                              OUString *pLocalName = 0,
     155             :                              sal_uInt16 nIdxGuess = USHRT_MAX ) const;
     156             : };
     157             : 
     158             : #endif // INCLUDED_XMLOFF_NMSPMAP_HXX
     159             : 
     160             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11