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 <comphelper/TypeGeneration.hxx>
22 :
23 : using ::comphelper::PropertyInfo;
24 : using ::comphelper::GenerateCppuType;
25 : using ::comphelper::MasterPropertySetInfo;
26 : using ::com::sun::star::uno::Any;
27 : using ::com::sun::star::uno::Type;
28 : using ::com::sun::star::uno::Sequence;
29 : using ::com::sun::star::uno::Reference;
30 : using ::com::sun::star::uno::XInterface;
31 : using ::com::sun::star::uno::RuntimeException;
32 : using ::com::sun::star::beans::Property;
33 : using ::com::sun::star::beans::XPropertySetInfo;
34 : using ::com::sun::star::beans::UnknownPropertyException;
35 :
36 911 : MasterPropertySetInfo::MasterPropertySetInfo( PropertyInfo* pMap )
37 911 : throw()
38 : {
39 911 : add ( pMap );
40 911 : }
41 :
42 1822 : MasterPropertySetInfo::~MasterPropertySetInfo()
43 1822 : throw()
44 : {
45 911 : PropertyDataHash::iterator aEnd = maMap.end(), aIter = maMap.begin();
46 72880 : while (aIter != aEnd )
47 : {
48 71058 : delete (*aIter).second;
49 71058 : ++aIter;
50 : }
51 1822 : }
52 :
53 911 : void MasterPropertySetInfo::add( PropertyInfo* pMap, sal_Int32 nCount, sal_uInt8 nMapId )
54 : throw()
55 : {
56 : // nCount < 0 => add all
57 : // nCount == 0 => add nothing
58 : // nCount > 0 => add at most nCount entries
59 911 : if( maProperties.getLength() )
60 0 : maProperties.realloc( 0 );
61 :
62 55571 : for ( ; pMap->mpName && ( ( nCount < 0 ) || ( nCount > 0 ) ); --nCount, ++pMap )
63 : {
64 54660 : OUString aName( pMap->mpName, pMap->mnNameLen, RTL_TEXTENCODING_ASCII_US );
65 :
66 : #ifdef DBG_UTIL
67 : PropertyDataHash::iterator aIter = maMap.find( aName );
68 : if( aIter != maMap.end() )
69 : OSL_FAIL( "Warning: PropertyInfo added twice, possible error!");
70 : #endif
71 54660 : maMap[aName] = new PropertyData ( nMapId, pMap );
72 54660 : }
73 911 : }
74 :
75 911 : void MasterPropertySetInfo::add( PropertyInfoHash &rHash, sal_uInt8 nMapId )
76 : throw()
77 : {
78 911 : if( maProperties.getLength() )
79 0 : maProperties.realloc( 0 );
80 911 : PropertyInfoHash::iterator aIter = rHash.begin(), aEnd = rHash.end();
81 :
82 18220 : while ( aIter != aEnd )
83 : {
84 : #ifdef DBG_UTIL
85 : PropertyDataHash::iterator aDebugIter = maMap.find( (*aIter).first );
86 : if( aDebugIter != maMap.end() )
87 : OSL_FAIL( "Warning: PropertyInfo added twice, possible error!");
88 : #endif
89 16398 : maMap[(*aIter).first] = new PropertyData ( nMapId, (*aIter).second );
90 16398 : ++aIter;
91 : }
92 911 : }
93 :
94 15 : Sequence< ::Property > SAL_CALL MasterPropertySetInfo::getProperties()
95 : throw(::com::sun::star::uno::RuntimeException)
96 : {
97 15 : sal_Int32 nSize = maMap.size();
98 15 : if( maProperties.getLength() != nSize )
99 : {
100 15 : maProperties.realloc ( nSize );
101 15 : Property* pProperties = maProperties.getArray();
102 :
103 1185 : for (PropertyDataHash::const_iterator aIter(maMap.begin()), aEnd(maMap.end()) ; aIter != aEnd; ++aIter, ++pProperties)
104 : {
105 1170 : PropertyInfo* pInfo = (*aIter).second->mpInfo;
106 :
107 1170 : pProperties->Name = OUString( pInfo->mpName, pInfo->mnNameLen, RTL_TEXTENCODING_ASCII_US );
108 1170 : pProperties->Handle = pInfo->mnHandle;
109 : const Type* pType;
110 1170 : GenerateCppuType ( pInfo->meCppuType, pType);
111 1170 : pProperties->Type = *pType;
112 1170 : pProperties->Attributes = pInfo->mnAttributes;
113 : }
114 : }
115 15 : return maProperties;
116 : }
117 :
118 22 : Property SAL_CALL MasterPropertySetInfo::getPropertyByName( const OUString& rName )
119 : throw(::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
120 : {
121 22 : PropertyDataHash::iterator aIter = maMap.find( rName );
122 :
123 22 : if ( maMap.end() == aIter )
124 0 : throw UnknownPropertyException( rName, *this );
125 :
126 22 : PropertyInfo *pInfo = (*aIter).second->mpInfo;
127 22 : Property aProperty;
128 22 : aProperty.Name = OUString( pInfo->mpName, pInfo->mnNameLen, RTL_TEXTENCODING_ASCII_US );
129 22 : aProperty.Handle = pInfo->mnHandle;
130 : const Type* pType;
131 22 : GenerateCppuType ( pInfo->meCppuType, pType );
132 22 : aProperty.Type = *pType;
133 :
134 22 : aProperty.Attributes = pInfo->mnAttributes;
135 22 : return aProperty;
136 : }
137 :
138 3506 : sal_Bool SAL_CALL MasterPropertySetInfo::hasPropertyByName( const OUString& rName )
139 : throw(::com::sun::star::uno::RuntimeException)
140 : {
141 3506 : return static_cast < sal_Bool > ( maMap.find ( rName ) != maMap.end() );
142 : }
143 :
144 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|