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 318872 : struct TagAttribute
36 : {
37 : TagAttribute()
38 : {}
39 104012 : TagAttribute( const OUString &aName, const OUString &aType , const OUString &aValue )
40 104012 : {
41 104012 : this->sName = aName;
42 104012 : this->sType = aType;
43 104012 : this->sValue = aValue;
44 104012 : }
45 :
46 : OUString sName;
47 : OUString sType;
48 : OUString sValue;
49 : };
50 :
51 2937 : struct AttributeList_impl
52 : {
53 2865 : AttributeList_impl()
54 2865 : {
55 : // performance improvement during adding
56 2865 : vecAttribute.reserve(20);
57 2865 : }
58 : vector<struct TagAttribute> vecAttribute;
59 : };
60 :
61 :
62 :
63 99567 : sal_Int16 AttributeList::getLength(void) throw (RuntimeException)
64 : {
65 99567 : return static_cast<sal_Int16>(m_pImpl->vecAttribute.size());
66 : }
67 :
68 :
69 72 : AttributeList::AttributeList( const AttributeList &r ) :
70 72 : cppu::WeakImplHelper2<XAttributeList, XCloneable>()
71 : {
72 72 : m_pImpl = new AttributeList_impl;
73 72 : *m_pImpl = *(r.m_pImpl);
74 72 : }
75 :
76 189565 : OUString AttributeList::getNameByIndex(sal_Int16 i) throw (RuntimeException)
77 : {
78 189565 : if( std::vector< TagAttribute >::size_type(i) < m_pImpl->vecAttribute.size() ) {
79 189565 : 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 111172 : OUString AttributeList::getValueByIndex(sal_Int16 i) throw (RuntimeException)
94 : {
95 111172 : if( std::vector< TagAttribute >::size_type(i) < m_pImpl->vecAttribute.size() ) {
96 111172 : 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 16691 : OUString AttributeList::getValueByName(const OUString& sName) throw (RuntimeException)
117 : {
118 16691 : vector<struct TagAttribute>::iterator ii = m_pImpl->vecAttribute.begin();
119 :
120 33647 : for (; ii != m_pImpl->vecAttribute.end(); ++ii)
121 : {
122 31501 : if( (*ii).sName == sName )
123 : {
124 14545 : return (*ii).sValue;
125 : }
126 : }
127 2146 : return OUString();
128 : }
129 :
130 :
131 72 : Reference< XCloneable > AttributeList::createClone() throw (RuntimeException)
132 : {
133 72 : AttributeList *p = new AttributeList( *this );
134 72 : return Reference< XCloneable > ( (XCloneable * ) p );
135 : }
136 :
137 :
138 :
139 2793 : AttributeList::AttributeList()
140 : {
141 2793 : m_pImpl = new AttributeList_impl;
142 2793 : }
143 :
144 :
145 :
146 8595 : AttributeList::~AttributeList()
147 : {
148 2865 : delete m_pImpl;
149 5730 : }
150 :
151 :
152 104012 : void AttributeList::addAttribute( const OUString &sName ,
153 : const OUString &sType ,
154 : const OUString &sValue )
155 : {
156 104012 : m_pImpl->vecAttribute.push_back( TagAttribute( sName , sType , sValue ) );
157 104012 : }
158 :
159 55350 : void AttributeList::clear()
160 : {
161 55350 : m_pImpl->vecAttribute.clear();
162 55350 : }
163 :
164 : }
165 :
166 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|