Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / comphelper / source / property / ChainablePropertySetInfo.cxx
blobaa769539b10b9d76f236b56c25a0431b849b24c7
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/ChainablePropertySetInfo.hxx>
21 #include <comphelper/TypeGeneration.hxx>
23 using ::rtl::OUString;
24 using ::comphelper::PropertyInfo;
25 using ::comphelper::GenerateCppuType;
26 using ::comphelper::ChainablePropertySetInfo;
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 ChainablePropertySetInfo::ChainablePropertySetInfo( PropertyInfo* pMap )
38 throw()
40 add ( pMap );
43 ChainablePropertySetInfo::~ChainablePropertySetInfo()
44 throw()
48 void ChainablePropertySetInfo::add( PropertyInfo* pMap, sal_Int32 nCount )
49 throw()
51 // nCount < 0 => add all
52 // nCount == 0 => add nothing
53 // nCount > 0 => add at most nCount entries
54 if( maProperties.getLength() )
55 maProperties.realloc( 0 );
57 while( pMap->mpName && ( ( nCount < 0) || ( nCount-- > 0 ) ) )
59 OUString aName( pMap->mpName, pMap->mnNameLen, RTL_TEXTENCODING_ASCII_US );
61 #ifdef DBG_UTIL
62 PropertyInfoHash::iterator aIter = maMap.find( aName );
63 if( aIter != maMap.end() )
64 OSL_FAIL( "Warning: PropertyInfo added twice, possible error!");
65 #endif
66 maMap[aName] = pMap++;
70 void ChainablePropertySetInfo::remove( const rtl::OUString& aName )
71 throw()
73 maMap.erase ( aName );
74 if ( maProperties.getLength() )
75 maProperties.realloc( 0 );
78 Sequence< ::Property > SAL_CALL ChainablePropertySetInfo::getProperties()
79 throw(::com::sun::star::uno::RuntimeException)
81 sal_Int32 nSize = maMap.size();
82 if( maProperties.getLength() != nSize )
84 maProperties.realloc ( nSize );
85 Property* pProperties = maProperties.getArray();
87 PropertyInfoHash::iterator aIter = maMap.begin();
88 const PropertyInfoHash::iterator aEnd = maMap.end();
89 for ( ; aIter != aEnd; ++aIter, ++pProperties)
91 PropertyInfo* pInfo = (*aIter).second;
93 pProperties->Name = OUString( pInfo->mpName, pInfo->mnNameLen, RTL_TEXTENCODING_ASCII_US );
94 pProperties->Handle = pInfo->mnHandle;
95 const Type* pType;
96 GenerateCppuType ( pInfo->meCppuType, pType);
97 pProperties->Type = *pType;
98 pProperties->Attributes = pInfo->mnAttributes;
101 return maProperties;
104 Property SAL_CALL ChainablePropertySetInfo::getPropertyByName( const ::rtl::OUString& rName )
105 throw(::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
107 PropertyInfoHash::iterator aIter = maMap.find( rName );
109 if ( maMap.end() == aIter )
110 throw UnknownPropertyException( rName, *this );
112 PropertyInfo *pInfo = (*aIter).second;
113 Property aProperty;
114 aProperty.Name = OUString( pInfo->mpName, pInfo->mnNameLen, RTL_TEXTENCODING_ASCII_US );
115 aProperty.Handle = pInfo->mnHandle;
116 const Type* pType = &aProperty.Type;
117 GenerateCppuType ( pInfo->meCppuType, pType );
118 aProperty.Type = *pType;
119 aProperty.Attributes = pInfo->mnAttributes;
120 return aProperty;
123 sal_Bool SAL_CALL ChainablePropertySetInfo::hasPropertyByName( const ::rtl::OUString& rName )
124 throw(::com::sun::star::uno::RuntimeException)
126 return static_cast < sal_Bool > ( maMap.find ( rName ) != maMap.end() );
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */