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