tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / stoc / source / corereflection / crenum.cxx
blob13484e0eb324818052ebfc9739217aa16d764c0b
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 "base.hxx"
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;
31 namespace stoc_corefl
34 namespace {
36 typedef cppu::ImplInheritanceHelper<IdlMemberImpl, XIdlField, XIdlField2> IdlEnumFieldImpl_Base;
37 class IdlEnumFieldImpl : public IdlEnumFieldImpl_Base
39 sal_Int32 _nValue;
41 public:
42 IdlEnumFieldImpl( IdlReflectionServiceImpl * pReflection, const OUString & rName,
43 typelib_TypeDescription * pTypeDescr, sal_Int32 nValue )
44 : IdlEnumFieldImpl_Base( pReflection, rName, pTypeDescr, pTypeDescr )
45 , _nValue( nValue )
48 // XIdlMember
49 virtual Reference< XIdlClass > SAL_CALL getDeclaringClass() override;
50 virtual OUString SAL_CALL getName() override;
51 // XIdlField
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;
62 // XIdlMember
64 Reference< XIdlClass > IdlEnumFieldImpl::getDeclaringClass()
66 return IdlMemberImpl::getDeclaringClass();
69 OUString IdlEnumFieldImpl::getName()
71 return IdlMemberImpl::getName();
74 // XIdlField
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,
95 getXWeak() );
98 void IdlEnumFieldImpl::set( Any &, const Any & )
100 throw IllegalAccessException(
101 u"cannot set enum field, it is constant"_ustr,
102 getXWeak() );
106 EnumIdlClassImpl::~EnumIdlClassImpl()
110 // IdlClassImpl modifications
112 Reference< XIdlField > EnumIdlClassImpl::getField( const OUString & rName )
114 if (! m_xFields)
115 getFields(); // init members
117 const OUString2Field::const_iterator iFind( _aName2Field.find( rName ) );
118 if (iFind != _aName2Field.end())
119 return (*iFind).second;
120 else
121 return Reference< XIdlField >();
124 Sequence< Reference< XIdlField > > EnumIdlClassImpl::getFields()
126 if (! m_xFields)
128 ::osl::MutexGuard aGuard( getMutexAccess() );
129 if (! m_xFields)
131 sal_Int32 nFields = getTypeDescr()->nEnumValues;
132 Sequence< Reference< XIdlField > > aFields( nFields );
133 Reference< XIdlField > * pSeq = aFields.getArray();
135 while (nFields--)
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 );
145 return *m_xFields;
148 void EnumIdlClassImpl::createObject( Any & rObj )
150 sal_Int32 eVal =
151 reinterpret_cast<typelib_EnumTypeDescription *>(IdlClassImpl::getTypeDescr())->nDefaultEnumValue;
152 rObj.setValue( &eVal, IdlClassImpl::getTypeDescr() );
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */