xref: /AOO41X/main/comphelper/source/property/ChainablePropertySetInfo.cxx (revision dde7d3faf6dcd9cbeb7b48ba6d0cea5ffcc883d0)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_comphelper.hxx"
26 #include <comphelper/ChainablePropertySetInfo.hxx>
27 #include <comphelper/TypeGeneration.hxx>
28 
29 using ::rtl::OUString;
30 using ::comphelper::PropertyInfo;
31 using ::comphelper::GenerateCppuType;
32 using ::comphelper::ChainablePropertySetInfo;
33 using ::com::sun::star::uno::Any;
34 using ::com::sun::star::uno::Type;
35 using ::com::sun::star::uno::Sequence;
36 using ::com::sun::star::uno::Reference;
37 using ::com::sun::star::uno::XInterface;
38 using ::com::sun::star::uno::RuntimeException;
39 using ::com::sun::star::beans::Property;
40 using ::com::sun::star::beans::XPropertySetInfo;
41 using ::com::sun::star::beans::UnknownPropertyException;
42 
ChainablePropertySetInfo()43 ChainablePropertySetInfo::ChainablePropertySetInfo()
44     throw()
45 {
46 }
47 
ChainablePropertySetInfo(PropertyInfo * pMap)48 ChainablePropertySetInfo::ChainablePropertySetInfo( PropertyInfo* pMap )
49     throw()
50 {
51     add ( pMap );
52 }
53 
~ChainablePropertySetInfo()54 ChainablePropertySetInfo::~ChainablePropertySetInfo()
55     throw()
56 {
57 }
58 
add(PropertyInfo * pMap,sal_Int32 nCount)59 void ChainablePropertySetInfo::add( PropertyInfo* pMap, sal_Int32 nCount )
60     throw()
61 {
62     // nCount < 0   => add all
63     // nCount == 0  => add nothing
64     // nCount > 0   => add at most nCount entries
65     if( maProperties.getLength() )
66         maProperties.realloc( 0 );
67 
68     while( pMap->mpName && ( ( nCount < 0) || ( nCount-- > 0 ) ) )
69     {
70         OUString aName( pMap->mpName, pMap->mnNameLen, RTL_TEXTENCODING_ASCII_US );
71 
72 #ifdef DBG_UTIL
73         PropertyInfoHash::iterator aIter = maMap.find( aName );
74         if( aIter != maMap.end() )
75             OSL_ENSURE( sal_False, "Warning: PropertyInfo added twice, possible error!");
76 #endif
77         maMap[aName] = pMap++;
78     }
79 }
80 
remove(const rtl::OUString & aName)81 void ChainablePropertySetInfo::remove( const rtl::OUString& aName )
82     throw()
83 {
84     maMap.erase ( aName );
85     if ( maProperties.getLength() )
86          maProperties.realloc( 0 );
87 }
88 
getProperties()89 Sequence< ::Property > SAL_CALL ChainablePropertySetInfo::getProperties()
90     throw(::com::sun::star::uno::RuntimeException)
91 {
92     sal_Int32 nSize = maMap.size();
93     if( maProperties.getLength() != nSize )
94     {
95         maProperties.realloc ( nSize );
96         Property* pProperties = maProperties.getArray();
97 
98         PropertyInfoHash::iterator aIter = maMap.begin();
99         const PropertyInfoHash::iterator aEnd = maMap.end();
100         for ( ; aIter != aEnd; ++aIter, ++pProperties)
101         {
102             PropertyInfo* pInfo = (*aIter).second;
103 
104             pProperties->Name = OUString( pInfo->mpName, pInfo->mnNameLen, RTL_TEXTENCODING_ASCII_US );
105             pProperties->Handle = pInfo->mnHandle;
106             const Type* pType;
107             GenerateCppuType ( pInfo->meCppuType, pType);
108             pProperties->Type = *pType;
109             pProperties->Attributes = pInfo->mnAttributes;
110         }
111     }
112     return maProperties;
113 }
114 
getPropertyByName(const::rtl::OUString & rName)115 Property SAL_CALL ChainablePropertySetInfo::getPropertyByName( const ::rtl::OUString& rName )
116     throw(::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
117 {
118     PropertyInfoHash::iterator aIter = maMap.find( rName );
119 
120     if ( maMap.end() == aIter )
121         throw UnknownPropertyException( rName, *this );
122 
123     PropertyInfo *pInfo = (*aIter).second;
124     Property aProperty;
125     aProperty.Name   = OUString( pInfo->mpName, pInfo->mnNameLen, RTL_TEXTENCODING_ASCII_US );
126     aProperty.Handle = pInfo->mnHandle;
127     const Type* pType = &aProperty.Type;
128     GenerateCppuType ( pInfo->meCppuType, pType );
129     aProperty.Type = *pType;
130     aProperty.Attributes = pInfo->mnAttributes;
131     return aProperty;
132 }
133 
hasPropertyByName(const::rtl::OUString & rName)134 sal_Bool SAL_CALL ChainablePropertySetInfo::hasPropertyByName( const ::rtl::OUString& rName )
135     throw(::com::sun::star::uno::RuntimeException)
136 {
137     return static_cast < sal_Bool > ( maMap.find ( rName ) != maMap.end() );
138 }
139