LibreOffice Module stoc (master) 1
crenum.cxx
Go to the documentation of this file.
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 "base.hxx"
21
24
25#include <com/sun/star/reflection/XIdlField2.hpp>
26
27using namespace css::lang;
28using namespace css::reflection;
29using namespace css::uno;
30
31namespace stoc_corefl
32{
33
34namespace {
35
36typedef cppu::ImplInheritanceHelper<IdlMemberImpl, XIdlField, XIdlField2> IdlEnumFieldImpl_Base;
37class IdlEnumFieldImpl : public IdlEnumFieldImpl_Base
38{
39 sal_Int32 _nValue;
40
41public:
42 IdlEnumFieldImpl( IdlReflectionServiceImpl * pReflection, const OUString & rName,
43 typelib_TypeDescription * pTypeDescr, sal_Int32 nValue )
44 : IdlEnumFieldImpl_Base( pReflection, rName, pTypeDescr, pTypeDescr )
45 , _nValue( nValue )
46 {}
47
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;
58};
59
60}
61
62// XIdlMember
63
64Reference< XIdlClass > IdlEnumFieldImpl::getDeclaringClass()
65{
67}
68
69OUString IdlEnumFieldImpl::getName()
70{
72}
73
74// XIdlField
75
76Reference< XIdlClass > IdlEnumFieldImpl::getType()
77{
78 return getDeclaringClass();
79}
80
81FieldAccessMode IdlEnumFieldImpl::getAccessMode()
82{
83 return FieldAccessMode_READONLY;
84}
85
86Any IdlEnumFieldImpl::get( const Any & )
87{
88 return Any( &_nValue, getTypeDescr() );
89}
90
91void IdlEnumFieldImpl::set( const Any &, const Any & )
92{
93 throw IllegalAccessException(
94 "cannot set enum field, it is constant",
95 getXWeak() );
96}
97
98void IdlEnumFieldImpl::set( Any &, const Any & )
99{
100 throw IllegalAccessException(
101 "cannot set enum field, it is constant",
102 getXWeak() );
103}
104
105
107{
108}
109
110// IdlClassImpl modifications
111
112Reference< XIdlField > EnumIdlClassImpl::getField( const OUString & rName )
113{
114 if (! m_xFields)
115 getFields(); // init members
116
117 const OUString2Field::const_iterator iFind( _aName2Field.find( rName ) );
118 if (iFind != _aName2Field.end())
119 return (*iFind).second;
120 else
121 return Reference< XIdlField >();
122}
123
124Sequence< Reference< XIdlField > > EnumIdlClassImpl::getFields()
125{
126 if (! m_xFields)
127 {
128 ::osl::MutexGuard aGuard( getMutexAccess() );
129 if (! m_xFields)
130 {
131 sal_Int32 nFields = getTypeDescr()->nEnumValues;
132 Sequence< Reference< XIdlField > > aFields( nFields );
133 Reference< XIdlField > * pSeq = aFields.getArray();
134
135 while (nFields--)
136 {
137 OUString aName( getTypeDescr()->ppEnumNames[nFields] );
138 _aName2Field[aName] = pSeq[nFields] = new IdlEnumFieldImpl(
139 getReflection(), aName, IdlClassImpl::getTypeDescr(), getTypeDescr()->pEnumValues[nFields] );
140 }
141
142 m_xFields = std::move( aFields );
143 }
144 }
145 return *m_xFields;
146}
147
149{
150 sal_Int32 eVal =
151 reinterpret_cast<typelib_EnumTypeDescription *>(IdlClassImpl::getTypeDescr())->nDefaultEnumValue;
152 rObj.setValue( &eVal, IdlClassImpl::getTypeDescr() );
153}
154
155}
156
157
158/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString2Field _aName2Field
Definition: base.hxx:280
virtual css::uno::Sequence< css::uno::Reference< css::reflection::XIdlField > > SAL_CALL getFields() override
Definition: crenum.cxx:124
typelib_EnumTypeDescription * getTypeDescr() const
Definition: base.hxx:283
virtual css::uno::Reference< css::reflection::XIdlField > SAL_CALL getField(const OUString &rName) override
Definition: crenum.cxx:112
std::optional< css::uno::Sequence< css::uno::Reference< css::reflection::XIdlField > > > m_xFields
Definition: base.hxx:279
virtual void SAL_CALL createObject(css::uno::Any &rObj) override
Definition: crenum.cxx:148
virtual ~EnumIdlClassImpl() override
Definition: crenum.cxx:106
IdlReflectionServiceImpl * getReflection() const
Definition: base.hxx:142
typelib_TypeDescription * getTypeDescr() const
Definition: base.hxx:140
virtual css::uno::Reference< css::reflection::XIdlClass > SAL_CALL getDeclaringClass() override
Definition: crbase.cxx:230
virtual OUString SAL_CALL getName() override
Definition: crbase.cxx:242
sal_Int32 _nValue
Definition: crenum.cxx:39
sal_Int16 nValue
OUString aName
Definition: invocation.cxx:689
struct _typelib_TypeDescription typelib_TypeDescription
void set(css::uno::UnoInterfaceReference const &value)
::osl::Mutex & getMutexAccess()
Definition: crbase.cxx:37
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
bool getType(BSTR name, Type &type)