LibreOffice Module comphelper (master) 1
MasterPropertySetInfo.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
21#include <sal/log.hxx>
22
23using ::comphelper::PropertyInfo;
24using ::comphelper::MasterPropertySetInfo;
25using ::com::sun::star::uno::Sequence;
26using ::com::sun::star::beans::Property;
27using ::com::sun::star::beans::UnknownPropertyException;
28
29MasterPropertySetInfo::MasterPropertySetInfo( PropertyInfo const * pMap )
30{
31 for ( ; !pMap->maName.isEmpty(); ++pMap )
32 {
34 maMap.find(pMap->maName) != maMap.end(),
35 "comphelper", "Duplicate property name \"" << pMap->maName << "\"");
36 maMap[pMap->maName] = new PropertyData ( 0, pMap );
37 }
38}
39
40MasterPropertySetInfo::~MasterPropertySetInfo()
41 noexcept
42{
43 for( const auto& rObj : maMap )
44 delete rObj.second;
45}
46
47void MasterPropertySetInfo::add( PropertyInfoHash &rHash, sal_uInt8 nMapId )
48{
49 if( maProperties.hasElements() )
50 maProperties.realloc( 0 );
51
52 for( const auto& rObj : rHash )
53 {
55 maMap.find(rObj.first) != maMap.end(),
56 "comphelper", "Duplicate property name \"" << rObj.first << "\"");
57 maMap[rObj.first] = new PropertyData ( nMapId, rObj.second );
58 }
59}
60
61Sequence< ::Property > SAL_CALL MasterPropertySetInfo::getProperties()
62{
63 sal_Int32 nSize = maMap.size();
64 if( maProperties.getLength() != nSize )
65 {
66 maProperties.realloc ( nSize );
67 Property* pProperties = maProperties.getArray();
68
69 for (auto const& elem : maMap)
70 {
71 PropertyInfo const * pInfo = elem.second->mpInfo;
72
73 pProperties->Name = pInfo->maName;
74 pProperties->Handle = pInfo->mnHandle;
75 pProperties->Type = pInfo->maType;
76 pProperties->Attributes = pInfo->mnAttributes;
77 ++pProperties;
78 }
79 }
80 return maProperties;
81}
82
83Property SAL_CALL MasterPropertySetInfo::getPropertyByName( const OUString& rName )
84{
85 PropertyDataHash::iterator aIter = maMap.find( rName );
86
87 if ( maMap.end() == aIter )
88 throw UnknownPropertyException( rName, *this );
89
90 PropertyInfo const *pInfo = (*aIter).second->mpInfo;
91 Property aProperty;
92 aProperty.Name = pInfo->maName;
93 aProperty.Handle = pInfo->mnHandle;
94 aProperty.Type = pInfo->maType;
95
96 aProperty.Attributes = pInfo->mnAttributes;
97 return aProperty;
98}
99
100sal_Bool SAL_CALL MasterPropertySetInfo::hasPropertyByName( const OUString& rName )
101{
102 return maMap.find ( rName ) != maMap.end();
103}
104
105/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unordered_map< OUString, ::comphelper::PropertyInfo const * > PropertyInfoHash
#define SAL_WARN_IF(condition, area, stream)
SvGenericNameContainerMapImpl maProperties
unsigned char sal_uInt8
unsigned char sal_Bool