bump product version to 6.3.0.0.beta1
[LibreOffice.git] / include / xmloff / nmspmap.hxx
blob9c4c57393200305f3564b8bddd30415ce13a9256
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 <unordered_map>
27 #include <utility>
29 #include <xmloff/dllapi.h>
30 #include <sal/types.h>
31 #include <rtl/ustring.hxx>
32 #include <rtl/ref.hxx>
33 #include <salhelper/simplereferenceobject.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 salhelper::SimpleReferenceObject
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 typedef ::std::pair < sal_uInt16, OUString > QNamePair;
55 struct QNamePairHash
57 size_t operator()( const QNamePair &r1 ) const
59 size_t hash = 17;
60 hash = hash * 37 + r1.first;
61 hash = hash * 37 + r1.second.hashCode();
62 return hash;
66 typedef std::unordered_map < QNamePair, OUString, QNamePairHash > QNameCache;
67 typedef std::unordered_map < OUString, ::rtl::Reference <NameSpaceEntry > > NameSpaceHash;
68 typedef std::unordered_map < sal_uInt16, ::rtl::Reference < NameSpaceEntry > > NameSpaceMap;
70 class XMLOFF_DLLPUBLIC SvXMLNamespaceMap
72 OUString sXMLNS;
74 NameSpaceHash aNameHash;
75 mutable NameSpaceHash aNameCache;
76 NameSpaceMap aNameMap;
77 mutable QNameCache aQNameCache;
78 SAL_DLLPRIVATE sal_uInt16 Add_( const OUString& rPrefix, const OUString &rName, sal_uInt16 nKey );
80 public:
82 SvXMLNamespaceMap();
83 ~SvXMLNamespaceMap();
85 SvXMLNamespaceMap( const SvXMLNamespaceMap& );
87 SvXMLNamespaceMap& operator =( const SvXMLNamespaceMap& rCmp );
88 bool operator ==( const SvXMLNamespaceMap& rCmp ) const;
90 sal_uInt16 Add( const OUString& rPrefix,
91 const OUString& rName,
92 sal_uInt16 nKey = XML_NAMESPACE_UNKNOWN );
93 sal_uInt16 AddIfKnown( const OUString& rPrefix,
94 const OUString& rName );
96 sal_uInt16 GetKeyByName( const OUString& rName ) const;
97 const OUString& GetNameByKey( sal_uInt16 nKey ) const;
99 sal_uInt16 GetKeyByPrefix( const OUString& rPrefix ) const;
100 const OUString& GetPrefixByKey( sal_uInt16 nKey ) const;
102 OUString GetQNameByKey( sal_uInt16 nKey,
103 const OUString& rLocalName,
104 bool bCache = true) const;
106 OUString GetAttrNameByKey( sal_uInt16 nKey ) const;
108 /* This will replace the version with the unused 5th default parameter */
109 sal_uInt16 GetKeyByAttrName_( const OUString& rAttrName,
110 OUString *pPrefix,
111 OUString *pLocalName,
112 OUString *pNamespace = nullptr,
113 bool bCache = true) const;
115 /* This will replace the version with the unused 3rd default parameter */
116 sal_uInt16 GetKeyByAttrName_( const OUString& rAttrName,
117 OUString *pLocalName) const;
119 sal_uInt16 GetFirstKey() const;
120 sal_uInt16 GetNextKey( sal_uInt16 nOldKey ) const;
122 /* Give access to all namespace definitions, including multiple entries
123 for the same key (needed for saving sheets separately in Calc).
124 This might be replaced by a better interface later. */
125 const NameSpaceHash& GetAllEntries() const { return aNameHash; }
127 static bool NormalizeOasisURN( OUString& rName );
128 static bool NormalizeW3URI( OUString& rName );
129 static bool NormalizeURI( OUString& rName );
131 /* deprecated */ void AddAtIndex( const OUString& rPrefix,
132 const OUString& rName, sal_uInt16 nKey );
133 /* deprecated */ static sal_uInt16 GetIndexByKey( sal_uInt16 nKey );
134 /* deprecated */ sal_uInt16 GetIndexByPrefix( const OUString& rPrefix ) const;
135 /* deprecated */ sal_uInt16 GetFirstIndex() const;
136 /* deprecated */ sal_uInt16 GetNextIndex( sal_uInt16 nOldIdx ) const;
137 /* deprecated */ const OUString& GetPrefixByIndex( sal_uInt16 nIdx ) const;
138 /* deprecated */ const OUString& GetNameByIndex( sal_uInt16 nIdx ) const;
139 /* deprecated */ OUString GetAttrNameByIndex( sal_uInt16 nIdx ) const;
140 /* deprecated */ OUString GetQNameByIndex( sal_uInt16 nIdx,
141 const OUString& rLocalName ) const;
142 /* deprecated */ sal_uInt16 GetKeyByAttrName( const OUString& rAttrName,
143 OUString *pPrefix,
144 OUString *pLocalName,
145 OUString *pNamespace ) const;
146 /* deprecated */ sal_uInt16 GetKeyByAttrName( const OUString& rAttrName,
147 OUString *pLocalName = nullptr ) const;
150 #endif // INCLUDED_XMLOFF_NMSPMAP_HXX
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */