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