LCOV - code coverage report
Current view: top level - libreoffice/solver/unxlngi6.pro/inc/xmloff - nmspmap.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 3 33.3 %
Date: 2012-12-17 Functions: 1 2 50.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             : class NameSpaceEntry : public cppu::OWeakObject
      43             : {
      44             : public:
      45             :     // sName refers to the full namespace name
      46             :     ::rtl::OUString     sName;
      47             :     // sPrefix is the prefix used to declare a given item to be from a given namespace
      48             :     ::rtl::OUString     sPrefix;
      49             :     // nKey is the unique identifier of a namespace
      50             :     sal_uInt16          nKey;
      51             : };
      52             : 
      53             : struct OUStringEqFunc
      54             : {
      55           0 :     sal_Bool operator()( const rtl::OUString &r1,
      56             :                          const rtl::OUString &r2) const
      57             :     {
      58           0 :         return r1 == r2;
      59             :     }
      60             : };
      61             : 
      62             : struct uInt32lt
      63             : {
      64             :     sal_Bool operator()( const sal_uInt32 &r1,
      65             :                          const sal_uInt32 &r2) const
      66             :     {
      67             :         return r1 < r2;
      68             :     }
      69             : };
      70             : typedef ::std::pair < sal_uInt16, rtl::OUString > QNamePair;
      71             : 
      72             : struct QNamePairHash
      73             : {
      74             :     size_t operator()( const QNamePair &r1 ) const
      75             :     {
      76             :         return (size_t) r1.second.hashCode() + r1.first;
      77             :     }
      78             : };
      79             : 
      80             : typedef ::boost::unordered_map < QNamePair, ::rtl::OUString, QNamePairHash > QNameCache;
      81             : typedef ::boost::unordered_map < ::rtl::OUString, ::rtl::Reference <NameSpaceEntry >, rtl::OUStringHash, OUStringEqFunc > NameSpaceHash;
      82             : typedef ::std::map < sal_uInt16, ::rtl::Reference < NameSpaceEntry >, uInt32lt > NameSpaceMap;
      83             : 
      84             : class XMLOFF_DLLPUBLIC SvXMLNamespaceMap
      85             : {
      86             :     const ::rtl::OUString       sXMLNS;
      87             :     const ::rtl::OUString       sEmpty;
      88             : 
      89             :     NameSpaceHash               aNameHash;
      90             :     mutable NameSpaceHash       aNameCache;
      91             :     NameSpaceMap                aNameMap;
      92             :     mutable QNameCache          aQNameCache;
      93             :     SAL_DLLPRIVATE sal_uInt16 _Add( const rtl::OUString& rPrefix, const rtl::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 ::rtl::OUString& rPrefix,
     106             :                 const ::rtl::OUString& rName,
     107             :                 sal_uInt16 nKey = XML_NAMESPACE_UNKNOWN );
     108             :     sal_uInt16 AddIfKnown( const ::rtl::OUString& rPrefix,
     109             :                 const ::rtl::OUString& rName );
     110             : 
     111             :     sal_uInt16 GetKeyByName( const ::rtl::OUString& rName ) const;
     112             :     const ::rtl::OUString& GetNameByKey( sal_uInt16 nKey ) const;
     113             : 
     114             :     sal_uInt16 GetKeyByPrefix( const ::rtl::OUString& rPrefix ) const;
     115             :     const ::rtl::OUString& GetPrefixByKey( sal_uInt16 nKey ) const;
     116             : 
     117             :     ::rtl::OUString GetQNameByKey( sal_uInt16 nKey,
     118             :                            const ::rtl::OUString& rLocalName,
     119             :                            sal_Bool bCache = sal_True) const;
     120             : 
     121             :     ::rtl::OUString GetAttrNameByKey( sal_uInt16 nKey ) const;
     122             : 
     123             :     /* This will replace the version with the unused 5th default parameter */
     124             :     sal_uInt16 _GetKeyByAttrName( const ::rtl::OUString& rAttrName,
     125             :                              ::rtl::OUString *pPrefix,
     126             :                              ::rtl::OUString *pLocalName,
     127             :                              ::rtl::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 ::rtl::OUString& rAttrName,
     132             :                              ::rtl::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         132 :     const NameSpaceHash& GetAllEntries() const { return aNameHash; }
     142             : 
     143             :     static sal_Bool NormalizeOasisURN( ::rtl::OUString& rName );
     144             :     static sal_Bool NormalizeW3URI( ::rtl::OUString& rName );
     145             :     static sal_Bool NormalizeURI( ::rtl::OUString& rName );
     146             : 
     147             : /* deprecated */ sal_Bool AddAtIndex( sal_uInt16 nIdx, const ::rtl::OUString& rPrefix,
     148             :                      const ::rtl::OUString& rName, sal_uInt16 nKey = XML_NAMESPACE_UNKNOWN );
     149             : /* deprecated */ sal_uInt16 GetIndexByKey( sal_uInt16 nKey ) const;
     150             : /* deprecated */ sal_uInt16 GetIndexByPrefix( const ::rtl::OUString& rPrefix ) const;
     151             : /* deprecated */ sal_uInt16 GetFirstIndex() const;
     152             : /* deprecated */ sal_uInt16 GetNextIndex( sal_uInt16 nOldIdx ) const;
     153             : /* deprecated */ const ::rtl::OUString& GetPrefixByIndex( sal_uInt16 nIdx ) const;
     154             : /* deprecated */ const ::rtl::OUString& GetNameByIndex( sal_uInt16 nIdx ) const;
     155             : /* deprecated */ ::rtl::OUString GetAttrNameByIndex( sal_uInt16 nIdx ) const;
     156             : /* deprecated */ ::rtl::OUString GetQNameByIndex( sal_uInt16 nIdx,
     157             :                             const ::rtl::OUString& rLocalName ) const;
     158             : /* deprecated */ sal_uInt16 GetKeyByAttrName( const ::rtl::OUString& rAttrName,
     159             :                              ::rtl::OUString *pPrefix,
     160             :                              ::rtl::OUString *pLocalName,
     161             :                              ::rtl::OUString *pNamespace=0,
     162             :                              sal_uInt16 nIdxGuess = USHRT_MAX ) const;
     163             : /* deprecated */ sal_uInt16 GetKeyByAttrName( const ::rtl::OUString& rAttrName,
     164             :                              ::rtl::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