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
;
29 using namespace ::com::sun::star::lang
;
31 PropertySetInfo::PropertySetInfo() noexcept
35 PropertySetInfo::PropertySetInfo( o3tl::span
<const PropertyMapEntry
> pMap
) noexcept
37 maPropertyMap
.reserve(pMap
.size());
38 for (const auto & rEntry
: pMap
)
40 // check for duplicates
41 assert(maPropertyMap
.find(rEntry
.maName
) == maPropertyMap
.end());
42 // Make sure there are no accidental empty entries left at the end of the array from
43 // when this method used to take a empty-terminated array.
44 assert(!rEntry
.maName
.isEmpty());
46 maPropertyMap
.emplace(rEntry
.maName
, &rEntry
);
50 PropertySetInfo::~PropertySetInfo() noexcept
54 void PropertySetInfo::add( o3tl::span
<PropertyMapEntry
const> pMap
) noexcept
56 maPropertyMap
.reserve(maPropertyMap
.size() + pMap
.size());
57 for (const auto & rEntry
: pMap
)
59 // check for duplicates
60 assert(maPropertyMap
.find(rEntry
.maName
) == maPropertyMap
.end());
61 // Make sure there are no accidental empty entries left at the end of the array from
62 // when this method used to take a empty-terminated array.
63 assert(!rEntry
.maName
.isEmpty());
65 maPropertyMap
.emplace(rEntry
.maName
, &rEntry
);
69 maProperties
.realloc(0);
72 void PropertySetInfo::remove( const OUString
& aName
) noexcept
74 maPropertyMap
.erase( aName
);
75 maProperties
.realloc(0);
78 Sequence
< css::beans::Property
> SAL_CALL
PropertySetInfo::getProperties()
80 // maybe we have to generate the properties after
81 // a change in the property map or at first call
83 if( maProperties
.size() != maPropertyMap
.size() )
85 maProperties
.realloc( maPropertyMap
.size() );
86 auto propIter
= maProperties
.getArray();
88 for( const auto& rProperty
: maPropertyMap
)
90 PropertyMapEntry
const * pEntry
= rProperty
.second
;
92 propIter
->Name
= pEntry
->maName
;
93 propIter
->Handle
= pEntry
->mnHandle
;
94 propIter
->Type
= pEntry
->maType
;
95 propIter
->Attributes
= pEntry
->mnAttributes
;
103 Property SAL_CALL
PropertySetInfo::getPropertyByName( const OUString
& aName
)
105 PropertyMap::iterator aIter
= maPropertyMap
.find( aName
);
107 if( maPropertyMap
.end() == aIter
)
108 throw UnknownPropertyException( aName
);
110 PropertyMapEntry
const * pEntry
= (*aIter
).second
;
112 return Property( aName
, pEntry
->mnHandle
, pEntry
->maType
, pEntry
->mnAttributes
);
115 sal_Bool SAL_CALL
PropertySetInfo::hasPropertyByName( const OUString
& aName
)
117 return maPropertyMap
.find( aName
) != maPropertyMap
.end();
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */