1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
32 #include "attributes.hxx"
37 TagAttribute( const OUString
&rName
, const OUString
&rType
, const OUString
&rValue
)
49 struct AttributeListImpl_impl
51 AttributeListImpl_impl()
53 // performance improvement during adding
54 vecAttribute
.reserve(20);
56 std::vector
<struct TagAttribute
> vecAttribute
;
59 sal_Int16 SAL_CALL
AttributeListImpl::getLength(void) throw (RuntimeException
)
61 return (sal_Int16
)m_pImpl
->vecAttribute
.size();
65 AttributeListImpl::AttributeListImpl( const AttributeListImpl
&r
) :
66 cppu::WeakImplHelper1
<com::sun::star::xml::sax::XAttributeList
>( r
)
68 m_pImpl
= new AttributeListImpl_impl
;
69 *m_pImpl
= *(r
.m_pImpl
);
73 OUString
AttributeListImpl::getNameByIndex(sal_Int16 i
) throw (RuntimeException
)
75 sal_uInt32 i2
= sal::static_int_cast
<sal_Int16
>(i
);
76 if( i
>= 0 && i2
< m_pImpl
->vecAttribute
.size() )
78 return m_pImpl
->vecAttribute
[i
].sName
;
84 OUString
AttributeListImpl::getTypeByIndex(sal_Int16 i
) throw (RuntimeException
)
86 sal_uInt32 i2
= sal::static_int_cast
<sal_Int16
>(i
);
87 if( i
>= 0 && i2
< m_pImpl
->vecAttribute
.size() )
89 return m_pImpl
->vecAttribute
[i
].sType
;
95 OUString
AttributeListImpl::getValueByIndex(sal_Int16 i
) throw (RuntimeException
)
97 sal_uInt32 i2
= sal::static_int_cast
<sal_Int16
>(i
);
98 if( i
>= 0 && i2
< m_pImpl
->vecAttribute
.size() )
100 return m_pImpl
->vecAttribute
[i
].sValue
;
107 OUString
AttributeListImpl::getTypeByName( const OUString
& sName
) throw (RuntimeException
)
109 std::vector
<struct TagAttribute
>::iterator ii
= m_pImpl
->vecAttribute
.begin();
111 for (; ii
!= m_pImpl
->vecAttribute
.end(); ++ii
)
113 if( (*ii
).sName
== sName
)
122 OUString
AttributeListImpl::getValueByName(const OUString
& sName
) throw (RuntimeException
)
124 std::vector
<struct TagAttribute
>::iterator ii
= m_pImpl
->vecAttribute
.begin();
126 for (; ii
!= m_pImpl
->vecAttribute
.end(); ++ii
)
128 if( (*ii
).sName
== sName
)
137 AttributeListImpl::AttributeListImpl()
139 m_pImpl
= new AttributeListImpl_impl
;
143 AttributeListImpl::~AttributeListImpl()
149 void AttributeListImpl::addAttribute( const OUString
&sName
,
150 const OUString
&sType
,
151 const OUString
&sValue
)
153 m_pImpl
->vecAttribute
.push_back( TagAttribute( sName
, sType
, sValue
) );
157 void AttributeListImpl::clear()
159 std::vector
<struct TagAttribute
> dummy
;
160 m_pImpl
->vecAttribute
.swap( dummy
);
162 assert( ! getLength() );
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */