LibreOffice Module comphelper (master) 1
propertysetinfo.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
23
24
25using namespace ::comphelper;
26using namespace ::com::sun::star;
27using namespace ::com::sun::star::uno;
28using namespace ::com::sun::star::beans;
29using namespace ::com::sun::star::lang;
30
31PropertySetInfo::PropertySetInfo() noexcept
32{
33}
34
35PropertySetInfo::PropertySetInfo( o3tl::span<const PropertyMapEntry> pMap ) noexcept
36{
37 maPropertyMap.reserve(pMap.size());
38 for (const auto & rEntry : pMap)
39 {
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());
45
46 maPropertyMap.emplace(rEntry.maName, &rEntry);
47 }
48}
49
50PropertySetInfo::~PropertySetInfo() noexcept
51{
52}
53
54void PropertySetInfo::add( o3tl::span<PropertyMapEntry const> pMap ) noexcept
55{
56 maPropertyMap.reserve(maPropertyMap.size() + pMap.size());
57 for (const auto & rEntry : pMap)
58 {
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());
64
65 maPropertyMap.emplace(rEntry.maName, &rEntry);
66 }
67
68 // clear cache
69 maProperties.realloc(0);
70}
71
72void PropertySetInfo::remove( const OUString& aName ) noexcept
73{
74 maPropertyMap.erase( aName );
75 maProperties.realloc(0);
76}
77
78Sequence< css::beans::Property > SAL_CALL PropertySetInfo::getProperties()
79{
80 // maybe we have to generate the properties after
81 // a change in the property map or at first call
82 // to getProperties
83 if( maProperties.size() != maPropertyMap.size() )
84 {
85 maProperties.realloc( maPropertyMap.size() );
86 auto propIter = maProperties.getArray();
87
88 for( const auto& rProperty : maPropertyMap )
89 {
90 PropertyMapEntry const * pEntry = rProperty.second;
91
92 propIter->Name = pEntry->maName;
93 propIter->Handle = pEntry->mnHandle;
94 propIter->Type = pEntry->maType;
95 propIter->Attributes = pEntry->mnAttributes;
96
97 ++propIter;
98 }
99 }
100 return maProperties;
101}
102
103Property SAL_CALL PropertySetInfo::getPropertyByName( const OUString& aName )
104{
105 PropertyMap::iterator aIter = maPropertyMap.find( aName );
106
107 if( maPropertyMap.end() == aIter )
108 throw UnknownPropertyException( aName );
109
110 PropertyMapEntry const * pEntry = (*aIter).second;
111
112 return Property( aName, pEntry->mnHandle, pEntry->maType, pEntry->mnAttributes );
113}
114
115sal_Bool SAL_CALL PropertySetInfo::hasPropertyByName( const OUString& aName )
116{
117 return maPropertyMap.find( aName ) != maPropertyMap.end();
118}
119
120/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString aName
SvGenericNameContainerMapImpl maProperties
OUStringBuffer & remove(OUStringBuffer &rIn, sal_Unicode c)
Removes all occurrences of a character from within the source string.
Definition: string.hxx:49
std::pair< OUString const, DataAccessDescriptorProperty > PropertyMapEntry
sal_Int16 mnAttributes
flag bitmap,
unsigned char sal_Bool