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 ************************************************************************/
29 #include "attrlistimpl.hxx"
33 #include <cppuhelper/weak.hxx>
35 using namespace ::std
;
36 using namespace ::rtl
;
37 using namespace ::cppu
;
38 using namespace ::com::sun::star::uno
;
39 using namespace ::com::sun::star::util
;
40 using namespace ::com::sun::star::xml::sax
;
43 namespace sax_expatwrap
{
48 TagAttribute( const OUString
&aName
, const OUString
&aType
, const OUString
&aValue
)
52 this->sValue
= aValue
;
60 struct AttributeList_impl
64 // performance improvement during adding
65 vecAttribute
.reserve(20);
67 vector
<struct TagAttribute
> vecAttribute
;
72 sal_Int16
AttributeList::getLength(void) throw (RuntimeException
)
74 return static_cast<sal_Int16
>(m_pImpl
->vecAttribute
.size());
78 AttributeList::AttributeList( const AttributeList
&r
) :
79 cppu::WeakImplHelper2
<XAttributeList
, XCloneable
>()
81 m_pImpl
= new AttributeList_impl
;
82 *m_pImpl
= *(r
.m_pImpl
);
85 OUString
AttributeList::getNameByIndex(sal_Int16 i
) throw (RuntimeException
)
87 if( std::vector
< TagAttribute
>::size_type(i
) < m_pImpl
->vecAttribute
.size() ) {
88 return m_pImpl
->vecAttribute
[i
].sName
;
94 OUString
AttributeList::getTypeByIndex(sal_Int16 i
) throw (RuntimeException
)
96 if( std::vector
< TagAttribute
>::size_type(i
) < m_pImpl
->vecAttribute
.size() ) {
97 return m_pImpl
->vecAttribute
[i
].sType
;
102 OUString
AttributeList::getValueByIndex(sal_Int16 i
) throw (RuntimeException
)
104 if( std::vector
< TagAttribute
>::size_type(i
) < m_pImpl
->vecAttribute
.size() ) {
105 return m_pImpl
->vecAttribute
[i
].sValue
;
111 OUString
AttributeList::getTypeByName( const OUString
& sName
) throw (RuntimeException
)
113 vector
<struct TagAttribute
>::iterator ii
= m_pImpl
->vecAttribute
.begin();
115 for (; ii
!= m_pImpl
->vecAttribute
.end(); ++ii
)
117 if( (*ii
).sName
== sName
)
125 OUString
AttributeList::getValueByName(const OUString
& sName
) throw (RuntimeException
)
127 vector
<struct TagAttribute
>::iterator ii
= m_pImpl
->vecAttribute
.begin();
129 for (; ii
!= m_pImpl
->vecAttribute
.end(); ++ii
)
131 if( (*ii
).sName
== sName
)
140 Reference
< XCloneable
> AttributeList::createClone() throw (RuntimeException
)
142 AttributeList
*p
= new AttributeList( *this );
143 return Reference
< XCloneable
> ( (XCloneable
* ) p
);
148 AttributeList::AttributeList()
150 m_pImpl
= new AttributeList_impl
;
155 AttributeList::~AttributeList()
161 void AttributeList::addAttribute( const OUString
&sName
,
162 const OUString
&sType
,
163 const OUString
&sValue
)
165 m_pImpl
->vecAttribute
.push_back( TagAttribute( sName
, sType
, sValue
) );
168 void AttributeList::clear()
170 m_pImpl
->vecAttribute
.clear();
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */