LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/include/xmloff - nmspmap.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 8 8 100.0 %
Date: 2013-07-09 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 _XMLOFF_NMSPMAP_HXX
      21             : #define _XMLOFF_NMSPMAP_HXX
      22             : 
      23             : #include "sal/config.h"
      24             : 
      25             : #include <map>
      26             : #include <utility>
      27             : 
      28             : #include "xmloff/dllapi.h"
      29             : #include "sal/types.h"
      30             : #include <rtl/ustring.hxx>
      31             : #include <boost/unordered_map.hpp>
      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      272520 : 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 OUStringEqFunc
      54             : {
      55      239589 :     sal_Bool operator()( const OUString &r1,
      56             :                          const OUString &r2) const
      57             :     {
      58      239589 :         return r1 == r2;
      59             :     }
      60             : };
      61             : 
      62             : struct uInt32lt
      63             : {
      64      780461 :     sal_Bool operator()( const sal_uInt32 &r1,
      65             :                          const sal_uInt32 &r2) const
      66             :     {
      67      780461 :         return r1 < r2;
      68             :     }
      69             : };
      70             : typedef ::std::pair < sal_uInt16, OUString > QNamePair;
      71             : 
      72             : struct QNamePairHash
      73             : {
      74      123506 :     size_t operator()( const QNamePair &r1 ) const
      75             :     {
      76      123506 :         return (size_t) r1.second.hashCode() + r1.first;
      77             :     }
      78             : };
      79             : 
      80             : typedef ::boost::unordered_map < QNamePair, OUString, QNamePairHash > QNameCache;
      81             : typedef ::boost::unordered_map < OUString, ::rtl::Reference <NameSpaceEntry >, OUStringHash, OUStringEqFunc > NameSpaceHash;
      82             : typedef ::std::map < sal_uInt16, ::rtl::Reference < NameSpaceEntry >, uInt32lt > NameSpaceMap;
      83             : 
      84             : class XMLOFF_DLLPUBLIC SvXMLNamespaceMap
      85             : {
      86             :     const OUString       sXMLNS;
      87             :     const OUString       sEmpty;
      88             : 
      89             :     NameSpaceHash               aNameHash;
      90             :     mutable NameSpaceHash       aNameCache;
      91             :     NameSpaceMap                aNameMap;
      92             :     mutable QNameCache          aQNameCache;
      93             :     SAL_DLLPRIVATE sal_uInt16 _Add( const OUString& rPrefix, const OUString &rName, sal_uInt16 nKey );
      94             : 
      95             : public:
      96             : 
      97             :     SvXMLNamespaceMap();
      98             :     ~SvXMLNamespaceMap();
      99             : 
     100             :     SvXMLNamespaceMap( const SvXMLNamespaceMap& );
     101             : 
     102             :     void operator =( const SvXMLNamespaceMap& rCmp );
     103             :     int operator ==( const SvXMLNamespaceMap& rCmp ) const;
     104             : 
     105             :     sal_uInt16 Add( const OUString& rPrefix,
     106             :                 const OUString& rName,
     107             :                 sal_uInt16 nKey = XML_NAMESPACE_UNKNOWN );
     108             :     sal_uInt16 AddIfKnown( const OUString& rPrefix,
     109             :                 const OUString& rName );
     110             : 
     111             :     sal_uInt16 GetKeyByName( const OUString& rName ) const;
     112             :     const OUString& GetNameByKey( sal_uInt16 nKey ) const;
     113             : 
     114             :     sal_uInt16 GetKeyByPrefix( const OUString& rPrefix ) const;
     115             :     const OUString& GetPrefixByKey( sal_uInt16 nKey ) const;
     116             : 
     117             :     OUString GetQNameByKey( sal_uInt16 nKey,
     118             :                            const OUString& rLocalName,
     119             :                            sal_Bool bCache = sal_True) const;
     120             : 
     121             :     OUString GetAttrNameByKey( sal_uInt16 nKey ) const;
     122             : 
     123             :     /* This will replace the version with the unused 5th default parameter */
     124             :     sal_uInt16 _GetKeyByAttrName( const OUString& rAttrName,
     125             :                              OUString *pPrefix,
     126             :                              OUString *pLocalName,
     127             :                              OUString *pNamespace = 0,
     128             :                              sal_Bool bCache = sal_True) const;
     129             : 
     130             :     /* This will replace the version with the unused 3rd default parameter */
     131             :     sal_uInt16 _GetKeyByAttrName( const OUString& rAttrName,
     132             :                              OUString *pLocalName = 0,
     133             :                              sal_Bool bCache = sal_True) const;
     134             : 
     135             :     sal_uInt16 GetFirstKey() const;
     136             :     sal_uInt16 GetNextKey( sal_uInt16 nOldKey ) const;
     137             : 
     138             :     /* Give access to all namespace definitions, including multiple entries
     139             :        for the same key (needed for saving sheets separately in Calc).
     140             :        This might be replaced by a better interface later. */
     141         150 :     const NameSpaceHash& GetAllEntries() const { return aNameHash; }
     142             : 
     143             :     static sal_Bool NormalizeOasisURN( OUString& rName );
     144             :     static sal_Bool NormalizeW3URI( OUString& rName );
     145             :     static sal_Bool NormalizeURI( OUString& rName );
     146             : 
     147             : /* deprecated */ sal_Bool AddAtIndex( sal_uInt16 nIdx, const OUString& rPrefix,
     148             :                      const OUString& rName, sal_uInt16 nKey = XML_NAMESPACE_UNKNOWN );
     149             : /* deprecated */ sal_uInt16 GetIndexByKey( sal_uInt16 nKey ) const;
     150             : /* deprecated */ sal_uInt16 GetIndexByPrefix( const OUString& rPrefix ) const;
     151             : /* deprecated */ sal_uInt16 GetFirstIndex() const;
     152             : /* deprecated */ sal_uInt16 GetNextIndex( sal_uInt16 nOldIdx ) const;
     153             : /* deprecated */ const OUString& GetPrefixByIndex( sal_uInt16 nIdx ) const;
     154             : /* deprecated */ const OUString& GetNameByIndex( sal_uInt16 nIdx ) const;
     155             : /* deprecated */ OUString GetAttrNameByIndex( sal_uInt16 nIdx ) const;
     156             : /* deprecated */ OUString GetQNameByIndex( sal_uInt16 nIdx,
     157             :                             const OUString& rLocalName ) const;
     158             : /* deprecated */ sal_uInt16 GetKeyByAttrName( const OUString& rAttrName,
     159             :                              OUString *pPrefix,
     160             :                              OUString *pLocalName,
     161             :                              OUString *pNamespace=0,
     162             :                              sal_uInt16 nIdxGuess = USHRT_MAX ) const;
     163             : /* deprecated */ sal_uInt16 GetKeyByAttrName( const OUString& rAttrName,
     164             :                              OUString *pLocalName = 0,
     165             :                              sal_uInt16 nIdxGuess = USHRT_MAX ) const;
     166             : };
     167             : 
     168             : #endif  //  _XMLOFF_NMSPMAP_HXX
     169             : 
     170             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10