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 assert(!rLName
.isEmpty());
24 aAttrs
.emplace_back(rLName
, rValue
);
28 bool SvXMLAttrCollection::AddAttr( const OUString
& rPrefix
,
29 const OUString
& rNamespace
,
30 const OUString
& rLName
,
31 const OUString
& rValue
)
33 assert(!rPrefix
.isEmpty());
34 assert(!rNamespace
.isEmpty());
35 assert(!rLName
.isEmpty());
36 sal_uInt16 nPos
= aNamespaceMap
.Add( rPrefix
, rNamespace
);
37 aAttrs
.emplace_back(nPos
, rLName
, rValue
);
41 bool SvXMLAttrCollection::AddAttr( const OUString
& rPrefix
,
42 const OUString
& rLName
,
43 const OUString
& rValue
)
45 assert(!rPrefix
.isEmpty());
46 assert(!rLName
.isEmpty());
47 sal_uInt16 nPos
= aNamespaceMap
.GetIndexByPrefix( rPrefix
);
48 if( USHRT_MAX
== nPos
)
50 aAttrs
.emplace_back(nPos
, rLName
, rValue
);
54 bool SvXMLAttrCollection::SetAt( size_t i
,
55 const OUString
& rLName
,
56 const OUString
& rValue
)
58 assert(!rLName
.isEmpty());
59 if( i
>= GetAttrCount() )
61 aAttrs
[i
] = SvXMLAttr(rLName
, rValue
);
65 bool SvXMLAttrCollection::SetAt( size_t i
,
66 const OUString
& rPrefix
,
67 const OUString
& rNamespace
,
68 const OUString
& rLName
,
69 const OUString
& rValue
)
71 assert(!rPrefix
.isEmpty());
72 assert(!rNamespace
.isEmpty());
73 assert(!rLName
.isEmpty());
74 if( i
>= GetAttrCount() )
77 sal_uInt16 nPos
= aNamespaceMap
.Add( rPrefix
, rNamespace
);
78 if( USHRT_MAX
== nPos
)
81 aAttrs
[i
] = SvXMLAttr(nPos
, rLName
, rValue
);
85 bool SvXMLAttrCollection::SetAt( size_t i
,
86 const OUString
& rPrefix
,
87 const OUString
& rLName
,
88 const OUString
& rValue
)
90 assert(!rPrefix
.isEmpty());
91 assert(!rLName
.isEmpty());
92 if( i
>= GetAttrCount() )
95 sal_uInt16 nPos
= aNamespaceMap
.GetIndexByPrefix( rPrefix
);
96 if( USHRT_MAX
== nPos
)
99 aAttrs
[i
] = SvXMLAttr(nPos
, rLName
, rValue
);
103 void SvXMLAttrCollection::Remove( size_t i
)
105 if( i
< GetAttrCount() )
107 aAttrs
.erase( aAttrs
.begin() + i
);
111 OSL_FAIL( "illegal index" );
115 size_t SvXMLAttrCollection::GetAttrCount() const
117 return aAttrs
.size();
120 const OUString
& SvXMLAttrCollection::GetAttrLName(size_t i
) const
122 OSL_ENSURE( i
< aAttrs
.size(), "SvXMLAttrContainerData::GetLName: illegal index" );
123 return aAttrs
[i
].getLName();
126 const OUString
& SvXMLAttrCollection::GetAttrValue(size_t i
) const
128 OSL_ENSURE( i
< aAttrs
.size(), "SvXMLAttrContainerData::GetValue: illegal index" );
129 return aAttrs
[i
].getValue();
132 OUString
SvXMLAttrCollection::GetAttrNamespace( size_t i
) const
135 sal_uInt16 nPos
= GetPrefixPos( i
);
136 //Does this point to a valid namespace entry?
137 if( USHRT_MAX
!= nPos
)
138 sRet
= aNamespaceMap
.GetNameByIndex( nPos
);
142 OUString
SvXMLAttrCollection::GetAttrPrefix( size_t i
) const
145 sal_uInt16 nPos
= GetPrefixPos( i
);
146 //Does this point to a valid namespace entry?
147 if( USHRT_MAX
!= nPos
)
148 sRet
= aNamespaceMap
.GetPrefixByIndex( nPos
);
152 const OUString
& SvXMLAttrCollection::GetNamespace( sal_uInt16 i
) const
154 return aNamespaceMap
.GetNameByIndex( i
);
157 const OUString
& SvXMLAttrCollection::GetPrefix( sal_uInt16 i
) const
159 return aNamespaceMap
.GetPrefixByIndex( i
);
162 sal_uInt16
SvXMLAttrCollection::GetFirstNamespaceIndex() const
164 return aNamespaceMap
.GetFirstIndex();
167 sal_uInt16
SvXMLAttrCollection::GetNextNamespaceIndex( sal_uInt16 nIdx
) const
169 return aNamespaceMap
.GetNextIndex( nIdx
);
172 sal_uInt16
SvXMLAttrCollection::GetPrefixPos( size_t i
) const
174 // SAL_WARN_IF( i < 0 || i >= aAttrs.size()), "xmloff",
175 // "SvXMLAttrCollection::GetPrefixPos: illegal index" );
176 return aAttrs
[i
].getPrefixPos();
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */