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 :
21 : #include <assert.h>
22 : #include <vector>
23 : #include "attributes.hxx"
24 :
25 0 : struct TagAttribute
26 : {
27 : TagAttribute(){}
28 0 : TagAttribute( const OUString &rName, const OUString &rType , const OUString &rValue )
29 0 : {
30 0 : sName = rName;
31 0 : sType = rType;
32 0 : sValue = rValue;
33 0 : }
34 :
35 : OUString sName;
36 : OUString sType;
37 : OUString sValue;
38 : };
39 :
40 0 : struct AttributeListImpl_impl
41 : {
42 0 : AttributeListImpl_impl()
43 0 : {
44 : // performance improvement during adding
45 0 : vecAttribute.reserve(20);
46 0 : }
47 : std::vector<struct TagAttribute> vecAttribute;
48 : };
49 :
50 0 : sal_Int16 SAL_CALL AttributeListImpl::getLength(void) throw (RuntimeException, std::exception)
51 : {
52 0 : return (sal_Int16)m_pImpl->vecAttribute.size();
53 : }
54 :
55 :
56 0 : AttributeListImpl::AttributeListImpl( const AttributeListImpl &r ) :
57 0 : cppu::WeakImplHelper1<com::sun::star::xml::sax::XAttributeList>( r )
58 : {
59 0 : m_pImpl = new AttributeListImpl_impl;
60 0 : *m_pImpl = *(r.m_pImpl);
61 0 : }
62 :
63 :
64 0 : OUString AttributeListImpl::getNameByIndex(sal_Int16 i) throw (RuntimeException, std::exception)
65 : {
66 0 : sal_uInt32 i2 = sal::static_int_cast<sal_Int16>(i);
67 0 : if( i >= 0 && i2 < m_pImpl->vecAttribute.size() )
68 : {
69 0 : return m_pImpl->vecAttribute[i].sName;
70 : }
71 0 : return OUString();
72 : }
73 :
74 :
75 0 : OUString AttributeListImpl::getTypeByIndex(sal_Int16 i) throw (RuntimeException, std::exception)
76 : {
77 0 : sal_uInt32 i2 = sal::static_int_cast<sal_Int16>(i);
78 0 : if( i >= 0 && i2 < m_pImpl->vecAttribute.size() )
79 : {
80 0 : return m_pImpl->vecAttribute[i].sType;
81 : }
82 0 : return OUString();
83 : }
84 :
85 :
86 0 : OUString AttributeListImpl::getValueByIndex(sal_Int16 i) throw (RuntimeException, std::exception)
87 : {
88 0 : sal_uInt32 i2 = sal::static_int_cast<sal_Int16>(i);
89 0 : if( i >= 0 && i2 < m_pImpl->vecAttribute.size() )
90 : {
91 0 : return m_pImpl->vecAttribute[i].sValue;
92 : }
93 0 : return OUString();
94 :
95 : }
96 :
97 :
98 0 : OUString AttributeListImpl::getTypeByName( const OUString& sName ) throw (RuntimeException, std::exception)
99 : {
100 0 : std::vector<struct TagAttribute>::iterator ii = m_pImpl->vecAttribute.begin();
101 :
102 0 : for (; ii != m_pImpl->vecAttribute.end(); ++ii)
103 : {
104 0 : if( (*ii).sName == sName )
105 : {
106 0 : return (*ii).sType;
107 : }
108 : }
109 0 : return OUString();
110 : }
111 :
112 :
113 0 : OUString AttributeListImpl::getValueByName(const OUString& sName) throw (RuntimeException, std::exception)
114 : {
115 0 : std::vector<struct TagAttribute>::iterator ii = m_pImpl->vecAttribute.begin();
116 :
117 0 : for (; ii != m_pImpl->vecAttribute.end(); ++ii)
118 : {
119 0 : if( (*ii).sName == sName )
120 : {
121 0 : return (*ii).sValue;
122 : }
123 : }
124 0 : return OUString();
125 : }
126 :
127 :
128 0 : AttributeListImpl::AttributeListImpl()
129 : {
130 0 : m_pImpl = new AttributeListImpl_impl;
131 0 : }
132 :
133 :
134 0 : AttributeListImpl::~AttributeListImpl()
135 : {
136 0 : delete m_pImpl;
137 0 : }
138 :
139 :
140 0 : void AttributeListImpl::addAttribute( const OUString &sName ,
141 : const OUString &sType ,
142 : const OUString &sValue )
143 : {
144 0 : m_pImpl->vecAttribute.push_back( TagAttribute( sName , sType , sValue ) );
145 0 : }
146 :
147 :
148 0 : void AttributeListImpl::clear()
149 : {
150 0 : std::vector<struct TagAttribute> dummy;
151 0 : m_pImpl->vecAttribute.swap( dummy );
152 :
153 0 : assert( ! getLength() );
154 0 : }
155 :
156 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|