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 : #include "ImplOPropertySet.hxx"
21 : #include "CloneHelper.hxx"
22 :
23 : #include <algorithm>
24 : #include <iterator>
25 : #include <functional>
26 : #include <com/sun/star/beans/XFastPropertySet.hpp>
27 :
28 : using namespace ::com::sun::star;
29 :
30 : using ::com::sun::star::uno::Sequence;
31 : using ::com::sun::star::uno::Reference;
32 : using ::com::sun::star::uno::Any;
33 :
34 : namespace
35 : {
36 :
37 : struct lcl_getPropertyStateByHandle :
38 : public ::std::unary_function< sal_Int32, beans::PropertyState >
39 : {
40 562372 : lcl_getPropertyStateByHandle(
41 : const ::property::impl::ImplOPropertySet::tPropertyMap & rMap )
42 562372 : : m_rMap( rMap )
43 562372 : {}
44 :
45 563092 : inline beans::PropertyState operator() ( sal_Int32 nHandle )
46 : {
47 563092 : if( m_rMap.end() == m_rMap.find( nHandle ))
48 494022 : return beans::PropertyState_DEFAULT_VALUE;
49 69070 : return beans::PropertyState_DIRECT_VALUE;
50 : }
51 :
52 : private:
53 : const ::property::impl::ImplOPropertySet::tPropertyMap & m_rMap;
54 : };
55 :
56 : template< typename K, typename V >
57 0 : struct lcl_eraseMapEntry :
58 : public ::std::unary_function< K, void >
59 : {
60 0 : lcl_eraseMapEntry( ::std::map< K, V > & rMap )
61 0 : : m_rMap( rMap )
62 0 : {}
63 :
64 0 : inline void operator() ( const K & aKey )
65 : {
66 0 : m_rMap.erase( aKey );
67 0 : }
68 :
69 : private:
70 : ::std::map< K, V > m_rMap;
71 : };
72 :
73 : struct lcl_replaceInterfacePropertiesByClones :
74 : public ::std::unary_function< ::property::impl::ImplOPropertySet::tPropertyMap::value_type, void >
75 : {
76 88 : inline void operator() ( ::property::impl::ImplOPropertySet::tPropertyMap::value_type & rProp )
77 : {
78 176 : if( rProp.second.hasValue() &&
79 88 : rProp.second.getValueType().getTypeClass() == uno::TypeClass_INTERFACE )
80 : {
81 0 : Reference< util::XCloneable > xCloneable;
82 0 : if( rProp.second >>= xCloneable )
83 0 : rProp.second <<= xCloneable->createClone();
84 : }
85 88 : }
86 : };
87 :
88 : } // anonymous namespace
89 :
90 : namespace property
91 : {
92 : namespace impl
93 : {
94 :
95 303495 : ImplOPropertySet::ImplOPropertySet()
96 303495 : {}
97 :
98 22 : ImplOPropertySet::ImplOPropertySet( const ImplOPropertySet & rOther )
99 : {
100 : ::std::copy( rOther.m_aProperties.begin(), rOther.m_aProperties.end(),
101 22 : ::std::inserter( m_aProperties, m_aProperties.begin() ));
102 22 : cloneInterfaceProperties();
103 22 : m_xStyle.set( ::chart::CloneHelper::CreateRefClone< Reference< style::XStyle > >()( rOther.m_xStyle ));
104 22 : }
105 :
106 562352 : beans::PropertyState ImplOPropertySet::GetPropertyStateByHandle( sal_Int32 nHandle ) const
107 : {
108 562352 : return lcl_getPropertyStateByHandle( m_aProperties ) ( nHandle );
109 : }
110 :
111 20 : Sequence< beans::PropertyState > ImplOPropertySet::GetPropertyStatesByHandle(
112 : const ::std::vector< sal_Int32 > & aHandles ) const
113 : {
114 20 : Sequence< beans::PropertyState > aResult( aHandles.size());
115 :
116 : ::std::transform( aHandles.begin(), aHandles.end(),
117 : aResult.getArray(),
118 20 : lcl_getPropertyStateByHandle( m_aProperties ));
119 :
120 20 : return aResult;
121 : }
122 :
123 61846 : void ImplOPropertySet::SetPropertyToDefault( sal_Int32 nHandle )
124 : {
125 61846 : tPropertyMap::iterator aFoundIter( m_aProperties.find( nHandle ) );
126 :
127 61846 : if( m_aProperties.end() != aFoundIter )
128 : {
129 61846 : m_aProperties.erase( aFoundIter );
130 : }
131 61846 : }
132 :
133 0 : void ImplOPropertySet::SetPropertiesToDefault(
134 : const ::std::vector< sal_Int32 > & aHandles )
135 : {
136 : ::std::for_each( aHandles.begin(), aHandles.end(),
137 0 : lcl_eraseMapEntry< sal_Int32, Any >( m_aProperties ) );
138 0 : }
139 :
140 0 : void ImplOPropertySet::SetAllPropertiesToDefault()
141 : {
142 0 : m_aProperties.clear();
143 0 : }
144 :
145 1947937 : bool ImplOPropertySet::GetPropertyValueByHandle(
146 : Any & rValue,
147 : sal_Int32 nHandle ) const
148 : {
149 1947937 : bool bResult = false;
150 :
151 1947937 : tPropertyMap::const_iterator aFoundIter( m_aProperties.find( nHandle ) );
152 :
153 1947937 : if( m_aProperties.end() != aFoundIter )
154 : {
155 315353 : rValue = (*aFoundIter).second;
156 315353 : bResult = true;
157 : }
158 :
159 1947937 : return bResult;
160 : }
161 :
162 271066 : void ImplOPropertySet::SetPropertyValueByHandle(
163 : sal_Int32 nHandle, const Any & rValue, Any * pOldValue )
164 : {
165 271066 : if( pOldValue != NULL )
166 : {
167 0 : tPropertyMap::const_iterator aFoundIter( m_aProperties.find( nHandle ) );
168 0 : if( m_aProperties.end() != aFoundIter )
169 0 : (*pOldValue) = (*aFoundIter).second;
170 : }
171 :
172 271066 : m_aProperties[ nHandle ] = rValue;
173 271066 : }
174 :
175 0 : bool ImplOPropertySet::SetStyle( const Reference< style::XStyle > & xStyle )
176 : {
177 0 : if( ! xStyle.is())
178 0 : return false;
179 :
180 0 : m_xStyle = xStyle;
181 0 : return true;
182 : }
183 :
184 22 : void ImplOPropertySet::cloneInterfaceProperties()
185 : {
186 : ::std::for_each( m_aProperties.begin(), m_aProperties.end(),
187 22 : lcl_replaceInterfacePropertiesByClones());
188 22 : }
189 :
190 : } // namespace impl
191 : } // namespace chart
192 :
193 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|