1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
24 #include "attributes.hxx"
30 TagAttribute( OUString aName
, OUString aType
, OUString aValue
)
31 : sName(std::move(aName
)), sType(std::move(aType
)), sValue(std::move(aValue
))
42 struct AttributeListImpl_impl
44 AttributeListImpl_impl()
46 // performance improvement during adding
47 vecAttribute
.reserve(20);
49 std::vector
<struct TagAttribute
> vecAttribute
;
52 sal_Int16 SAL_CALL
AttributeListImpl::getLength()
54 return static_cast<sal_Int16
>(m_pImpl
->vecAttribute
.size());
58 AttributeListImpl::AttributeListImpl( const AttributeListImpl
&r
)
59 : cppu::WeakImplHelper
<css::xml::sax::XAttributeList
>( r
),
60 m_pImpl( new AttributeListImpl_impl
)
62 *m_pImpl
= *(r
.m_pImpl
);
66 OUString
AttributeListImpl::getNameByIndex(sal_Int16 i
)
68 sal_uInt32 i2
= sal::static_int_cast
<sal_Int16
>(i
);
69 if( i
>= 0 && i2
< m_pImpl
->vecAttribute
.size() )
71 return m_pImpl
->vecAttribute
[i
].sName
;
77 OUString
AttributeListImpl::getTypeByIndex(sal_Int16 i
)
79 sal_uInt32 i2
= sal::static_int_cast
<sal_Int16
>(i
);
80 if( i
>= 0 && i2
< m_pImpl
->vecAttribute
.size() )
82 return m_pImpl
->vecAttribute
[i
].sType
;
88 OUString
AttributeListImpl::getValueByIndex(sal_Int16 i
)
90 sal_uInt32 i2
= sal::static_int_cast
<sal_Int16
>(i
);
91 if( i
>= 0 && i2
< m_pImpl
->vecAttribute
.size() )
93 return m_pImpl
->vecAttribute
[i
].sValue
;
100 OUString
AttributeListImpl::getTypeByName( const OUString
& sName
)
102 for (auto const& elem
: m_pImpl
->vecAttribute
)
104 if( elem
.sName
== sName
)
113 OUString
AttributeListImpl::getValueByName(const OUString
& sName
)
115 for (auto const& elem
: m_pImpl
->vecAttribute
)
117 if( elem
.sName
== sName
)
126 AttributeListImpl::AttributeListImpl()
127 : m_pImpl( new AttributeListImpl_impl
)
132 AttributeListImpl::~AttributeListImpl()
137 void AttributeListImpl::addAttribute( const OUString
&sName
,
138 const OUString
&sType
,
139 const OUString
&sValue
)
141 m_pImpl
->vecAttribute
.emplace_back( sName
, sType
, sValue
);
145 void AttributeListImpl::clear()
147 std::vector
<struct TagAttribute
>().swap(m_pImpl
->vecAttribute
);
149 assert( ! getLength() );
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */