Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / hwpfilter / source / attributes.cxx
blob533769d879ace312810b666619f874d14b6e3fda
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 .
21 #include <assert.h>
22 #include <vector>
23 #include "attributes.hxx"
25 struct TagAttribute
27 TagAttribute( const OUString &rName, const OUString &rType , const OUString &rValue )
29 sName = rName;
30 sType = rType;
31 sValue = rValue;
34 OUString sName;
35 OUString sType;
36 OUString sValue;
39 struct AttributeListImpl_impl
41 AttributeListImpl_impl()
43 // performance improvement during adding
44 vecAttribute.reserve(20);
46 std::vector<struct TagAttribute> vecAttribute;
49 sal_Int16 SAL_CALL AttributeListImpl::getLength()
51 return static_cast<sal_Int16>(m_pImpl->vecAttribute.size());
55 AttributeListImpl::AttributeListImpl( const AttributeListImpl &r )
56 : cppu::WeakImplHelper<css::xml::sax::XAttributeList>( r ),
57 m_pImpl( new AttributeListImpl_impl )
59 *m_pImpl = *(r.m_pImpl);
63 OUString AttributeListImpl::getNameByIndex(sal_Int16 i)
65 sal_uInt32 i2 = sal::static_int_cast<sal_Int16>(i);
66 if( i >= 0 && i2 < m_pImpl->vecAttribute.size() )
68 return m_pImpl->vecAttribute[i].sName;
70 return OUString();
74 OUString AttributeListImpl::getTypeByIndex(sal_Int16 i)
76 sal_uInt32 i2 = sal::static_int_cast<sal_Int16>(i);
77 if( i >= 0 && i2 < m_pImpl->vecAttribute.size() )
79 return m_pImpl->vecAttribute[i].sType;
81 return OUString();
85 OUString AttributeListImpl::getValueByIndex(sal_Int16 i)
87 sal_uInt32 i2 = sal::static_int_cast<sal_Int16>(i);
88 if( i >= 0 && i2 < m_pImpl->vecAttribute.size() )
90 return m_pImpl->vecAttribute[i].sValue;
92 return OUString();
97 OUString AttributeListImpl::getTypeByName( const OUString& sName )
99 for (auto const& elem : m_pImpl->vecAttribute)
101 if( elem.sName == sName )
103 return elem.sType;
106 return OUString();
110 OUString AttributeListImpl::getValueByName(const OUString& sName)
112 for (auto const& elem : m_pImpl->vecAttribute)
114 if( elem.sName == sName )
116 return elem.sValue;
119 return OUString();
123 AttributeListImpl::AttributeListImpl()
124 : m_pImpl( new AttributeListImpl_impl )
129 AttributeListImpl::~AttributeListImpl()
134 void AttributeListImpl::addAttribute( const OUString &sName ,
135 const OUString &sType ,
136 const OUString &sValue )
138 m_pImpl->vecAttribute.emplace_back( sName , sType , sValue );
142 void AttributeListImpl::clear()
144 std::vector<struct TagAttribute> dummy;
145 m_pImpl->vecAttribute.swap( dummy );
147 assert( ! getLength() );
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */