update dev300-m58
[ooovba.git] / sax / source / expatwrap / attrlistimpl.cxx
blob3f88be67d5a589eb641bf06b24593c5793241f97
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: attrlistimpl.cxx,v $
10 * $Revision: 1.8.10.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "attrlistimpl.hxx"
33 #include <vector>
35 #if OSL_DEBUG_LEVEL == 0
36 # ifndef NDEBUG
37 # define NDEBUG
38 # endif
39 #endif
40 #include <assert.h>
42 #include <cppuhelper/weak.hxx>
44 using namespace ::std;
45 using namespace ::rtl;
46 using namespace ::cppu;
47 using namespace ::com::sun::star::uno;
48 using namespace ::com::sun::star::util;
49 using namespace ::com::sun::star::xml::sax;
52 namespace sax_expatwrap {
53 struct TagAttribute
55 TagAttribute()
57 TagAttribute( const OUString &aName, const OUString &aType , const OUString &aValue )
59 this->sName = aName;
60 this->sType = aType;
61 this->sValue = aValue;
64 OUString sName;
65 OUString sType;
66 OUString sValue;
69 struct AttributeList_impl
71 AttributeList_impl()
73 // performance improvement during adding
74 vecAttribute.reserve(20);
76 vector<struct TagAttribute> vecAttribute;
81 sal_Int16 AttributeList::getLength(void) throw (RuntimeException)
83 return static_cast<sal_Int16>(m_pImpl->vecAttribute.size());
87 AttributeList::AttributeList( const AttributeList &r ) :
88 cppu::WeakImplHelper2<XAttributeList, XCloneable>()
90 m_pImpl = new AttributeList_impl;
91 *m_pImpl = *(r.m_pImpl);
94 OUString AttributeList::getNameByIndex(sal_Int16 i) throw (RuntimeException)
96 if( std::vector< TagAttribute >::size_type(i) < m_pImpl->vecAttribute.size() ) {
97 return m_pImpl->vecAttribute[i].sName;
99 return OUString();
103 OUString AttributeList::getTypeByIndex(sal_Int16 i) throw (RuntimeException)
105 if( std::vector< TagAttribute >::size_type(i) < m_pImpl->vecAttribute.size() ) {
106 return m_pImpl->vecAttribute[i].sType;
108 return OUString();
111 OUString AttributeList::getValueByIndex(sal_Int16 i) throw (RuntimeException)
113 if( std::vector< TagAttribute >::size_type(i) < m_pImpl->vecAttribute.size() ) {
114 return m_pImpl->vecAttribute[i].sValue;
116 return OUString();
120 OUString AttributeList::getTypeByName( const OUString& sName ) throw (RuntimeException)
122 vector<struct TagAttribute>::iterator ii = m_pImpl->vecAttribute.begin();
124 for( ; ii != m_pImpl->vecAttribute.end() ; ii ++ ) {
125 if( (*ii).sName == sName ) {
126 return (*ii).sType;
129 return OUString();
132 OUString AttributeList::getValueByName(const OUString& sName) throw (RuntimeException)
134 vector<struct TagAttribute>::iterator ii = m_pImpl->vecAttribute.begin();
136 for( ; ii != m_pImpl->vecAttribute.end() ; ii ++ ) {
137 if( (*ii).sName == sName ) {
138 return (*ii).sValue;
141 return OUString();
145 Reference< XCloneable > AttributeList::createClone() throw (RuntimeException)
147 AttributeList *p = new AttributeList( *this );
148 return Reference< XCloneable > ( (XCloneable * ) p );
153 AttributeList::AttributeList()
155 m_pImpl = new AttributeList_impl;
160 AttributeList::~AttributeList()
162 delete m_pImpl;
166 void AttributeList::addAttribute( const OUString &sName ,
167 const OUString &sType ,
168 const OUString &sValue )
170 m_pImpl->vecAttribute.push_back( TagAttribute( sName , sType , sValue ) );
173 void AttributeList::clear()
175 m_pImpl->vecAttribute.clear();