update dev300-m57
[ooovba.git] / hwpfilter / source / attributes.cxx
blob578ed2c8516cd5a58f1214f798f88448fdd1ce1d
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: attributes.cxx,v $
10 * $Revision: 1.5 $
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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_hwpfilter.hxx"
34 #include <assert.h>
35 #ifndef __SGI_STL_VECTOR
36 #include <vector>
37 #endif
38 #include "attributes.hxx"
40 //using namespace ::std;
42 struct TagAttribute
44 TagAttribute(){}
45 TagAttribute( const OUString &rName, const OUString &rType , const OUString &rValue )
47 sName = rName;
48 sType = rType;
49 sValue = rValue;
52 OUString sName;
53 OUString sType;
54 OUString sValue;
57 struct AttributeListImpl_impl
59 AttributeListImpl_impl()
61 // performance improvement during adding
62 vecAttribute.reserve(20);
64 std::vector<struct TagAttribute> vecAttribute;
67 sal_Int16 SAL_CALL AttributeListImpl::getLength(void) throw (RuntimeException)
69 return (sal_Int16)m_pImpl->vecAttribute.size();
73 AttributeListImpl::AttributeListImpl( const AttributeListImpl &r ) :
74 cppu::WeakImplHelper1<com::sun::star::xml::sax::XAttributeList>( r )
76 m_pImpl = new AttributeListImpl_impl;
77 *m_pImpl = *(r.m_pImpl);
81 OUString AttributeListImpl::getNameByIndex(sal_Int16 i) throw (RuntimeException)
83 sal_uInt32 i2 = sal::static_int_cast<sal_Int16>(i);
84 if( i >= 0 && i2 < m_pImpl->vecAttribute.size() )
86 return m_pImpl->vecAttribute[i].sName;
88 return OUString();
92 OUString AttributeListImpl::getTypeByIndex(sal_Int16 i) throw (RuntimeException)
94 sal_uInt32 i2 = sal::static_int_cast<sal_Int16>(i);
95 if( i >= 0 && i2 < m_pImpl->vecAttribute.size() )
97 return m_pImpl->vecAttribute[i].sType;
99 return OUString();
103 OUString AttributeListImpl::getValueByIndex(sal_Int16 i) throw (RuntimeException)
105 sal_uInt32 i2 = sal::static_int_cast<sal_Int16>(i);
106 if( i >= 0 && i2 < m_pImpl->vecAttribute.size() )
108 return m_pImpl->vecAttribute[i].sValue;
110 return OUString();
115 OUString AttributeListImpl::getTypeByName( const OUString& sName ) throw (RuntimeException)
117 std::vector<struct TagAttribute>::iterator ii = m_pImpl->vecAttribute.begin();
119 for( ; ii != m_pImpl->vecAttribute.end() ; ii ++ )
121 if( (*ii).sName == sName )
123 return (*ii).sType;
126 return OUString();
130 OUString AttributeListImpl::getValueByName(const OUString& sName) throw (RuntimeException)
132 std::vector<struct TagAttribute>::iterator ii = m_pImpl->vecAttribute.begin();
134 for( ; ii != m_pImpl->vecAttribute.end() ; ii ++ )
136 if( (*ii).sName == sName )
138 return (*ii).sValue;
141 return OUString();
145 AttributeListImpl::AttributeListImpl()
147 m_pImpl = new AttributeListImpl_impl;
151 AttributeListImpl::~AttributeListImpl()
153 delete m_pImpl;
157 void AttributeListImpl::addAttribute( const OUString &sName ,
158 const OUString &sType ,
159 const OUString &sValue )
161 m_pImpl->vecAttribute.push_back( TagAttribute( sName , sType , sValue ) );
165 void AttributeListImpl::clear()
167 std::vector<struct TagAttribute> dummy;
168 m_pImpl->vecAttribute.swap( dummy );
170 assert( ! getLength() );