1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include "SvXMLAttrCollection.hxx"
11 #include <limits.h> //USHRT_MAX
13 bool SvXMLAttrCollection::operator ==( const SvXMLAttrCollection
& rCmp
) const
15 return (rCmp
.aNamespaceMap
== aNamespaceMap
) &&
16 (rCmp
.aAttrs
== aAttrs
);
19 sal_Bool
SvXMLAttrCollection::AddAttr( const OUString
& rLName
,
20 const OUString
& rValue
)
22 aAttrs
.push_back( SvXMLAttr(rLName
, rValue
) );
26 sal_Bool
SvXMLAttrCollection::AddAttr( const OUString
& rPrefix
,
27 const OUString
& rNamespace
,
28 const OUString
& rLName
,
29 const OUString
& rValue
)
31 sal_uInt16 nPos
= aNamespaceMap
.Add( rPrefix
, rNamespace
);
32 aAttrs
.push_back( SvXMLAttr(nPos
, rLName
, rValue
) );
36 sal_Bool
SvXMLAttrCollection::AddAttr( const OUString
& rPrefix
,
37 const OUString
& rLName
,
38 const OUString
& rValue
)
40 sal_uInt16 nPos
= aNamespaceMap
.GetIndexByPrefix( rPrefix
);
41 if( USHRT_MAX
== nPos
)
43 aAttrs
.push_back( SvXMLAttr(nPos
, rLName
, rValue
) );
47 sal_Bool
SvXMLAttrCollection::SetAt( size_t i
,
48 const OUString
& rLName
,
49 const OUString
& rValue
)
51 if( i
>= GetAttrCount() )
53 aAttrs
[i
] = SvXMLAttr(rLName
, rValue
);
57 sal_Bool
SvXMLAttrCollection::SetAt( size_t i
,
58 const OUString
& rPrefix
,
59 const OUString
& rNamespace
,
60 const OUString
& rLName
,
61 const OUString
& rValue
)
63 if( i
>= GetAttrCount() )
66 sal_uInt16 nPos
= aNamespaceMap
.Add( rPrefix
, rNamespace
);
67 if( USHRT_MAX
== nPos
)
70 aAttrs
[i
] = SvXMLAttr(nPos
, rLName
, rValue
);
74 sal_Bool
SvXMLAttrCollection::SetAt( size_t i
,
75 const OUString
& rPrefix
,
76 const OUString
& rLName
,
77 const OUString
& rValue
)
79 if( i
>= GetAttrCount() )
82 sal_uInt16 nPos
= aNamespaceMap
.GetIndexByPrefix( rPrefix
);
83 if( USHRT_MAX
== nPos
)
86 aAttrs
[i
] = SvXMLAttr(nPos
, rLName
, rValue
);
90 void SvXMLAttrCollection::Remove( size_t i
)
92 if( i
< GetAttrCount() )
94 aAttrs
.erase( aAttrs
.begin() + i
);
98 OSL_FAIL( "illegal index" );
102 size_t SvXMLAttrCollection::GetAttrCount() const
104 return aAttrs
.size();
107 const OUString
& SvXMLAttrCollection::GetAttrLName(size_t i
) const
109 OSL_ENSURE( i
< aAttrs
.size(), "SvXMLAttrContainerData::GetLName: illegal index" );
110 return aAttrs
[i
].getLName();
113 const OUString
& SvXMLAttrCollection::GetAttrValue(size_t i
) const
115 OSL_ENSURE( i
< aAttrs
.size(), "SvXMLAttrContainerData::GetValue: illegal index" );
116 return aAttrs
[i
].getValue();
119 const OUString
SvXMLAttrCollection::GetAttrNamespace( size_t i
) const
122 sal_uInt16 nPos
= GetPrefixPos( i
);
123 //Does this point to a valid namespace entry?
124 if( USHRT_MAX
!= nPos
)
125 sRet
= aNamespaceMap
.GetNameByIndex( nPos
);
129 const OUString
SvXMLAttrCollection::GetAttrPrefix( size_t i
) const
132 sal_uInt16 nPos
= GetPrefixPos( i
);
133 //Does this point to a valid namespace entry?
134 if( USHRT_MAX
!= nPos
)
135 sRet
= aNamespaceMap
.GetPrefixByIndex( nPos
);
139 const OUString
& SvXMLAttrCollection::GetNamespace( sal_uInt16 i
) const
141 return aNamespaceMap
.GetNameByIndex( i
);
144 const OUString
& SvXMLAttrCollection::GetPrefix( sal_uInt16 i
) const
146 return aNamespaceMap
.GetPrefixByIndex( i
);
149 sal_uInt16
SvXMLAttrCollection::GetFirstNamespaceIndex() const
151 return aNamespaceMap
.GetFirstIndex();
154 sal_uInt16
SvXMLAttrCollection::GetNextNamespaceIndex( sal_uInt16 nIdx
) const
156 return aNamespaceMap
.GetNextIndex( nIdx
);
159 sal_uInt16
SvXMLAttrCollection::GetPrefixPos( size_t i
) const
161 // DBG_ASSERT( i >= 0 && i < aAttrs.size(),
162 // "SvXMLAttrCollection::GetPrefixPos: illegal index" );
163 return aAttrs
[i
].getPrefixPos();
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */