tdf#137335 calculate paragraph height in RTF/DOCX
[LibreOffice.git] / include / xmloff / namespacemap.hxx
blob946e36656a2fa971267ad868b9ddd57fdef5fb89
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 <unordered_map>
26 #include <utility>
28 #include <xmloff/dllapi.h>
29 #include <sal/types.h>
30 #include <rtl/ustring.hxx>
32 #include <limits.h>
34 const sal_uInt16 XML_NAMESPACE_XMLNS = USHRT_MAX-2;
35 const sal_uInt16 XML_NAMESPACE_NONE = USHRT_MAX-1;
36 const sal_uInt16 XML_NAMESPACE_UNKNOWN = USHRT_MAX;
37 const sal_uInt16 XML_NAMESPACE_UNKNOWN_FLAG = 0x8000;
39 class NameSpaceEntry final
41 public:
42 // sName refers to the full namespace name
43 OUString m_sName;
44 // sPrefix is the prefix used to declare a given item to be from a given namespace
45 OUString m_sPrefix;
46 // nKey is the unique identifier of a namespace
47 sal_uInt16 m_nKey;
49 bool operator==(NameSpaceEntry const & rhs) const
51 return m_sName == rhs.m_sName && m_sPrefix == rhs.m_sPrefix && m_nKey == rhs.m_nKey;
55 class KeyToNameSpaceMapEntry final
57 public:
58 // sName refers to the full namespace name
59 OUString sName;
60 // sPrefix is the prefix used to declare a given item to be from a given namespace
61 OUString sPrefix;
64 typedef ::std::pair < sal_uInt16, OUString > QNamePair;
66 struct QNamePairHash
68 size_t operator()( const QNamePair &r1 ) const
70 size_t hash = 17;
71 hash = hash * 37 + r1.first;
72 hash = hash * 37 + r1.second.hashCode();
73 return hash;
77 typedef std::unordered_map < QNamePair, OUString, QNamePairHash > QNameCache;
78 typedef std::unordered_map < OUString, NameSpaceEntry > NameSpaceHash;
79 typedef std::unordered_map < sal_uInt16, KeyToNameSpaceMapEntry > KeyToNameSpaceMap;
81 class XMLOFF_DLLPUBLIC SvXMLNamespaceMap
83 OUString m_sXMLNS;
85 NameSpaceHash m_aNameHash;
86 mutable NameSpaceHash m_aNameCache;
87 KeyToNameSpaceMap maKeyToNamespaceMap;
88 mutable QNameCache m_aQNameCache;
89 SAL_DLLPRIVATE sal_uInt16 Add_( const OUString& rPrefix, const OUString &rName, sal_uInt16 nKey );
91 public:
93 SvXMLNamespaceMap();
94 ~SvXMLNamespaceMap();
96 SvXMLNamespaceMap( const SvXMLNamespaceMap& );
98 SvXMLNamespaceMap& operator =( const SvXMLNamespaceMap& rCmp );
99 bool operator ==( const SvXMLNamespaceMap& rCmp ) const;
101 sal_uInt16 Add( const OUString& rPrefix,
102 const OUString& rName,
103 sal_uInt16 nKey = XML_NAMESPACE_UNKNOWN );
104 sal_uInt16 AddIfKnown( const OUString& rPrefix,
105 const OUString& rName );
107 sal_uInt16 GetKeyByName( const OUString& rName ) const;
108 const OUString& GetNameByKey( sal_uInt16 nKey ) const;
110 sal_uInt16 GetKeyByPrefix( const OUString& rPrefix ) const;
111 const OUString& GetPrefixByKey( sal_uInt16 nKey ) const;
113 OUString GetQNameByKey( sal_uInt16 nKey,
114 const OUString& rLocalName,
115 bool bCache = true) const;
117 OUString GetAttrNameByKey( sal_uInt16 nKey ) const;
119 enum class QNameMode { AttrNameCached, AttrValue };
120 sal_uInt16 GetKeyByQName(const OUString& rQName,
121 OUString *pPrefix,
122 OUString *pLocalName,
123 OUString *pNamespace,
124 QNameMode eMode) const;
126 sal_uInt16 GetKeyByAttrValueQName(const OUString& rAttrName,
127 OUString *pLocalName) const;
129 sal_uInt16 GetFirstKey() const;
130 sal_uInt16 GetNextKey( sal_uInt16 nOldKey ) const;
132 /* Give access to all namespace definitions, including multiple entries
133 for the same key (needed for saving sheets separately in Calc).
134 This might be replaced by a better interface later. */
135 const NameSpaceHash& GetAllEntries() const { return m_aNameHash; }
137 void Clear();
139 static bool NormalizeOasisURN( OUString& rName );
140 static bool NormalizeW3URI( OUString& rName );
141 static bool NormalizeURI( OUString& rName );
143 /* deprecated */ void AddAtIndex( const OUString& rPrefix,
144 const OUString& rName, sal_uInt16 nKey );
145 /* deprecated */ static sal_uInt16 GetIndexByKey( sal_uInt16 nKey );
146 /* deprecated */ sal_uInt16 GetIndexByPrefix( const OUString& rPrefix ) const;
147 /* deprecated */ sal_uInt16 GetFirstIndex() const;
148 /* deprecated */ sal_uInt16 GetNextIndex( sal_uInt16 nOldIdx ) const;
149 /* deprecated */ const OUString& GetPrefixByIndex( sal_uInt16 nIdx ) const;
150 /* deprecated */ const OUString& GetNameByIndex( sal_uInt16 nIdx ) const;
151 /* deprecated */ OUString GetAttrNameByIndex( sal_uInt16 nIdx ) const;
152 sal_uInt16 GetKeyByAttrName( const OUString& rAttrName,
153 OUString *pPrefix,
154 OUString *pLocalName,
155 OUString *pNamespace ) const;
156 /* deprecated */ sal_uInt16 GetKeyByAttrName( const OUString& rAttrName,
157 OUString *pLocalName = nullptr ) const;
160 #endif // INCLUDED_XMLOFF_NMSPMAP_HXX
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */