Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / comphelper / source / property / MasterPropertySetInfo.cxx
blobd0f9cd0f0ba6a7e5ecda2babe4b86634d5da3f9e
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 ::rtl::OUString;
24 using ::comphelper::PropertyInfo;
25 using ::comphelper::GenerateCppuType;
26 using ::comphelper::MasterPropertySetInfo;
27 using ::com::sun::star::uno::Any;
28 using ::com::sun::star::uno::Type;
29 using ::com::sun::star::uno::Sequence;
30 using ::com::sun::star::uno::Reference;
31 using ::com::sun::star::uno::XInterface;
32 using ::com::sun::star::uno::RuntimeException;
33 using ::com::sun::star::beans::Property;
34 using ::com::sun::star::beans::XPropertySetInfo;
35 using ::com::sun::star::beans::UnknownPropertyException;
37 MasterPropertySetInfo::MasterPropertySetInfo( PropertyInfo* pMap )
38 throw()
40 add ( pMap );
43 MasterPropertySetInfo::~MasterPropertySetInfo()
44 throw()
46 PropertyDataHash::iterator aEnd = maMap.end(), aIter = maMap.begin();
47 while (aIter != aEnd )
49 delete (*aIter).second;
50 ++aIter;
54 void MasterPropertySetInfo::add( PropertyInfo* pMap, sal_Int32 nCount, sal_uInt8 nMapId )
55 throw()
57 // nCount < 0 => add all
58 // nCount == 0 => add nothing
59 // nCount > 0 => add at most nCount entries
60 if( maProperties.getLength() )
61 maProperties.realloc( 0 );
63 for ( ; pMap->mpName && ( ( nCount < 0 ) || ( nCount > 0 ) ); --nCount, ++pMap )
65 OUString aName( pMap->mpName, pMap->mnNameLen, RTL_TEXTENCODING_ASCII_US );
67 #ifdef DBG_UTIL
68 PropertyDataHash::iterator aIter = maMap.find( aName );
69 if( aIter != maMap.end() )
70 OSL_FAIL( "Warning: PropertyInfo added twice, possible error!");
71 #endif
72 maMap[aName] = new PropertyData ( nMapId, pMap );
76 void MasterPropertySetInfo::add( PropertyInfoHash &rHash, sal_uInt8 nMapId )
77 throw()
79 if( maProperties.getLength() )
80 maProperties.realloc( 0 );
81 PropertyInfoHash::iterator aIter = rHash.begin(), aEnd = rHash.end();
83 while ( aIter != aEnd )
85 #ifdef DBG_UTIL
86 PropertyDataHash::iterator aDebugIter = maMap.find( (*aIter).first );
87 if( aDebugIter != maMap.end() )
88 OSL_FAIL( "Warning: PropertyInfo added twice, possible error!");
89 #endif
90 maMap[(*aIter).first] = new PropertyData ( nMapId, (*aIter).second );
91 ++aIter;
95 Sequence< ::Property > SAL_CALL MasterPropertySetInfo::getProperties()
96 throw(::com::sun::star::uno::RuntimeException)
98 sal_Int32 nSize = maMap.size();
99 if( maProperties.getLength() != nSize )
101 maProperties.realloc ( nSize );
102 Property* pProperties = maProperties.getArray();
104 PropertyDataHash::iterator aIter = maMap.begin();
105 const PropertyDataHash::iterator aEnd = maMap.end();
106 for ( ; aIter != aEnd; ++aIter, ++pProperties)
108 PropertyInfo* pInfo = (*aIter).second->mpInfo;
110 pProperties->Name = OUString( pInfo->mpName, pInfo->mnNameLen, RTL_TEXTENCODING_ASCII_US );
111 pProperties->Handle = pInfo->mnHandle;
112 const Type* pType;
113 GenerateCppuType ( pInfo->meCppuType, pType);
114 pProperties->Type = *pType;
115 pProperties->Attributes = pInfo->mnAttributes;
118 return maProperties;
121 Property SAL_CALL MasterPropertySetInfo::getPropertyByName( const ::rtl::OUString& rName )
122 throw(::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
124 PropertyDataHash::iterator aIter = maMap.find( rName );
126 if ( maMap.end() == aIter )
127 throw UnknownPropertyException( rName, *this );
129 PropertyInfo *pInfo = (*aIter).second->mpInfo;
130 Property aProperty;
131 aProperty.Name = OUString( pInfo->mpName, pInfo->mnNameLen, RTL_TEXTENCODING_ASCII_US );
132 aProperty.Handle = pInfo->mnHandle;
133 const Type* pType;
134 GenerateCppuType ( pInfo->meCppuType, pType );
135 aProperty.Type = *pType;
137 aProperty.Attributes = pInfo->mnAttributes;
138 return aProperty;
141 sal_Bool SAL_CALL MasterPropertySetInfo::hasPropertyByName( const ::rtl::OUString& rName )
142 throw(::com::sun::star::uno::RuntimeException)
144 return static_cast < sal_Bool > ( maMap.find ( rName ) != maMap.end() );
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */