1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_comphelper.hxx"
30 #include <comphelper/attributelist.hxx>
31 #include <vos/diagnose.hxx>
37 using namespace com::sun::star
;
39 namespace comphelper
{
41 struct TagAttribute_Impl
44 TagAttribute_Impl( const OUString
&aName
, const OUString
&aType
,
45 const OUString
&aValue
)
49 this->sValue
= aValue
;
57 struct AttributeList_Impl
61 // performance improvement during adding
62 vecAttribute
.reserve(20);
64 ::std::vector
<struct TagAttribute_Impl
> vecAttribute
;
67 sal_Int16 SAL_CALL
AttributeList::getLength(void) throw( ::com::sun::star::uno::RuntimeException
)
69 return (sal_Int16
)(m_pImpl
->vecAttribute
.size());
72 OUString SAL_CALL
AttributeList::getNameByIndex(sal_Int16 i
) throw( ::com::sun::star::uno::RuntimeException
)
74 return ( i
< static_cast < sal_Int16
> (m_pImpl
->vecAttribute
.size()) ) ? m_pImpl
->vecAttribute
[i
].sName
: OUString();
77 OUString SAL_CALL
AttributeList::getTypeByIndex(sal_Int16 i
) throw( ::com::sun::star::uno::RuntimeException
)
79 if( i
< static_cast < sal_Int16
> (m_pImpl
->vecAttribute
.size() ) ) {
80 return m_pImpl
->vecAttribute
[i
].sType
;
85 OUString SAL_CALL
AttributeList::getValueByIndex(sal_Int16 i
) throw( ::com::sun::star::uno::RuntimeException
)
87 return ( i
< static_cast < sal_Int16
> (m_pImpl
->vecAttribute
.size() ) ) ? m_pImpl
->vecAttribute
[i
].sValue
: OUString();
90 OUString SAL_CALL
AttributeList::getTypeByName( const OUString
& sName
) throw( ::com::sun::star::uno::RuntimeException
)
92 ::std::vector
<struct TagAttribute_Impl
>::iterator ii
= m_pImpl
->vecAttribute
.begin();
94 for( ; ii
!= m_pImpl
->vecAttribute
.end() ; ii
++ ) {
95 if( (*ii
).sName
== sName
) {
102 OUString SAL_CALL
AttributeList::getValueByName(const OUString
& sName
) throw( ::com::sun::star::uno::RuntimeException
)
104 ::std::vector
<struct TagAttribute_Impl
>::iterator ii
= m_pImpl
->vecAttribute
.begin();
106 for( ; ii
!= m_pImpl
->vecAttribute
.end() ; ii
++ ) {
107 if( (*ii
).sName
== sName
) {
115 AttributeList::AttributeList()
117 m_pImpl
= new AttributeList_Impl
;
122 AttributeList::~AttributeList()
127 void AttributeList::AddAttribute( const OUString
&sName
,
128 const OUString
&sType
,
129 const OUString
&sValue
)
131 m_pImpl
->vecAttribute
.push_back( TagAttribute_Impl( sName
, sType
, sValue
) );
134 void AttributeList::Clear()
136 m_pImpl
->vecAttribute
.clear();
138 VOS_ENSURE( ! getLength(), "Length > 0 after AttributeList::Clear!");
141 void AttributeList::RemoveAttribute( const OUString sName
)
143 ::std::vector
<struct TagAttribute_Impl
>::iterator ii
= m_pImpl
->vecAttribute
.begin();
145 for( ; ii
!= m_pImpl
->vecAttribute
.end() ; ii
++ ) {
146 if( (*ii
).sName
== sName
) {
147 m_pImpl
->vecAttribute
.erase( ii
);
154 void AttributeList::SetAttributeList( const uno::Reference
< ::com::sun::star::xml::sax::XAttributeList
> &r
)
157 AppendAttributeList( r
);
160 void AttributeList::AppendAttributeList( const uno::Reference
< ::com::sun::star::xml::sax::XAttributeList
> &r
)
162 VOS_ENSURE( r
.is(), "r isn't!" );
164 sal_Int32 nMax
= r
->getLength();
165 sal_Int32 nTotalSize
= m_pImpl
->vecAttribute
.size() + nMax
;
166 m_pImpl
->vecAttribute
.reserve( nTotalSize
);
168 for( sal_Int16 i
= 0 ; i
< nMax
; i
++ ) {
169 m_pImpl
->vecAttribute
.push_back( TagAttribute_Impl(
170 r
->getNameByIndex( i
) ,
171 r
->getTypeByIndex( i
) ,
172 r
->getValueByIndex( i
)));
175 VOS_ENSURE( nTotalSize
== getLength(), "nTotalSize != getLength()");
178 } // namespace comphelper