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 typedef cppu::ImplInheritanceHelper
<IdlMemberImpl
, XIdlField
, XIdlField2
> IdlEnumFieldImpl_Base
;
37 class IdlEnumFieldImpl
: public IdlEnumFieldImpl_Base
42 IdlEnumFieldImpl( IdlReflectionServiceImpl
* pReflection
, const OUString
& rName
,
43 typelib_TypeDescription
* pTypeDescr
, sal_Int32 nValue
)
44 : IdlEnumFieldImpl_Base( pReflection
, rName
, pTypeDescr
, pTypeDescr
)
49 virtual Reference
< XIdlClass
> SAL_CALL
getDeclaringClass() override
;
50 virtual OUString SAL_CALL
getName() override
;
52 virtual Reference
< XIdlClass
> SAL_CALL
getType() override
;
53 virtual FieldAccessMode SAL_CALL
getAccessMode() override
;
54 virtual Any SAL_CALL
get( const Any
& rObj
) override
;
55 virtual void SAL_CALL
set( const Any
& rObj
, const Any
& rValue
) override
;
56 // XIdlField2: getType, getAccessMode and get are equal to XIdlField
57 virtual void SAL_CALL
set( Any
& rObj
, const Any
& rValue
) override
;
64 Reference
< XIdlClass
> IdlEnumFieldImpl::getDeclaringClass()
66 return IdlMemberImpl::getDeclaringClass();
69 OUString
IdlEnumFieldImpl::getName()
71 return IdlMemberImpl::getName();
76 Reference
< XIdlClass
> IdlEnumFieldImpl::getType()
78 return getDeclaringClass();
81 FieldAccessMode
IdlEnumFieldImpl::getAccessMode()
83 return FieldAccessMode_READONLY
;
86 Any
IdlEnumFieldImpl::get( const Any
& )
88 return Any( &_nValue
, getTypeDescr() );
91 void IdlEnumFieldImpl::set( const Any
&, const Any
& )
93 throw IllegalAccessException(
94 u
"cannot set enum field, it is constant"_ustr
,
98 void IdlEnumFieldImpl::set( Any
&, const Any
& )
100 throw IllegalAccessException(
101 u
"cannot set enum field, it is constant"_ustr
,
106 EnumIdlClassImpl::~EnumIdlClassImpl()
110 // IdlClassImpl modifications
112 Reference
< XIdlField
> EnumIdlClassImpl::getField( const OUString
& rName
)
115 getFields(); // init members
117 const OUString2Field::const_iterator
iFind( _aName2Field
.find( rName
) );
118 if (iFind
!= _aName2Field
.end())
119 return (*iFind
).second
;
121 return Reference
< XIdlField
>();
124 Sequence
< Reference
< XIdlField
> > EnumIdlClassImpl::getFields()
128 ::osl::MutexGuard
aGuard( getMutexAccess() );
131 sal_Int32 nFields
= getTypeDescr()->nEnumValues
;
132 Sequence
< Reference
< XIdlField
> > aFields( nFields
);
133 Reference
< XIdlField
> * pSeq
= aFields
.getArray();
137 OUString
aName( getTypeDescr()->ppEnumNames
[nFields
] );
138 _aName2Field
[aName
] = pSeq
[nFields
] = new IdlEnumFieldImpl(
139 getReflection(), aName
, IdlClassImpl::getTypeDescr(), getTypeDescr()->pEnumValues
[nFields
] );
142 m_xFields
= std::move( aFields
);
148 void EnumIdlClassImpl::createObject( Any
& rObj
)
151 reinterpret_cast<typelib_EnumTypeDescription
*>(IdlClassImpl::getTypeDescr())->nDefaultEnumValue
;
152 rObj
.setValue( &eVal
, IdlClassImpl::getTypeDescr() );
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */