bump product version to 5.0.4.1
[LibreOffice.git] / comphelper / source / property / propertysetinfo.cxx
blobbfd8e58c2c857c60908dbb12b9442f946b1dfee2
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 .
21 #include <comphelper/propertysetinfo.hxx>
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;
30 namespace comphelper
32 class PropertyMapImpl
34 public:
35 PropertyMapImpl() throw();
36 virtual ~PropertyMapImpl() throw();
38 void add(PropertyMapEntry const * pMap) throw();
39 void remove( const OUString& aName ) throw();
41 Sequence< Property > getProperties() throw();
43 const PropertyMap& getPropertyMap() const throw() { return maPropertyMap;}
45 Property getPropertyByName( const OUString& aName ) throw( UnknownPropertyException );
46 bool hasPropertyByName( const OUString& aName ) throw();
48 private:
49 PropertyMap maPropertyMap;
50 Sequence< Property > maProperties;
54 PropertyMapImpl::PropertyMapImpl() throw()
58 PropertyMapImpl::~PropertyMapImpl() throw()
62 void PropertyMapImpl::add(PropertyMapEntry const * pMap) throw()
64 while (!pMap->maName.isEmpty())
66 // check for duplicates
67 assert(maPropertyMap.find(pMap->maName) == maPropertyMap.end());
69 maPropertyMap[pMap->maName] = pMap;
71 if( maProperties.getLength() )
72 maProperties.realloc( 0 );
74 pMap = &pMap[1];
78 void PropertyMapImpl::remove( const OUString& aName ) throw()
80 maPropertyMap.erase( aName );
82 if( maProperties.getLength() )
83 maProperties.realloc( 0 );
86 Sequence< Property > PropertyMapImpl::getProperties() throw()
88 // maybe we have to generate the properties after
89 // a change in the property map or at first call
90 // to getProperties
91 if( maProperties.getLength() != (sal_Int32)maPropertyMap.size() )
93 maProperties = Sequence< Property >( maPropertyMap.size() );
94 Property* pProperties = maProperties.getArray();
96 PropertyMap::iterator aIter = maPropertyMap.begin();
97 const PropertyMap::iterator aEnd = maPropertyMap.end();
98 while( aIter != aEnd )
100 PropertyMapEntry const * pEntry = (*aIter).second;
102 pProperties->Name = pEntry->maName;
103 pProperties->Handle = pEntry->mnHandle;
104 pProperties->Type = pEntry->maType;
105 pProperties->Attributes = pEntry->mnAttributes;
107 ++pProperties;
108 ++aIter;
112 return maProperties;
116 Property PropertyMapImpl::getPropertyByName( const OUString& aName ) throw( UnknownPropertyException )
118 PropertyMap::iterator aIter = maPropertyMap.find( aName );
120 if( maPropertyMap.end() == aIter )
121 throw UnknownPropertyException( aName );
123 PropertyMapEntry const * pEntry = (*aIter).second;
125 return Property( aName, pEntry->mnHandle, pEntry->maType, pEntry->mnAttributes );
128 bool PropertyMapImpl::hasPropertyByName( const OUString& aName ) throw()
130 return maPropertyMap.find( aName ) != maPropertyMap.end();
135 PropertySetInfo::PropertySetInfo() throw()
137 mpMap = new PropertyMapImpl();
140 PropertySetInfo::PropertySetInfo( PropertyMapEntry const * pMap ) throw()
142 mpMap = new PropertyMapImpl();
143 mpMap->add( pMap );
146 PropertySetInfo::~PropertySetInfo() throw()
148 delete mpMap;
151 void PropertySetInfo::add( PropertyMapEntry const * pMap ) throw()
153 mpMap->add( pMap );
156 void PropertySetInfo::remove( const OUString& aName ) throw()
158 mpMap->remove( aName );
161 Sequence< ::com::sun::star::beans::Property > SAL_CALL PropertySetInfo::getProperties() throw(::com::sun::star::uno::RuntimeException, std::exception)
163 return mpMap->getProperties();
166 Property SAL_CALL PropertySetInfo::getPropertyByName( const OUString& aName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException, std::exception)
168 return mpMap->getPropertyByName( aName );
171 sal_Bool SAL_CALL PropertySetInfo::hasPropertyByName( const OUString& Name ) throw(::com::sun::star::uno::RuntimeException, std::exception)
173 return mpMap->hasPropertyByName( Name );
176 const PropertyMap& PropertySetInfo::getPropertyMap() const throw()
178 return mpMap->getPropertyMap();
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */