Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "attrlistimpl.hxx"
21 :
22 : #include <vector>
23 :
24 : #include <cppuhelper/weak.hxx>
25 :
26 : using namespace ::std;
27 : using namespace ::rtl;
28 : using namespace ::cppu;
29 : using namespace ::com::sun::star::uno;
30 : using namespace ::com::sun::star::util;
31 : using namespace ::com::sun::star::xml::sax;
32 :
33 :
34 : namespace sax_expatwrap {
35 291197 : struct TagAttribute
36 : {
37 : TagAttribute()
38 : {}
39 96033 : TagAttribute( const OUString &aName, const OUString &aType , const OUString &aValue )
40 96033 : {
41 96033 : this->sName = aName;
42 96033 : this->sType = aType;
43 96033 : this->sValue = aValue;
44 96033 : }
45 :
46 : OUString sName;
47 : OUString sType;
48 : OUString sValue;
49 : };
50 :
51 1666 : struct AttributeList_impl
52 : {
53 1630 : AttributeList_impl()
54 1630 : {
55 : // performance improvement during adding
56 1630 : vecAttribute.reserve(20);
57 1630 : }
58 : vector<struct TagAttribute> vecAttribute;
59 : };
60 :
61 :
62 :
63 87800 : sal_Int16 AttributeList::getLength(void) throw (RuntimeException)
64 : {
65 87800 : return static_cast<sal_Int16>(m_pImpl->vecAttribute.size());
66 : }
67 :
68 :
69 36 : AttributeList::AttributeList( const AttributeList &r ) :
70 36 : cppu::WeakImplHelper2<XAttributeList, XCloneable>()
71 : {
72 36 : m_pImpl = new AttributeList_impl;
73 36 : *m_pImpl = *(r.m_pImpl);
74 36 : }
75 :
76 130859 : OUString AttributeList::getNameByIndex(sal_Int16 i) throw (RuntimeException)
77 : {
78 130859 : if( std::vector< TagAttribute >::size_type(i) < m_pImpl->vecAttribute.size() ) {
79 130859 : return m_pImpl->vecAttribute[i].sName;
80 : }
81 0 : return OUString();
82 : }
83 :
84 :
85 0 : OUString AttributeList::getTypeByIndex(sal_Int16 i) throw (RuntimeException)
86 : {
87 0 : if( std::vector< TagAttribute >::size_type(i) < m_pImpl->vecAttribute.size() ) {
88 0 : return m_pImpl->vecAttribute[i].sType;
89 : }
90 0 : return OUString();
91 : }
92 :
93 97580 : OUString AttributeList::getValueByIndex(sal_Int16 i) throw (RuntimeException)
94 : {
95 97580 : if( std::vector< TagAttribute >::size_type(i) < m_pImpl->vecAttribute.size() ) {
96 97580 : return m_pImpl->vecAttribute[i].sValue;
97 : }
98 0 : return OUString();
99 :
100 : }
101 :
102 0 : OUString AttributeList::getTypeByName( const OUString& sName ) throw (RuntimeException)
103 : {
104 0 : vector<struct TagAttribute>::iterator ii = m_pImpl->vecAttribute.begin();
105 :
106 0 : for (; ii != m_pImpl->vecAttribute.end(); ++ii )
107 : {
108 0 : if( (*ii).sName == sName )
109 : {
110 0 : return (*ii).sType;
111 : }
112 : }
113 0 : return OUString();
114 : }
115 :
116 8424 : OUString AttributeList::getValueByName(const OUString& sName) throw (RuntimeException)
117 : {
118 8424 : vector<struct TagAttribute>::iterator ii = m_pImpl->vecAttribute.begin();
119 :
120 16995 : for (; ii != m_pImpl->vecAttribute.end(); ++ii)
121 : {
122 15908 : if( (*ii).sName == sName )
123 : {
124 7337 : return (*ii).sValue;
125 : }
126 : }
127 1087 : return OUString();
128 : }
129 :
130 :
131 36 : Reference< XCloneable > AttributeList::createClone() throw (RuntimeException)
132 : {
133 36 : AttributeList *p = new AttributeList( *this );
134 36 : return Reference< XCloneable > ( (XCloneable * ) p );
135 : }
136 :
137 :
138 :
139 1594 : AttributeList::AttributeList()
140 : {
141 1594 : m_pImpl = new AttributeList_impl;
142 1594 : }
143 :
144 :
145 :
146 4890 : AttributeList::~AttributeList()
147 : {
148 1630 : delete m_pImpl;
149 3260 : }
150 :
151 :
152 96033 : void AttributeList::addAttribute( const OUString &sName ,
153 : const OUString &sType ,
154 : const OUString &sValue )
155 : {
156 96033 : m_pImpl->vecAttribute.push_back( TagAttribute( sName , sType , sValue ) );
157 96033 : }
158 :
159 70250 : void AttributeList::clear()
160 : {
161 70250 : m_pImpl->vecAttribute.clear();
162 70250 : }
163 :
164 : }
165 :
166 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|