LibreOffice Module sdext (master) 1
saxattrlist.cxx
Go to the documentation of this file.
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
21#include "saxattrlist.hxx"
22
23namespace pdfi
24{
25
26SaxAttrList::SaxAttrList( const std::unordered_map< OUString, OUString >& rMap )
27{
28 m_aAttributes.reserve(rMap.size());
29 for( const auto& rEntry : rMap )
30 {
31 m_aIndexMap[ rEntry.first ] = m_aAttributes.size();
32 m_aAttributes.emplace_back( rEntry.first, rEntry.second );
33 }
34}
35
36namespace {
37 OUString getCDATAString()
38 {
39 return "CDATA";
40 }
41}
42
43sal_Int16 SAL_CALL SaxAttrList::getLength()
44{
45 return sal_Int16(m_aAttributes.size());
46}
47OUString SAL_CALL SaxAttrList::getNameByIndex( sal_Int16 i_nIndex )
48{
49 return (i_nIndex < sal_Int16(m_aAttributes.size())) ? m_aAttributes[i_nIndex].m_aName : OUString();
50}
51
52OUString SAL_CALL SaxAttrList::getTypeByIndex( sal_Int16 i_nIndex)
53{
54 return (i_nIndex < sal_Int16(m_aAttributes.size())) ? getCDATAString() : OUString();
55}
56
57OUString SAL_CALL SaxAttrList::getTypeByName( const OUString& i_rName )
58{
59 return (m_aIndexMap.find( i_rName ) != m_aIndexMap.end()) ? getCDATAString() : OUString();
60}
61
62OUString SAL_CALL SaxAttrList::getValueByIndex( sal_Int16 i_nIndex )
63{
64 return (i_nIndex < sal_Int16(m_aAttributes.size())) ? m_aAttributes[i_nIndex].m_aValue : OUString();
65}
66
67OUString SAL_CALL SaxAttrList::getValueByName(const OUString& i_rName)
68{
69 std::unordered_map< OUString, size_t >::const_iterator it = m_aIndexMap.find( i_rName );
70 return (it != m_aIndexMap.end()) ? m_aAttributes[it->second].m_aValue : OUString();
71}
72
73css::uno::Reference< css::util::XCloneable > SAL_CALL SaxAttrList::createClone()
74{
75 return new SaxAttrList( *this );
76}
77
78}
79
80/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual OUString SAL_CALL getTypeByName(const OUString &aName) override
Definition: saxattrlist.cxx:57
virtual sal_Int16 SAL_CALL getLength() override
Definition: saxattrlist.cxx:43
std::unordered_map< OUString, size_t > m_aIndexMap
Definition: saxattrlist.hxx:48
virtual OUString SAL_CALL getValueByIndex(sal_Int16 i) override
Definition: saxattrlist.cxx:62
virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override
Definition: saxattrlist.cxx:73
virtual OUString SAL_CALL getNameByIndex(sal_Int16 i) override
Definition: saxattrlist.cxx:47
std::vector< AttrEntry > m_aAttributes
Definition: saxattrlist.hxx:47
virtual OUString SAL_CALL getTypeByIndex(sal_Int16 i) override
Definition: saxattrlist.cxx:52
virtual OUString SAL_CALL getValueByName(const OUString &aName) override
Definition: saxattrlist.cxx:67
SaxAttrList(const std::unordered_map< OUString, OUString > &)
Definition: saxattrlist.cxx:26