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 3480 : struct TagAttribute_Impl
33 : {
34 : TagAttribute_Impl(){}
35 1160 : TagAttribute_Impl( const OUString &aName, const OUString &aType,
36 : const OUString &aValue )
37 1160 : {
38 1160 : this->sName = aName;
39 1160 : this->sType = aType;
40 1160 : this->sValue = aValue;
41 1160 : }
42 :
43 : OUString sName;
44 : OUString sType;
45 : OUString sValue;
46 : };
47 :
48 531 : struct AttributeList_Impl
49 : {
50 531 : AttributeList_Impl()
51 531 : {
52 : // performance improvement during adding
53 531 : vecAttribute.reserve(20);
54 531 : }
55 : ::std::vector<struct TagAttribute_Impl> vecAttribute;
56 : };
57 :
58 531 : sal_Int16 SAL_CALL AttributeList::getLength(void) throw( ::com::sun::star::uno::RuntimeException )
59 : {
60 531 : return (sal_Int16)(m_pImpl->vecAttribute.size());
61 : }
62 :
63 1160 : OUString SAL_CALL AttributeList::getNameByIndex(sal_Int16 i) throw( ::com::sun::star::uno::RuntimeException )
64 : {
65 1160 : 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 1132 : OUString SAL_CALL AttributeList::getValueByIndex(sal_Int16 i) throw( ::com::sun::star::uno::RuntimeException )
77 : {
78 1132 : 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 531 : AttributeList::AttributeList()
107 : {
108 531 : m_pImpl = new AttributeList_Impl;
109 531 : }
110 :
111 :
112 :
113 1593 : AttributeList::~AttributeList()
114 : {
115 531 : delete m_pImpl;
116 1062 : }
117 :
118 1160 : void AttributeList::AddAttribute( const OUString &sName ,
119 : const OUString &sType ,
120 : const OUString &sValue )
121 : {
122 1160 : m_pImpl->vecAttribute.push_back( TagAttribute_Impl( sName , sType , sValue ) );
123 1160 : }
124 :
125 : } // namespace comphelper
126 :
127 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|