| 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 |
#pragma once |
| 21 |
|
| 22 |
#include <rtl/ustring.hxx> |
| 23 |
#include <utility> |
| 24 |
#include <xmloff/namespacemap.hxx> |
| 25 |
#include "TransformerActionInit.hxx" |
| 26 |
#include "TransformerAction.hxx" |
| 27 |
#include <o3tl/hash_combine.hxx> |
| 28 |
#include <unordered_map> |
| 29 |
|
| 30 |
struct NameKey_Impl |
| 31 |
{ |
| 32 |
sal_uInt16 m_nPrefix; |
| 33 |
OUString m_aLocalName; |
| 34 |
|
| 35 |
NameKey_Impl( sal_uInt16 nPrfx, OUString aLclNm ) : |
| 36 |
m_nPrefix( nPrfx ), |
| 37 |
m_aLocalName(std::move( aLclNm )) |
| 38 |
{ |
| 39 |
} |
| 40 |
|
| 41 |
NameKey_Impl() : |
| 42 |
m_nPrefix( XML_NAMESPACE_UNKNOWN ) |
| 43 |
{ |
| 44 |
} |
| 45 |
|
| 46 |
void SetLocalName( ::xmloff::token::XMLTokenEnum eLclNm ) |
| 47 |
{ |
| 48 |
m_aLocalName = ::xmloff::token::GetXMLToken( eLclNm ); |
| 49 |
} |
| 50 |
}; |
| 51 |
|
| 52 |
struct NameHash_Impl |
| 53 |
{ |
| 54 |
inline size_t operator()( const NameKey_Impl& r ) const; |
| 55 |
inline bool operator()( const NameKey_Impl& r1, |
| 56 |
const NameKey_Impl& r2 ) const; |
| 57 |
}; |
| 58 |
|
| 59 |
inline size_t NameHash_Impl::operator()( const NameKey_Impl& r ) const |
| 60 |
{ |
| 61 |
std::size_t seed = 0; |
| 62 |
o3tl::hash_combine(seed, r.m_nPrefix); |
| 63 |
o3tl::hash_combine(seed, r.m_aLocalName.hashCode()); |
| 64 |
return seed; |
| 65 |
} |
| 66 |
|
| 67 |
inline bool NameHash_Impl::operator()( |
| 68 |
const NameKey_Impl& r1, |
| 69 |
const NameKey_Impl& r2 ) const |
| 70 |
{ |
| 71 |
return r1.m_nPrefix == r2.m_nPrefix && r1.m_aLocalName == r2.m_aLocalName; |
| 72 |
} |
| 73 |
|
| 74 |
struct TransformerAction_Impl |
| 75 |
{ |
| 76 |
sal_uInt32 m_nActionType; |
| 77 |
sal_uInt32 m_nParam1; |
| 78 |
sal_uInt32 m_nParam2; |
| 79 |
sal_uInt32 m_nParam3; |
| 80 |
|
| 81 |
TransformerAction_Impl() : |
| 82 |
m_nActionType( XML_TACTION_EOT ), |
| 83 |
m_nParam1( 0 ), |
| 84 |
m_nParam2( 0 ), |
| 85 |
m_nParam3( 0 ) |
| 86 |
{ |
| 87 |
} |
| 88 |
|
| 89 |
sal_uInt16 GetQNamePrefixFromParam1() const |
| 90 |
{ |
| 91 |
return static_cast< sal_uInt16 >( m_nParam1 >> 16 ); |
| 92 |
} |
| 93 |
|
| 94 |
sal_uInt16 GetQNamePrefixFromParam2() const |
| 95 |
{ |
| 96 |
return static_cast< sal_uInt16 >( m_nParam2 >> 16 ); |
| 97 |
} |
| 98 |
|
| 99 |
sal_uInt16 GetQNamePrefixFromParam3() const |
| 100 |
{ |
| 101 |
return static_cast< sal_uInt16 >( m_nParam3 >> 16 ); |
| 102 |
} |
| 103 |
|
| 104 |
::xmloff::token::XMLTokenEnum GetQNameTokenFromParam1() const |
| 105 |
{ |
| 106 |
return static_cast< ::xmloff::token::XMLTokenEnum>( m_nParam1 & 0xffff ); |
| 107 |
} |
| 108 |
|
| 109 |
::xmloff::token::XMLTokenEnum GetQNameTokenFromParam2() const |
| 110 |
{ |
| 111 |
return static_cast< ::xmloff::token::XMLTokenEnum>( m_nParam2 & 0xffff ); |
| 112 |
} |
| 113 |
|
| 114 |
::xmloff::token::XMLTokenEnum GetQNameTokenFromParam3() const |
| 115 |
{ |
| 116 |
return static_cast< ::xmloff::token::XMLTokenEnum>( m_nParam3 & 0xffff ); |
| 117 |
} |
| 118 |
|
| 119 |
}; |
| 120 |
|
| 121 |
class XMLTransformerActions : |
| 122 |
public std::unordered_map< NameKey_Impl, TransformerAction_Impl, |
| 123 |
NameHash_Impl, NameHash_Impl > |
| 124 |
{ |
| 125 |
public: |
| 126 |
explicit XMLTransformerActions( XMLTransformerActionInit const *pInit ); |
| 127 |
~XMLTransformerActions(); |
| 128 |
|
| 129 |
void Add( XMLTransformerActionInit const *pInit ); |
| 130 |
}; |
| 131 |
|
| 132 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |