1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 ::comphelper::PropertyInfo
;
24 using ::comphelper::GenerateCppuType
;
25 using ::comphelper::ChainablePropertySetInfo
;
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 ChainablePropertySetInfo::ChainablePropertySetInfo( PropertyInfo
* pMap
)
42 ChainablePropertySetInfo::~ChainablePropertySetInfo()
47 void ChainablePropertySetInfo::add( PropertyInfo
* pMap
, sal_Int32 nCount
)
50 // nCount < 0 => add all
51 // nCount == 0 => add nothing
52 // nCount > 0 => add at most nCount entries
53 if( maProperties
.getLength() )
54 maProperties
.realloc( 0 );
56 while( pMap
->mpName
&& ( ( nCount
< 0) || ( nCount
-- > 0 ) ) )
58 OUString
aName( pMap
->mpName
, pMap
->mnNameLen
, RTL_TEXTENCODING_ASCII_US
);
61 PropertyInfoHash::iterator aIter
= maMap
.find( aName
);
62 if( aIter
!= maMap
.end() )
63 OSL_FAIL( "Warning: PropertyInfo added twice, possible error!");
65 maMap
[aName
] = pMap
++;
69 void ChainablePropertySetInfo::remove( const OUString
& aName
)
72 maMap
.erase ( aName
);
73 if ( maProperties
.getLength() )
74 maProperties
.realloc( 0 );
77 Sequence
< ::Property
> SAL_CALL
ChainablePropertySetInfo::getProperties()
78 throw(::com::sun::star::uno::RuntimeException
)
80 sal_Int32 nSize
= maMap
.size();
81 if( maProperties
.getLength() != nSize
)
83 maProperties
.realloc ( nSize
);
84 Property
* pProperties
= maProperties
.getArray();
86 for (PropertyInfoHash::const_iterator
aIter(maMap
.begin()), aEnd(maMap
.end()); aIter
!= aEnd
; ++aIter
, ++pProperties
)
88 PropertyInfo
* pInfo
= (*aIter
).second
;
90 pProperties
->Name
= OUString( pInfo
->mpName
, pInfo
->mnNameLen
, RTL_TEXTENCODING_ASCII_US
);
91 pProperties
->Handle
= pInfo
->mnHandle
;
93 GenerateCppuType ( pInfo
->meCppuType
, pType
);
94 pProperties
->Type
= *pType
;
95 pProperties
->Attributes
= pInfo
->mnAttributes
;
101 Property SAL_CALL
ChainablePropertySetInfo::getPropertyByName( const OUString
& rName
)
102 throw(::UnknownPropertyException
, ::com::sun::star::uno::RuntimeException
)
104 PropertyInfoHash::iterator aIter
= maMap
.find( rName
);
106 if ( maMap
.end() == aIter
)
107 throw UnknownPropertyException( rName
, *this );
109 PropertyInfo
*pInfo
= (*aIter
).second
;
111 aProperty
.Name
= OUString( pInfo
->mpName
, pInfo
->mnNameLen
, RTL_TEXTENCODING_ASCII_US
);
112 aProperty
.Handle
= pInfo
->mnHandle
;
113 const Type
* pType
= &aProperty
.Type
;
114 GenerateCppuType ( pInfo
->meCppuType
, pType
);
115 aProperty
.Type
= *pType
;
116 aProperty
.Attributes
= pInfo
->mnAttributes
;
120 sal_Bool SAL_CALL
ChainablePropertySetInfo::hasPropertyByName( const OUString
& rName
)
121 throw(::com::sun::star::uno::RuntimeException
)
123 return static_cast < sal_Bool
> ( maMap
.find ( rName
) != maMap
.end() );
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */