Line data Source code
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 : #include <comphelper/MasterPropertySetInfo.hxx>
21 : #include <sal/log.hxx>
22 :
23 : using ::comphelper::PropertyInfo;
24 : using ::comphelper::MasterPropertySetInfo;
25 : using ::com::sun::star::uno::Any;
26 : using ::com::sun::star::uno::Type;
27 : using ::com::sun::star::uno::Sequence;
28 : using ::com::sun::star::uno::Reference;
29 : using ::com::sun::star::uno::XInterface;
30 : using ::com::sun::star::uno::RuntimeException;
31 : using ::com::sun::star::beans::Property;
32 : using ::com::sun::star::beans::XPropertySetInfo;
33 : using ::com::sun::star::beans::UnknownPropertyException;
34 :
35 5838 : MasterPropertySetInfo::MasterPropertySetInfo( PropertyInfo const * pMap )
36 : {
37 385308 : for ( ; !pMap->maName.isEmpty(); ++pMap )
38 : {
39 : SAL_WARN_IF(
40 : maMap.find(pMap->maName) != maMap.end(),
41 : "comphelper", "Duplicate property name \"" << pMap->maName << "\"");
42 379470 : maMap[pMap->maName] = new PropertyData ( 0, pMap );
43 : }
44 5838 : }
45 :
46 11676 : MasterPropertySetInfo::~MasterPropertySetInfo()
47 11676 : throw()
48 : {
49 5838 : PropertyDataHash::iterator aEnd = maMap.end(), aIter = maMap.begin();
50 496230 : while (aIter != aEnd )
51 : {
52 484554 : delete (*aIter).second;
53 484554 : ++aIter;
54 : }
55 11676 : }
56 :
57 5838 : void MasterPropertySetInfo::add( PropertyInfoHash &rHash, sal_uInt8 nMapId )
58 : {
59 5838 : if( maProperties.getLength() )
60 0 : maProperties.realloc( 0 );
61 5838 : PropertyInfoHash::iterator aIter = rHash.begin(), aEnd = rHash.end();
62 :
63 116760 : while ( aIter != aEnd )
64 : {
65 : SAL_WARN_IF(
66 : maMap.find(aIter->first) != maMap.end(),
67 : "comphelper", "Duplicate property name \"" << aIter->first << "\"");
68 105084 : maMap[(*aIter).first] = new PropertyData ( nMapId, (*aIter).second );
69 105084 : ++aIter;
70 : }
71 5838 : }
72 :
73 72 : Sequence< ::Property > SAL_CALL MasterPropertySetInfo::getProperties()
74 : throw(::com::sun::star::uno::RuntimeException, std::exception)
75 : {
76 72 : sal_Int32 nSize = maMap.size();
77 72 : if( maProperties.getLength() != nSize )
78 : {
79 72 : maProperties.realloc ( nSize );
80 72 : Property* pProperties = maProperties.getArray();
81 :
82 6048 : for (PropertyDataHash::const_iterator aIter(maMap.begin()), aEnd(maMap.end()) ; aIter != aEnd; ++aIter, ++pProperties)
83 : {
84 5976 : PropertyInfo const * pInfo = (*aIter).second->mpInfo;
85 :
86 5976 : pProperties->Name = pInfo->maName;
87 5976 : pProperties->Handle = pInfo->mnHandle;
88 5976 : pProperties->Type = pInfo->maType;
89 5976 : pProperties->Attributes = pInfo->mnAttributes;
90 : }
91 : }
92 72 : return maProperties;
93 : }
94 :
95 22 : Property SAL_CALL MasterPropertySetInfo::getPropertyByName( const OUString& rName )
96 : throw(::UnknownPropertyException, ::com::sun::star::uno::RuntimeException, std::exception)
97 : {
98 22 : PropertyDataHash::iterator aIter = maMap.find( rName );
99 :
100 22 : if ( maMap.end() == aIter )
101 0 : throw UnknownPropertyException( rName, *this );
102 :
103 22 : PropertyInfo const *pInfo = (*aIter).second->mpInfo;
104 22 : Property aProperty;
105 22 : aProperty.Name = pInfo->maName;
106 22 : aProperty.Handle = pInfo->mnHandle;
107 22 : aProperty.Type = pInfo->maType;
108 :
109 22 : aProperty.Attributes = pInfo->mnAttributes;
110 22 : return aProperty;
111 : }
112 :
113 21753 : sal_Bool SAL_CALL MasterPropertySetInfo::hasPropertyByName( const OUString& rName )
114 : throw(::com::sun::star::uno::RuntimeException, std::exception)
115 : {
116 21753 : return maMap.find ( rName ) != maMap.end();
117 : }
118 :
119 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|