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 .
21 #include <comphelper/propertysetinfo.hxx>
23 using namespace ::rtl
;
24 using namespace ::comphelper
;
25 using namespace ::com::sun::star
;
26 using namespace ::com::sun::star::uno
;
27 using namespace ::com::sun::star::beans
;
28 using namespace ::com::sun::star::lang
;
35 PropertyMapImpl() throw();
36 virtual ~PropertyMapImpl() throw();
38 void add( PropertyMapEntry
const * pMap
, sal_Int32 nCount
= -1 ) throw();
39 void remove( const OUString
& aName
) throw();
41 Sequence
< Property
> getProperties() throw();
43 const PropertyMap
* getPropertyMap() const throw();
45 Property
getPropertyByName( const OUString
& aName
) throw( UnknownPropertyException
);
46 bool hasPropertyByName( const OUString
& aName
) throw();
49 PropertyMap maPropertyMap
;
50 Sequence
< Property
> maProperties
;
54 PropertyMapImpl::PropertyMapImpl() throw()
58 PropertyMapImpl::~PropertyMapImpl() throw()
62 void PropertyMapImpl::add( PropertyMapEntry
const * pMap
, sal_Int32 nCount
) throw()
64 // nCount < 0 => add all
65 // nCount == 0 => add nothing
66 // nCount > 0 => add at most nCount entries
68 while( !pMap
->maName
.isEmpty() && ( ( nCount
< 0) || ( nCount
-- > 0 ) ) )
71 PropertyMap::iterator aIter
= maPropertyMap
.find( pMap
->maName
);
72 if( aIter
!= maPropertyMap
.end() )
74 OSL_FAIL( "Warning: PropertyMapEntry added twice, possible error!");
78 maPropertyMap
[pMap
->maName
] = pMap
;
80 if( maProperties
.getLength() )
81 maProperties
.realloc( 0 );
87 void PropertyMapImpl::remove( const OUString
& aName
) throw()
89 maPropertyMap
.erase( aName
);
91 if( maProperties
.getLength() )
92 maProperties
.realloc( 0 );
95 Sequence
< Property
> PropertyMapImpl::getProperties() throw()
97 // maybe we have to generate the properties after
98 // a change in the property map or at first call
100 if( maProperties
.getLength() != (sal_Int32
)maPropertyMap
.size() )
102 maProperties
= Sequence
< Property
>( maPropertyMap
.size() );
103 Property
* pProperties
= maProperties
.getArray();
105 PropertyMap::iterator aIter
= maPropertyMap
.begin();
106 const PropertyMap::iterator aEnd
= maPropertyMap
.end();
107 while( aIter
!= aEnd
)
109 PropertyMapEntry
const * pEntry
= (*aIter
).second
;
111 pProperties
->Name
= pEntry
->maName
;
112 pProperties
->Handle
= pEntry
->mnHandle
;
113 pProperties
->Type
= pEntry
->maType
;
114 pProperties
->Attributes
= pEntry
->mnAttributes
;
124 const PropertyMap
* PropertyMapImpl::getPropertyMap() const throw()
126 return &maPropertyMap
;
129 Property
PropertyMapImpl::getPropertyByName( const OUString
& aName
) throw( UnknownPropertyException
)
131 PropertyMap::iterator aIter
= maPropertyMap
.find( aName
);
133 if( maPropertyMap
.end() == aIter
)
134 throw UnknownPropertyException( aName
, NULL
);
136 PropertyMapEntry
const * pEntry
= (*aIter
).second
;
138 return Property( aName
, pEntry
->mnHandle
, pEntry
->maType
, pEntry
->mnAttributes
);
141 bool PropertyMapImpl::hasPropertyByName( const OUString
& aName
) throw()
143 return maPropertyMap
.find( aName
) != maPropertyMap
.end();
148 PropertySetInfo::PropertySetInfo() throw()
150 mpMap
= new PropertyMapImpl();
153 PropertySetInfo::PropertySetInfo( PropertyMapEntry
const * pMap
) throw()
155 mpMap
= new PropertyMapImpl();
159 PropertySetInfo::~PropertySetInfo() throw()
164 void PropertySetInfo::add( PropertyMapEntry
const * pMap
) throw()
169 void PropertySetInfo::remove( const OUString
& aName
) throw()
171 mpMap
->remove( aName
);
174 Sequence
< ::com::sun::star::beans::Property
> SAL_CALL
PropertySetInfo::getProperties() throw(::com::sun::star::uno::RuntimeException
, std::exception
)
176 return mpMap
->getProperties();
179 Property SAL_CALL
PropertySetInfo::getPropertyByName( const OUString
& aName
) throw(::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::uno::RuntimeException
, std::exception
)
181 return mpMap
->getPropertyByName( aName
);
184 sal_Bool SAL_CALL
PropertySetInfo::hasPropertyByName( const OUString
& Name
) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
186 return mpMap
->hasPropertyByName( Name
);
189 const PropertyMap
* PropertySetInfo::getPropertyMap() const throw()
191 return mpMap
->getPropertyMap();
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */