bump product version to 4.2.0.1
[LibreOffice.git] / include / xmloff / nmspmap.hxx
blobce3965d7f876025c213161943068e5b2daea3151
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_XMLOFF_NMSPMAP_HXX
21 #define INCLUDED_XMLOFF_NMSPMAP_HXX
23 #include <sal/config.h>
25 #include <map>
26 #include <utility>
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>
35 #include <limits.h>
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;
42 class NameSpaceEntry : public cppu::OWeakObject
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;
53 struct OUStringEqFunc
55 sal_Bool operator()( const OUString &r1,
56 const OUString &r2) const
58 return r1 == r2;
62 struct uInt32lt
64 sal_Bool operator()( const sal_uInt32 &r1,
65 const sal_uInt32 &r2) const
67 return r1 < r2;
70 typedef ::std::pair < sal_uInt16, OUString > QNamePair;
72 struct QNamePairHash
74 size_t operator()( const QNamePair &r1 ) const
76 return (size_t) r1.second.hashCode() + r1.first;
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;
84 class XMLOFF_DLLPUBLIC SvXMLNamespaceMap
86 const OUString sXMLNS;
87 const OUString sEmpty;
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 );
95 public:
97 SvXMLNamespaceMap();
98 ~SvXMLNamespaceMap();
100 SvXMLNamespaceMap( const SvXMLNamespaceMap& );
102 void operator =( const SvXMLNamespaceMap& rCmp );
103 int operator ==( const SvXMLNamespaceMap& rCmp ) const;
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 );
111 sal_uInt16 GetKeyByName( const OUString& rName ) const;
112 const OUString& GetNameByKey( sal_uInt16 nKey ) const;
114 sal_uInt16 GetKeyByPrefix( const OUString& rPrefix ) const;
115 const OUString& GetPrefixByKey( sal_uInt16 nKey ) const;
117 OUString GetQNameByKey( sal_uInt16 nKey,
118 const OUString& rLocalName,
119 sal_Bool bCache = sal_True) const;
121 OUString GetAttrNameByKey( sal_uInt16 nKey ) const;
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;
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;
135 sal_uInt16 GetFirstKey() const;
136 sal_uInt16 GetNextKey( sal_uInt16 nOldKey ) const;
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 const NameSpaceHash& GetAllEntries() const { return aNameHash; }
143 static sal_Bool NormalizeOasisURN( OUString& rName );
144 static sal_Bool NormalizeW3URI( OUString& rName );
145 static sal_Bool NormalizeURI( OUString& rName );
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;
168 #endif // INCLUDED_XMLOFF_NMSPMAP_HXX
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */