Branch data 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/ChainablePropertySetInfo.hxx>
21 : : #include <comphelper/TypeGeneration.hxx>
22 : :
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;
36 : :
37 : 772 : ChainablePropertySetInfo::ChainablePropertySetInfo( PropertyInfo* pMap )
38 [ + - ][ + - ]: 772 : throw()
39 : : {
40 : 772 : add ( pMap );
41 : 772 : }
42 : :
43 : 1544 : ChainablePropertySetInfo::~ChainablePropertySetInfo()
44 [ + - ][ + - ]: 772 : throw()
45 : : {
46 [ - + ]: 1544 : }
47 : :
48 : 772 : void ChainablePropertySetInfo::add( PropertyInfo* pMap, sal_Int32 nCount )
49 : : throw()
50 : : {
51 : : // nCount < 0 => add all
52 : : // nCount == 0 => add nothing
53 : : // nCount > 0 => add at most nCount entries
54 [ - + ]: 772 : if( maProperties.getLength() )
55 : 0 : maProperties.realloc( 0 );
56 : :
57 [ + + ][ - + ]: 15152 : while( pMap->mpName && ( ( nCount < 0) || ( nCount-- > 0 ) ) )
[ # # ][ + + ]
58 : : {
59 [ + - ]: 14380 : OUString aName( pMap->mpName, pMap->mnNameLen, RTL_TEXTENCODING_ASCII_US );
60 : :
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 [ + - ]: 14380 : maMap[aName] = pMap++;
67 : 14380 : }
68 : 772 : }
69 : :
70 : 2 : void ChainablePropertySetInfo::remove( const rtl::OUString& aName )
71 : : throw()
72 : : {
73 : 2 : maMap.erase ( aName );
74 [ - + ]: 2 : if ( maProperties.getLength() )
75 : 0 : maProperties.realloc( 0 );
76 : 2 : }
77 : :
78 : 2 : Sequence< ::Property > SAL_CALL ChainablePropertySetInfo::getProperties()
79 : : throw(::com::sun::star::uno::RuntimeException)
80 : : {
81 : 2 : sal_Int32 nSize = maMap.size();
82 [ + - ]: 2 : if( maProperties.getLength() != nSize )
83 : : {
84 [ + - ]: 2 : maProperties.realloc ( nSize );
85 [ + - ]: 2 : Property* pProperties = maProperties.getArray();
86 : :
87 [ + - ]: 2 : PropertyInfoHash::iterator aIter = maMap.begin();
88 [ + - ]: 2 : const PropertyInfoHash::iterator aEnd = maMap.end();
89 [ + + ]: 82 : for ( ; aIter != aEnd; ++aIter, ++pProperties)
90 : : {
91 [ + - ]: 80 : PropertyInfo* pInfo = (*aIter).second;
92 : :
93 [ + - ]: 80 : pProperties->Name = OUString( pInfo->mpName, pInfo->mnNameLen, RTL_TEXTENCODING_ASCII_US );
94 : 80 : pProperties->Handle = pInfo->mnHandle;
95 : : const Type* pType;
96 [ + - ]: 80 : GenerateCppuType ( pInfo->meCppuType, pType);
97 : 80 : pProperties->Type = *pType;
98 : 80 : pProperties->Attributes = pInfo->mnAttributes;
99 : : }
100 : : }
101 : 2 : return maProperties;
102 : : }
103 : :
104 : 82 : Property SAL_CALL ChainablePropertySetInfo::getPropertyByName( const ::rtl::OUString& rName )
105 : : throw(::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
106 : : {
107 [ + - ]: 82 : PropertyInfoHash::iterator aIter = maMap.find( rName );
108 : :
109 [ + - ][ - + ]: 82 : if ( maMap.end() == aIter )
110 [ # # ][ # # ]: 0 : throw UnknownPropertyException( rName, *this );
111 : :
112 [ + - ]: 82 : PropertyInfo *pInfo = (*aIter).second;
113 : 82 : Property aProperty;
114 [ + - ]: 82 : aProperty.Name = OUString( pInfo->mpName, pInfo->mnNameLen, RTL_TEXTENCODING_ASCII_US );
115 : 82 : aProperty.Handle = pInfo->mnHandle;
116 : 82 : const Type* pType = &aProperty.Type;
117 [ + - ]: 82 : GenerateCppuType ( pInfo->meCppuType, pType );
118 : 82 : aProperty.Type = *pType;
119 : 82 : aProperty.Attributes = pInfo->mnAttributes;
120 : 82 : return aProperty;
121 : : }
122 : :
123 : 84 : sal_Bool SAL_CALL ChainablePropertySetInfo::hasPropertyByName( const ::rtl::OUString& rName )
124 : : throw(::com::sun::star::uno::RuntimeException)
125 : : {
126 [ + - ]: 84 : return static_cast < sal_Bool > ( maMap.find ( rName ) != maMap.end() );
127 : : }
128 : :
129 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|