Updated core
[LibreOffice.git] / comphelper / source / property / MasterPropertySetInfo.cxx
blobe85d7402eb3ac8156a4a3d3bcfea6a6a63174b76
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <comphelper/MasterPropertySetInfo.hxx>
21 #include <comphelper/TypeGeneration.hxx>
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;
36 MasterPropertySetInfo::MasterPropertySetInfo( PropertyInfo* pMap )
37 throw()
39 add ( pMap );
42 MasterPropertySetInfo::~MasterPropertySetInfo()
43 throw()
45 PropertyDataHash::iterator aEnd = maMap.end(), aIter = maMap.begin();
46 while (aIter != aEnd )
48 delete (*aIter).second;
49 ++aIter;
53 void MasterPropertySetInfo::add( PropertyInfo* pMap, sal_Int32 nCount, sal_uInt8 nMapId )
54 throw()
56 // nCount < 0 => add all
57 // nCount == 0 => add nothing
58 // nCount > 0 => add at most nCount entries
59 if( maProperties.getLength() )
60 maProperties.realloc( 0 );
62 for ( ; pMap->mpName && ( ( nCount < 0 ) || ( nCount > 0 ) ); --nCount, ++pMap )
64 OUString aName( pMap->mpName, pMap->mnNameLen, RTL_TEXTENCODING_ASCII_US );
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 maMap[aName] = new PropertyData ( nMapId, pMap );
75 void MasterPropertySetInfo::add( PropertyInfoHash &rHash, sal_uInt8 nMapId )
76 throw()
78 if( maProperties.getLength() )
79 maProperties.realloc( 0 );
80 PropertyInfoHash::iterator aIter = rHash.begin(), aEnd = rHash.end();
82 while ( aIter != aEnd )
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 maMap[(*aIter).first] = new PropertyData ( nMapId, (*aIter).second );
90 ++aIter;
94 Sequence< ::Property > SAL_CALL MasterPropertySetInfo::getProperties()
95 throw(::com::sun::star::uno::RuntimeException)
97 sal_Int32 nSize = maMap.size();
98 if( maProperties.getLength() != nSize )
100 maProperties.realloc ( nSize );
101 Property* pProperties = maProperties.getArray();
103 for (PropertyDataHash::const_iterator aIter(maMap.begin()), aEnd(maMap.end()) ; aIter != aEnd; ++aIter, ++pProperties)
105 PropertyInfo* pInfo = (*aIter).second->mpInfo;
107 pProperties->Name = OUString( pInfo->mpName, pInfo->mnNameLen, RTL_TEXTENCODING_ASCII_US );
108 pProperties->Handle = pInfo->mnHandle;
109 const Type* pType;
110 GenerateCppuType ( pInfo->meCppuType, pType);
111 pProperties->Type = *pType;
112 pProperties->Attributes = pInfo->mnAttributes;
115 return maProperties;
118 Property SAL_CALL MasterPropertySetInfo::getPropertyByName( const OUString& rName )
119 throw(::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
121 PropertyDataHash::iterator aIter = maMap.find( rName );
123 if ( maMap.end() == aIter )
124 throw UnknownPropertyException( rName, *this );
126 PropertyInfo *pInfo = (*aIter).second->mpInfo;
127 Property aProperty;
128 aProperty.Name = OUString( pInfo->mpName, pInfo->mnNameLen, RTL_TEXTENCODING_ASCII_US );
129 aProperty.Handle = pInfo->mnHandle;
130 const Type* pType;
131 GenerateCppuType ( pInfo->meCppuType, pType );
132 aProperty.Type = *pType;
134 aProperty.Attributes = pInfo->mnAttributes;
135 return aProperty;
138 sal_Bool SAL_CALL MasterPropertySetInfo::hasPropertyByName( const OUString& rName )
139 throw(::com::sun::star::uno::RuntimeException)
141 return static_cast < sal_Bool > ( maMap.find ( rName ) != maMap.end() );
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */