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 .
22 #include <cppuhelper/queryinterface.hxx>
23 #include <cppuhelper/typeprovider.hxx>
25 #include <com/sun/star/reflection/XIdlField2.hpp>
27 using namespace css::lang
;
28 using namespace css::reflection
;
29 using namespace css::uno
;
36 class IdlEnumFieldImpl
37 : public IdlMemberImpl
44 IdlEnumFieldImpl( IdlReflectionServiceImpl
* pReflection
, const OUString
& rName
,
45 typelib_TypeDescription
* pTypeDescr
, sal_Int32 nValue
)
46 : IdlMemberImpl( pReflection
, rName
, pTypeDescr
, pTypeDescr
)
51 virtual Any SAL_CALL
queryInterface( const Type
& rType
) override
;
52 virtual void SAL_CALL
acquire() throw() override
;
53 virtual void SAL_CALL
release() throw() override
;
56 virtual Sequence
< Type
> SAL_CALL
getTypes() override
;
57 virtual Sequence
< sal_Int8
> SAL_CALL
getImplementationId() override
;
60 virtual Reference
< XIdlClass
> SAL_CALL
getDeclaringClass() override
;
61 virtual OUString SAL_CALL
getName() override
;
63 virtual Reference
< XIdlClass
> SAL_CALL
getType() override
;
64 virtual FieldAccessMode SAL_CALL
getAccessMode() override
;
65 virtual Any SAL_CALL
get( const Any
& rObj
) override
;
66 virtual void SAL_CALL
set( const Any
& rObj
, const Any
& rValue
) override
;
67 // XIdlField2: getType, getAccessMode and get are equal to XIdlField
68 virtual void SAL_CALL
set( Any
& rObj
, const Any
& rValue
) override
;
75 Any
IdlEnumFieldImpl::queryInterface( const Type
& rType
)
77 Any
aRet( ::cppu::queryInterface( rType
,
78 static_cast< XIdlField
* >( this ),
79 static_cast< XIdlField2
* >( this ) ) );
80 return (aRet
.hasValue() ? aRet
: IdlMemberImpl::queryInterface( rType
));
83 void IdlEnumFieldImpl::acquire() throw()
85 IdlMemberImpl::acquire();
88 void IdlEnumFieldImpl::release() throw()
90 IdlMemberImpl::release();
95 Sequence
< Type
> IdlEnumFieldImpl::getTypes()
97 static cppu::OTypeCollection
s_aTypes(
98 cppu::UnoType
<XIdlField2
>::get(),
99 cppu::UnoType
<XIdlField
>::get(),
100 IdlMemberImpl::getTypes() );
102 return s_aTypes
.getTypes();
105 Sequence
< sal_Int8
> IdlEnumFieldImpl::getImplementationId()
107 return css::uno::Sequence
<sal_Int8
>();
112 Reference
< XIdlClass
> IdlEnumFieldImpl::getDeclaringClass()
114 return IdlMemberImpl::getDeclaringClass();
117 OUString
IdlEnumFieldImpl::getName()
119 return IdlMemberImpl::getName();
124 Reference
< XIdlClass
> IdlEnumFieldImpl::getType()
126 return getDeclaringClass();
129 FieldAccessMode
IdlEnumFieldImpl::getAccessMode()
131 return FieldAccessMode_READONLY
;
134 Any
IdlEnumFieldImpl::get( const Any
& )
136 return Any( &_nValue
, getTypeDescr() );
139 void IdlEnumFieldImpl::set( const Any
&, const Any
& )
141 throw IllegalAccessException(
142 "cannot set enum field, it is constant",
143 static_cast<XWeak
*>(static_cast<OWeakObject
*>(this)) );
146 void IdlEnumFieldImpl::set( Any
&, const Any
& )
148 throw IllegalAccessException(
149 "cannot set enum field, it is constant",
150 static_cast<XWeak
*>(static_cast<OWeakObject
*>(this)) );
154 EnumIdlClassImpl::~EnumIdlClassImpl()
158 // IdlClassImpl modifications
160 Reference
< XIdlField
> EnumIdlClassImpl::getField( const OUString
& rName
)
163 getFields(); // init members
165 const OUString2Field::const_iterator
iFind( _aName2Field
.find( rName
) );
166 if (iFind
!= _aName2Field
.end())
167 return (*iFind
).second
;
169 return Reference
< XIdlField
>();
172 Sequence
< Reference
< XIdlField
> > EnumIdlClassImpl::getFields()
176 ::osl::MutexGuard
aGuard( getMutexAccess() );
179 sal_Int32 nFields
= getTypeDescr()->nEnumValues
;
180 Sequence
< Reference
< XIdlField
> > * pFields
=
181 new Sequence
< Reference
< XIdlField
> >( nFields
);
182 Reference
< XIdlField
> * pSeq
= pFields
->getArray();
186 OUString
aName( getTypeDescr()->ppEnumNames
[nFields
] );
187 _aName2Field
[aName
] = pSeq
[nFields
] = new IdlEnumFieldImpl(
188 getReflection(), aName
, IdlClassImpl::getTypeDescr(), getTypeDescr()->pEnumValues
[nFields
] );
191 _pFields
.reset( pFields
);
197 void EnumIdlClassImpl::createObject( Any
& rObj
)
200 reinterpret_cast<typelib_EnumTypeDescription
*>(IdlClassImpl::getTypeDescr())->nDefaultEnumValue
;
201 rObj
.setValue( &eVal
, IdlClassImpl::getTypeDescr() );
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */