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 ::cppu;
28 : using namespace ::com::sun::star::uno;
29 : using namespace ::com::sun::star::util;
30 : using namespace ::com::sun::star::xml::sax;
31 :
32 :
33 : namespace sax_expatwrap {
34 3950586 : struct TagAttribute
35 : {
36 1296466 : TagAttribute( const OUString &aName, const OUString &aType , const OUString &aValue )
37 1296466 : {
38 1296466 : this->sName = aName;
39 1296466 : this->sType = aType;
40 1296466 : this->sValue = aValue;
41 1296466 : }
42 :
43 : OUString sName;
44 : OUString sType;
45 : OUString sValue;
46 : };
47 :
48 46099 : struct AttributeList_impl
49 : {
50 45401 : AttributeList_impl()
51 45401 : {
52 : // performance improvement during adding
53 45401 : vecAttribute.reserve(20);
54 45401 : }
55 : vector<struct TagAttribute> vecAttribute;
56 : };
57 :
58 :
59 :
60 787985 : sal_Int16 AttributeList::getLength(void) throw (RuntimeException, std::exception)
61 : {
62 787985 : return static_cast<sal_Int16>(m_pImpl->vecAttribute.size());
63 : }
64 :
65 :
66 698 : AttributeList::AttributeList( const AttributeList &r ) :
67 698 : cppu::WeakImplHelper2<XAttributeList, XCloneable>()
68 : {
69 698 : m_pImpl = new AttributeList_impl;
70 698 : *m_pImpl = *(r.m_pImpl);
71 698 : }
72 :
73 1587837 : OUString AttributeList::getNameByIndex(sal_Int16 i) throw (RuntimeException, std::exception)
74 : {
75 1587837 : if( std::vector< TagAttribute >::size_type(i) < m_pImpl->vecAttribute.size() ) {
76 1587837 : return m_pImpl->vecAttribute[i].sName;
77 : }
78 0 : return OUString();
79 : }
80 :
81 :
82 0 : OUString AttributeList::getTypeByIndex(sal_Int16 i) throw (RuntimeException, std::exception)
83 : {
84 0 : if( std::vector< TagAttribute >::size_type(i) < m_pImpl->vecAttribute.size() ) {
85 0 : return m_pImpl->vecAttribute[i].sType;
86 : }
87 0 : return OUString();
88 : }
89 :
90 974369 : OUString AttributeList::getValueByIndex(sal_Int16 i) throw (RuntimeException, std::exception)
91 : {
92 974369 : if( std::vector< TagAttribute >::size_type(i) < m_pImpl->vecAttribute.size() ) {
93 974369 : return m_pImpl->vecAttribute[i].sValue;
94 : }
95 0 : return OUString();
96 :
97 : }
98 :
99 0 : OUString AttributeList::getTypeByName( const OUString& sName ) throw (RuntimeException, std::exception)
100 : {
101 0 : vector<struct TagAttribute>::iterator ii = m_pImpl->vecAttribute.begin();
102 :
103 0 : for (; ii != m_pImpl->vecAttribute.end(); ++ii )
104 : {
105 0 : if( (*ii).sName == sName )
106 : {
107 0 : return (*ii).sType;
108 : }
109 : }
110 0 : return OUString();
111 : }
112 :
113 504572 : OUString AttributeList::getValueByName(const OUString& sName) throw (RuntimeException, std::exception)
114 : {
115 504572 : vector<struct TagAttribute>::iterator ii = m_pImpl->vecAttribute.begin();
116 :
117 999390 : for (; ii != m_pImpl->vecAttribute.end(); ++ii)
118 : {
119 940450 : if( (*ii).sName == sName )
120 : {
121 445632 : return (*ii).sValue;
122 : }
123 : }
124 58940 : return OUString();
125 : }
126 :
127 :
128 698 : Reference< XCloneable > AttributeList::createClone() throw (RuntimeException, std::exception)
129 : {
130 698 : AttributeList *p = new AttributeList( *this );
131 698 : return Reference< XCloneable > ( (XCloneable * ) p );
132 : }
133 :
134 :
135 :
136 44703 : AttributeList::AttributeList()
137 : {
138 44703 : m_pImpl = new AttributeList_impl;
139 44703 : }
140 :
141 :
142 :
143 136203 : AttributeList::~AttributeList()
144 : {
145 45401 : delete m_pImpl;
146 90802 : }
147 :
148 :
149 1296466 : void AttributeList::addAttribute( const OUString &sName ,
150 : const OUString &sType ,
151 : const OUString &sValue )
152 : {
153 1296466 : m_pImpl->vecAttribute.push_back( TagAttribute( sName , sType , sValue ) );
154 1296466 : }
155 :
156 635208 : void AttributeList::clear()
157 : {
158 635208 : m_pImpl->vecAttribute.clear();
159 635208 : }
160 :
161 : }
162 :
163 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|