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 .
23 #include "attributes.hxx"
28 TagAttribute( const OUString
&rName
, const OUString
&rType
, const OUString
&rValue
)
40 struct AttributeListImpl_impl
42 AttributeListImpl_impl()
44 // performance improvement during adding
45 vecAttribute
.reserve(20);
47 std::vector
<struct TagAttribute
> vecAttribute
;
50 sal_Int16 SAL_CALL
AttributeListImpl::getLength(void) throw (RuntimeException
)
52 return (sal_Int16
)m_pImpl
->vecAttribute
.size();
56 AttributeListImpl::AttributeListImpl( const AttributeListImpl
&r
) :
57 cppu::WeakImplHelper1
<com::sun::star::xml::sax::XAttributeList
>( r
)
59 m_pImpl
= new AttributeListImpl_impl
;
60 *m_pImpl
= *(r
.m_pImpl
);
64 OUString
AttributeListImpl::getNameByIndex(sal_Int16 i
) throw (RuntimeException
)
66 sal_uInt32 i2
= sal::static_int_cast
<sal_Int16
>(i
);
67 if( i
>= 0 && i2
< m_pImpl
->vecAttribute
.size() )
69 return m_pImpl
->vecAttribute
[i
].sName
;
75 OUString
AttributeListImpl::getTypeByIndex(sal_Int16 i
) throw (RuntimeException
)
77 sal_uInt32 i2
= sal::static_int_cast
<sal_Int16
>(i
);
78 if( i
>= 0 && i2
< m_pImpl
->vecAttribute
.size() )
80 return m_pImpl
->vecAttribute
[i
].sType
;
86 OUString
AttributeListImpl::getValueByIndex(sal_Int16 i
) throw (RuntimeException
)
88 sal_uInt32 i2
= sal::static_int_cast
<sal_Int16
>(i
);
89 if( i
>= 0 && i2
< m_pImpl
->vecAttribute
.size() )
91 return m_pImpl
->vecAttribute
[i
].sValue
;
98 OUString
AttributeListImpl::getTypeByName( const OUString
& sName
) throw (RuntimeException
)
100 std::vector
<struct TagAttribute
>::iterator ii
= m_pImpl
->vecAttribute
.begin();
102 for (; ii
!= m_pImpl
->vecAttribute
.end(); ++ii
)
104 if( (*ii
).sName
== sName
)
113 OUString
AttributeListImpl::getValueByName(const OUString
& sName
) throw (RuntimeException
)
115 std::vector
<struct TagAttribute
>::iterator ii
= m_pImpl
->vecAttribute
.begin();
117 for (; ii
!= m_pImpl
->vecAttribute
.end(); ++ii
)
119 if( (*ii
).sName
== sName
)
128 AttributeListImpl::AttributeListImpl()
130 m_pImpl
= new AttributeListImpl_impl
;
134 AttributeListImpl::~AttributeListImpl()
140 void AttributeListImpl::addAttribute( const OUString
&sName
,
141 const OUString
&sType
,
142 const OUString
&sValue
)
144 m_pImpl
->vecAttribute
.push_back( TagAttribute( sName
, sType
, sValue
) );
148 void AttributeListImpl::clear()
150 std::vector
<struct TagAttribute
> dummy
;
151 m_pImpl
->vecAttribute
.swap( dummy
);
153 assert( ! getLength() );
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */