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 <comphelper/attributelist.hxx>
21 : #include <osl/diagnose.h>
22 :
23 : #include <vector>
24 :
25 : using namespace osl;
26 : using namespace com::sun::star;
27 :
28 :
29 : namespace comphelper {
30 :
31 691120 : struct TagAttribute_Impl
32 : {
33 230320 : TagAttribute_Impl( const OUString &aName, const OUString &aType,
34 : const OUString &aValue )
35 230320 : {
36 230320 : this->sName = aName;
37 230320 : this->sType = aType;
38 230320 : this->sValue = aValue;
39 230320 : }
40 :
41 : OUString sName;
42 : OUString sType;
43 : OUString sValue;
44 : };
45 :
46 163644 : struct AttributeList_Impl
47 : {
48 163644 : AttributeList_Impl()
49 163644 : {
50 : // performance improvement during adding
51 163644 : vecAttribute.reserve(20);
52 163644 : }
53 : ::std::vector<struct TagAttribute_Impl> vecAttribute;
54 : };
55 :
56 188494 : sal_Int16 SAL_CALL AttributeList::getLength() throw( ::com::sun::star::uno::RuntimeException, std::exception )
57 : {
58 188494 : return (sal_Int16)(m_pImpl->vecAttribute.size());
59 : }
60 :
61 230254 : OUString SAL_CALL AttributeList::getNameByIndex(sal_Int16 i) throw( ::com::sun::star::uno::RuntimeException, std::exception )
62 : {
63 230254 : return ( i < static_cast < sal_Int16 > (m_pImpl->vecAttribute.size()) ) ? m_pImpl->vecAttribute[i].sName : OUString();
64 : }
65 :
66 0 : OUString SAL_CALL AttributeList::getTypeByIndex(sal_Int16 i) throw( ::com::sun::star::uno::RuntimeException, std::exception )
67 : {
68 0 : if( i < static_cast < sal_Int16 > (m_pImpl->vecAttribute.size() ) ) {
69 0 : return m_pImpl->vecAttribute[i].sType;
70 : }
71 0 : return OUString();
72 : }
73 :
74 229483 : OUString SAL_CALL AttributeList::getValueByIndex(sal_Int16 i) throw( ::com::sun::star::uno::RuntimeException, std::exception )
75 : {
76 229483 : return ( i < static_cast < sal_Int16 > (m_pImpl->vecAttribute.size() ) ) ? m_pImpl->vecAttribute[i].sValue : OUString();
77 : }
78 :
79 0 : OUString SAL_CALL AttributeList::getTypeByName( const OUString& sName ) throw( ::com::sun::star::uno::RuntimeException, std::exception )
80 : {
81 0 : ::std::vector<struct TagAttribute_Impl>::iterator ii = m_pImpl->vecAttribute.begin();
82 :
83 0 : for( ; ii != m_pImpl->vecAttribute.end() ; ++ii ) {
84 0 : if( (*ii).sName == sName ) {
85 0 : return (*ii).sType;
86 : }
87 : }
88 0 : return OUString();
89 : }
90 :
91 0 : OUString SAL_CALL AttributeList::getValueByName(const OUString& sName) throw( ::com::sun::star::uno::RuntimeException, std::exception )
92 : {
93 0 : ::std::vector<struct TagAttribute_Impl>::iterator ii = m_pImpl->vecAttribute.begin();
94 :
95 0 : for( ; ii != m_pImpl->vecAttribute.end() ; ++ii ) {
96 0 : if( (*ii).sName == sName ) {
97 0 : return (*ii).sValue;
98 : }
99 : }
100 0 : return OUString();
101 : }
102 :
103 :
104 163644 : AttributeList::AttributeList()
105 : {
106 163644 : m_pImpl = new AttributeList_Impl;
107 163644 : }
108 :
109 :
110 :
111 490932 : AttributeList::~AttributeList()
112 : {
113 163644 : delete m_pImpl;
114 327288 : }
115 :
116 230320 : void AttributeList::AddAttribute( const OUString &sName ,
117 : const OUString &sType ,
118 : const OUString &sValue )
119 : {
120 230320 : m_pImpl->vecAttribute.push_back( TagAttribute_Impl( sName , sType , sValue ) );
121 230320 : }
122 :
123 : } // namespace comphelper
124 :
125 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|