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 :
21 : #include "comphelper/propertysetinfo.hxx"
22 :
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;
29 :
30 : namespace comphelper
31 : {
32 : class PropertyMapImpl
33 : {
34 : public:
35 : PropertyMapImpl() throw();
36 : virtual ~PropertyMapImpl() throw();
37 :
38 : void add( PropertyMapEntry const * pMap, sal_Int32 nCount = -1 ) throw();
39 : void remove( const OUString& aName ) throw();
40 :
41 : Sequence< Property > getProperties() throw();
42 :
43 : const PropertyMap* getPropertyMap() const throw();
44 :
45 : Property getPropertyByName( const OUString& aName ) throw( UnknownPropertyException );
46 : bool hasPropertyByName( const OUString& aName ) throw();
47 :
48 : private:
49 : PropertyMap maPropertyMap;
50 : Sequence< Property > maProperties;
51 : };
52 : }
53 :
54 0 : PropertyMapImpl::PropertyMapImpl() throw()
55 : {
56 0 : }
57 :
58 0 : PropertyMapImpl::~PropertyMapImpl() throw()
59 : {
60 0 : }
61 :
62 0 : void PropertyMapImpl::add( PropertyMapEntry const * pMap, sal_Int32 nCount ) throw()
63 : {
64 : // nCount < 0 => add all
65 : // nCount == 0 => add nothing
66 : // nCount > 0 => add at most nCount entries
67 :
68 0 : while( !pMap->maName.isEmpty() && ( ( nCount < 0) || ( nCount-- > 0 ) ) )
69 : {
70 : #ifdef DBG_UTIL
71 : PropertyMap::iterator aIter = maPropertyMap.find( pMap->maName );
72 : if( aIter != maPropertyMap.end() )
73 : {
74 : OSL_FAIL( "Warning: PropertyMapEntry added twice, possible error!");
75 : }
76 : #endif
77 :
78 0 : maPropertyMap[pMap->maName] = pMap;
79 :
80 0 : if( maProperties.getLength() )
81 0 : maProperties.realloc( 0 );
82 :
83 0 : pMap = &pMap[1];
84 : }
85 0 : }
86 :
87 0 : void PropertyMapImpl::remove( const OUString& aName ) throw()
88 : {
89 0 : maPropertyMap.erase( aName );
90 :
91 0 : if( maProperties.getLength() )
92 0 : maProperties.realloc( 0 );
93 0 : }
94 :
95 0 : Sequence< Property > PropertyMapImpl::getProperties() throw()
96 : {
97 : // maybe we have to generate the properties after
98 : // a change in the property map or at first call
99 : // to getProperties
100 0 : if( maProperties.getLength() != (sal_Int32)maPropertyMap.size() )
101 : {
102 0 : maProperties = Sequence< Property >( maPropertyMap.size() );
103 0 : Property* pProperties = maProperties.getArray();
104 :
105 0 : PropertyMap::iterator aIter = maPropertyMap.begin();
106 0 : const PropertyMap::iterator aEnd = maPropertyMap.end();
107 0 : while( aIter != aEnd )
108 : {
109 0 : PropertyMapEntry const * pEntry = (*aIter).second;
110 :
111 0 : pProperties->Name = pEntry->maName;
112 0 : pProperties->Handle = pEntry->mnHandle;
113 0 : pProperties->Type = pEntry->maType;
114 0 : pProperties->Attributes = pEntry->mnAttributes;
115 :
116 0 : ++pProperties;
117 0 : ++aIter;
118 : }
119 : }
120 :
121 0 : return maProperties;
122 : }
123 :
124 0 : const PropertyMap* PropertyMapImpl::getPropertyMap() const throw()
125 : {
126 0 : return &maPropertyMap;
127 : }
128 :
129 0 : Property PropertyMapImpl::getPropertyByName( const OUString& aName ) throw( UnknownPropertyException )
130 : {
131 0 : PropertyMap::iterator aIter = maPropertyMap.find( aName );
132 :
133 0 : if( maPropertyMap.end() == aIter )
134 0 : throw UnknownPropertyException( aName, NULL );
135 :
136 0 : PropertyMapEntry const * pEntry = (*aIter).second;
137 :
138 0 : return Property( aName, pEntry->mnHandle, pEntry->maType, pEntry->mnAttributes );
139 : }
140 :
141 0 : bool PropertyMapImpl::hasPropertyByName( const OUString& aName ) throw()
142 : {
143 0 : return maPropertyMap.find( aName ) != maPropertyMap.end();
144 : }
145 :
146 :
147 :
148 0 : PropertySetInfo::PropertySetInfo() throw()
149 : {
150 0 : mpMap = new PropertyMapImpl();
151 0 : }
152 :
153 0 : PropertySetInfo::PropertySetInfo( PropertyMapEntry const * pMap ) throw()
154 : {
155 0 : mpMap = new PropertyMapImpl();
156 0 : mpMap->add( pMap );
157 0 : }
158 :
159 0 : PropertySetInfo::~PropertySetInfo() throw()
160 : {
161 0 : delete mpMap;
162 0 : }
163 :
164 0 : void PropertySetInfo::add( PropertyMapEntry const * pMap ) throw()
165 : {
166 0 : mpMap->add( pMap );
167 0 : }
168 :
169 0 : void PropertySetInfo::remove( const OUString& aName ) throw()
170 : {
171 0 : mpMap->remove( aName );
172 0 : }
173 :
174 0 : Sequence< ::com::sun::star::beans::Property > SAL_CALL PropertySetInfo::getProperties() throw(::com::sun::star::uno::RuntimeException, std::exception)
175 : {
176 0 : return mpMap->getProperties();
177 : }
178 :
179 0 : Property SAL_CALL PropertySetInfo::getPropertyByName( const OUString& aName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException, std::exception)
180 : {
181 0 : return mpMap->getPropertyByName( aName );
182 : }
183 :
184 0 : sal_Bool SAL_CALL PropertySetInfo::hasPropertyByName( const OUString& Name ) throw(::com::sun::star::uno::RuntimeException, std::exception)
185 : {
186 0 : return mpMap->hasPropertyByName( Name );
187 : }
188 :
189 0 : const PropertyMap* PropertySetInfo::getPropertyMap() const throw()
190 : {
191 0 : return mpMap->getPropertyMap();
192 : }
193 :
194 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|