bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / core / SvXMLAttrCollection.cxx
blob8f1ad5c862ae1a7b5ff9abed2505f446370c5c0c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include "SvXMLAttrCollection.hxx"
11 #include <limits.h>
12 #include <osl/diagnose.h>
14 bool SvXMLAttrCollection::operator ==( const SvXMLAttrCollection& rCmp ) const
16 return (rCmp.aNamespaceMap == aNamespaceMap) &&
17 (rCmp.aAttrs == aAttrs);
20 bool SvXMLAttrCollection::AddAttr( const OUString& rLName,
21 const OUString& rValue )
23 aAttrs.push_back( SvXMLAttr(rLName, rValue) );
24 return true;
27 bool SvXMLAttrCollection::AddAttr( const OUString& rPrefix,
28 const OUString& rNamespace,
29 const OUString& rLName,
30 const OUString& rValue )
32 sal_uInt16 nPos = aNamespaceMap.Add( rPrefix, rNamespace );
33 aAttrs.push_back( SvXMLAttr(nPos, rLName, rValue) );
34 return true;
37 bool SvXMLAttrCollection::AddAttr( const OUString& rPrefix,
38 const OUString& rLName,
39 const OUString& rValue )
41 sal_uInt16 nPos = aNamespaceMap.GetIndexByPrefix( rPrefix );
42 if( USHRT_MAX == nPos )
43 return false;
44 aAttrs.push_back( SvXMLAttr(nPos, rLName, rValue) );
45 return true;
48 bool SvXMLAttrCollection::SetAt( size_t i,
49 const OUString& rLName,
50 const OUString& rValue )
52 if( i >= GetAttrCount() )
53 return false;
54 aAttrs[i] = SvXMLAttr(rLName, rValue);
55 return true;
58 bool SvXMLAttrCollection::SetAt( size_t i,
59 const OUString& rPrefix,
60 const OUString& rNamespace,
61 const OUString& rLName,
62 const OUString& rValue )
64 if( i >= GetAttrCount() )
65 return false;
67 sal_uInt16 nPos = aNamespaceMap.Add( rPrefix, rNamespace );
68 if( USHRT_MAX == nPos )
69 return false;
71 aAttrs[i] = SvXMLAttr(nPos, rLName, rValue);
72 return true;
75 bool SvXMLAttrCollection::SetAt( size_t i,
76 const OUString& rPrefix,
77 const OUString& rLName,
78 const OUString& rValue )
80 if( i >= GetAttrCount() )
81 return false;
83 sal_uInt16 nPos = aNamespaceMap.GetIndexByPrefix( rPrefix );
84 if( USHRT_MAX == nPos )
85 return false;
87 aAttrs[i] = SvXMLAttr(nPos, rLName, rValue);
88 return true;
91 void SvXMLAttrCollection::Remove( size_t i )
93 if( i < GetAttrCount() )
95 aAttrs.erase( aAttrs.begin() + i );
97 else
99 OSL_FAIL( "illegal index" );
103 size_t SvXMLAttrCollection::GetAttrCount() const
105 return aAttrs.size();
108 const OUString& SvXMLAttrCollection::GetAttrLName(size_t i) const
110 OSL_ENSURE( i < aAttrs.size(), "SvXMLAttrContainerData::GetLName: illegal index" );
111 return aAttrs[i].getLName();
114 const OUString& SvXMLAttrCollection::GetAttrValue(size_t i) const
116 OSL_ENSURE( i < aAttrs.size(), "SvXMLAttrContainerData::GetValue: illegal index" );
117 return aAttrs[i].getValue();
120 const OUString SvXMLAttrCollection::GetAttrNamespace( size_t i ) const
122 OUString sRet;
123 sal_uInt16 nPos = GetPrefixPos( i );
124 //Does this point to a valid namespace entry?
125 if( USHRT_MAX != nPos )
126 sRet = aNamespaceMap.GetNameByIndex( nPos );
127 return sRet;
130 const OUString SvXMLAttrCollection::GetAttrPrefix( size_t i ) const
132 OUString sRet;
133 sal_uInt16 nPos = GetPrefixPos( i );
134 //Does this point to a valid namespace entry?
135 if( USHRT_MAX != nPos )
136 sRet = aNamespaceMap.GetPrefixByIndex( nPos );
137 return sRet;
140 const OUString& SvXMLAttrCollection::GetNamespace( sal_uInt16 i ) const
142 return aNamespaceMap.GetNameByIndex( i );
145 const OUString& SvXMLAttrCollection::GetPrefix( sal_uInt16 i ) const
147 return aNamespaceMap.GetPrefixByIndex( i );
150 sal_uInt16 SvXMLAttrCollection::GetFirstNamespaceIndex() const
152 return aNamespaceMap.GetFirstIndex();
155 sal_uInt16 SvXMLAttrCollection::GetNextNamespaceIndex( sal_uInt16 nIdx ) const
157 return aNamespaceMap.GetNextIndex( nIdx );
160 sal_uInt16 SvXMLAttrCollection::GetPrefixPos( size_t i ) const
162 // DBG_ASSERT( i >= 0 && i < aAttrs.size(),
163 // "SvXMLAttrCollection::GetPrefixPos: illegal index" );
164 return aAttrs[i].getPrefixPos();
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */