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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <comphelper/propertysetinfo.hxx>
22 #include <comphelper/sequence.hxx>
25 using namespace ::comphelper
;
26 using namespace ::com::sun::star
;
27 using namespace ::com::sun::star::uno
;
28 using namespace ::com::sun::star::beans
;
30 PropertySetInfo::PropertySetInfo() noexcept
34 PropertySetInfo::PropertySetInfo( std::span
<const PropertyMapEntry
> pMap
) noexcept
36 maPropertyMap
.reserve(pMap
.size());
37 for (const auto & rEntry
: pMap
)
39 // check for duplicates
40 assert(!maPropertyMap
.contains(rEntry
.maName
));
41 // Make sure there are no accidental empty entries left at the end of the array from
42 // when this method used to take a empty-terminated array.
43 assert(!rEntry
.maName
.isEmpty());
45 maPropertyMap
.emplace(rEntry
.maName
, &rEntry
);
49 PropertySetInfo::~PropertySetInfo() noexcept
53 void PropertySetInfo::add( std::span
<PropertyMapEntry
const> pMap
) noexcept
55 maPropertyMap
.reserve(maPropertyMap
.size() + pMap
.size());
56 for (const auto & rEntry
: pMap
)
58 // check for duplicates
59 assert(!maPropertyMap
.contains(rEntry
.maName
));
60 // Make sure there are no accidental empty entries left at the end of the array from
61 // when this method used to take a empty-terminated array.
62 assert(!rEntry
.maName
.isEmpty());
64 maPropertyMap
.emplace(rEntry
.maName
, &rEntry
);
68 maProperties
.realloc(0);
71 void PropertySetInfo::remove( const OUString
& aName
) noexcept
73 maPropertyMap
.erase( aName
);
74 maProperties
.realloc(0);
77 Sequence
< css::beans::Property
> SAL_CALL
PropertySetInfo::getProperties()
79 // maybe we have to generate the properties after
80 // a change in the property map or at first call
82 if( maProperties
.size() != maPropertyMap
.size() )
84 maProperties
.realloc( maPropertyMap
.size() );
85 auto propIter
= maProperties
.getArray();
87 for( const auto& rProperty
: maPropertyMap
)
89 PropertyMapEntry
const * pEntry
= rProperty
.second
;
91 propIter
->Name
= pEntry
->maName
;
92 propIter
->Handle
= pEntry
->mnHandle
;
93 propIter
->Type
= pEntry
->maType
;
94 propIter
->Attributes
= pEntry
->mnAttributes
;
102 Property SAL_CALL
PropertySetInfo::getPropertyByName( const OUString
& aName
)
104 PropertyMap::iterator aIter
= maPropertyMap
.find( aName
);
106 if( maPropertyMap
.end() == aIter
)
107 throw UnknownPropertyException( aName
);
109 PropertyMapEntry
const * pEntry
= (*aIter
).second
;
111 return Property( aName
, pEntry
->mnHandle
, pEntry
->maType
, pEntry
->mnAttributes
);
114 sal_Bool SAL_CALL
PropertySetInfo::hasPropertyByName( const OUString
& aName
)
116 return maPropertyMap
.contains( aName
);
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */