bump product version to 5.0.4.1
[LibreOffice.git] / connectivity / source / sdbcx / VDescriptor.cxx
blob8a1ff43cdfc7a2b089e2f1f24351f5e57d17d8c5
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 .
20 #include <connectivity/sdbcx/VDescriptor.hxx>
21 #include <cppuhelper/queryinterface.hxx>
23 #include <functional>
24 #include <algorithm>
25 #include <string.h>
27 namespace connectivity
29 namespace sdbcx
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::lang;
33 using namespace ::com::sun::star::beans;
36 // = ODescriptor
39 ODescriptor::ODescriptor(::cppu::OBroadcastHelper& _rBHelper, bool _bCase, bool _bNew)
40 :ODescriptor_PBASE(_rBHelper)
41 ,m_aCase(_bCase)
42 ,m_bNew(_bNew)
47 // com::sun::star::lang::XUnoTunnel
48 sal_Int64 SAL_CALL ODescriptor::getSomething( const Sequence< sal_Int8 >& rId ) throw(RuntimeException, std::exception)
50 return (rId.getLength() == 16 && 0 == memcmp(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) )
51 ? reinterpret_cast< sal_Int64 >( this )
52 : 0;
56 ODescriptor* ODescriptor::getImplementation( const Reference< XInterface >& _rxSomeComp )
58 Reference< XUnoTunnel > xTunnel( _rxSomeComp, UNO_QUERY );
59 if ( xTunnel.is() )
60 return reinterpret_cast< ODescriptor* >( xTunnel->getSomething( getUnoTunnelImplementationId() ) );
61 return NULL;
65 namespace
67 struct ResetROAttribute : public ::std::unary_function< Property, void >
69 void operator ()( Property& _rProperty ) const
71 _rProperty.Attributes &= ~PropertyAttribute::READONLY;
74 struct SetROAttribute : public ::std::unary_function< Property, void >
76 void operator ()( Property& _rProperty ) const
78 _rProperty.Attributes |= PropertyAttribute::READONLY;
84 ::cppu::IPropertyArrayHelper* ODescriptor::doCreateArrayHelper() const
86 Sequence< Property > aProperties;
87 describeProperties( aProperties );
89 if ( isNew() )
90 ::std::for_each( aProperties.getArray(), aProperties.getArray() + aProperties.getLength(), ResetROAttribute() );
91 else
92 ::std::for_each( aProperties.getArray(), aProperties.getArray() + aProperties.getLength(), SetROAttribute() );
94 return new ::cppu::OPropertyArrayHelper( aProperties );
98 bool ODescriptor::isNew( const Reference< XInterface >& _rxDescriptor )
100 ODescriptor* pImplementation = getImplementation( _rxDescriptor );
101 return pImplementation && pImplementation->isNew();
105 Sequence< sal_Int8 > ODescriptor::getUnoTunnelImplementationId()
107 static ::cppu::OImplementationId * pId = 0;
108 if (! pId)
110 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
111 if (! pId)
113 static ::cppu::OImplementationId aId;
114 pId = &aId;
117 return pId->getImplementationId();
121 Any SAL_CALL ODescriptor::queryInterface( const Type & rType ) throw(RuntimeException, std::exception)
123 Any aRet = ::cppu::queryInterface(rType,static_cast< XUnoTunnel*> (this));
124 return aRet.hasValue() ? aRet : ODescriptor_PBASE::queryInterface(rType);
128 void ODescriptor::setNew(bool _bNew)
130 m_bNew = _bNew;
134 Sequence< Type > SAL_CALL ODescriptor::getTypes( ) throw(RuntimeException, std::exception)
136 ::cppu::OTypeCollection aTypes( cppu::UnoType<XMultiPropertySet>::get(),
137 cppu::UnoType<XFastPropertySet>::get(),
138 cppu::UnoType<XPropertySet>::get(),
139 cppu::UnoType<XUnoTunnel>::get());
140 return aTypes.getTypes();
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */