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"
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
) );
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
) );
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
)
44 aAttrs
.push_back( SvXMLAttr(nPos
, rLName
, rValue
) );
48 bool SvXMLAttrCollection::SetAt( size_t i
,
49 const OUString
& rLName
,
50 const OUString
& rValue
)
52 if( i
>= GetAttrCount() )
54 aAttrs
[i
] = SvXMLAttr(rLName
, rValue
);
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() )
67 sal_uInt16 nPos
= aNamespaceMap
.Add( rPrefix
, rNamespace
);
68 if( USHRT_MAX
== nPos
)
71 aAttrs
[i
] = SvXMLAttr(nPos
, rLName
, rValue
);
75 bool SvXMLAttrCollection::SetAt( size_t i
,
76 const OUString
& rPrefix
,
77 const OUString
& rLName
,
78 const OUString
& rValue
)
80 if( i
>= GetAttrCount() )
83 sal_uInt16 nPos
= aNamespaceMap
.GetIndexByPrefix( rPrefix
);
84 if( USHRT_MAX
== nPos
)
87 aAttrs
[i
] = SvXMLAttr(nPos
, rLName
, rValue
);
91 void SvXMLAttrCollection::Remove( size_t i
)
93 if( i
< GetAttrCount() )
95 aAttrs
.erase( aAttrs
.begin() + i
);
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
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
);
130 const OUString
SvXMLAttrCollection::GetAttrPrefix( size_t i
) const
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
);
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: */