update emoji autocorrect entries from po-files
[LibreOffice.git] / stoc / source / corereflection / crenum.cxx
blob8cd09763aeb9632ccc255e42420716d36ee74d1c
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>
24 using namespace css::lang;
25 using namespace css::reflection;
26 using namespace css::uno;
28 namespace stoc_corefl
32 class IdlEnumFieldImpl
33 : public IdlMemberImpl
34 , public XIdlField
35 , public XIdlField2
37 sal_Int32 _nValue;
39 public:
40 IdlEnumFieldImpl( IdlReflectionServiceImpl * pReflection, const OUString & rName,
41 typelib_TypeDescription * pTypeDescr, sal_Int32 nValue )
42 : IdlMemberImpl( pReflection, rName, pTypeDescr, pTypeDescr )
43 , _nValue( nValue )
45 virtual ~IdlEnumFieldImpl();
47 // XInterface
48 virtual Any SAL_CALL queryInterface( const Type & rType ) throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
49 virtual void SAL_CALL acquire() throw() SAL_OVERRIDE;
50 virtual void SAL_CALL release() throw() SAL_OVERRIDE;
52 // XTypeProvider
53 virtual Sequence< Type > SAL_CALL getTypes() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
54 virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
56 // XIdlMember
57 virtual Reference< XIdlClass > SAL_CALL getDeclaringClass() throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
58 virtual OUString SAL_CALL getName() throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
59 // XIdlField
60 virtual Reference< XIdlClass > SAL_CALL getType() throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
61 virtual FieldAccessMode SAL_CALL getAccessMode() throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
62 virtual Any SAL_CALL get( const Any & rObj ) throw(css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
63 virtual void SAL_CALL set( const Any & rObj, const Any & rValue ) throw(css::lang::IllegalArgumentException, css::lang::IllegalAccessException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
64 // XIdlField2: getType, getAccessMode and get are equal to XIdlField
65 virtual void SAL_CALL set( Any & rObj, const Any & rValue ) throw(css::lang::IllegalArgumentException, css::lang::IllegalAccessException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
68 IdlEnumFieldImpl::~IdlEnumFieldImpl()
72 // XInterface
74 Any IdlEnumFieldImpl::queryInterface( const Type & rType )
75 throw(css::uno::RuntimeException, std::exception)
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();
93 // XTypeProvider
95 Sequence< Type > IdlEnumFieldImpl::getTypes()
96 throw (css::uno::RuntimeException, std::exception)
98 static ::cppu::OTypeCollection * s_pTypes = 0;
99 if (! s_pTypes)
101 ::osl::MutexGuard aGuard( getMutexAccess() );
102 if (! s_pTypes)
104 static ::cppu::OTypeCollection s_aTypes(
105 cppu::UnoType<XIdlField2>::get(),
106 cppu::UnoType<XIdlField>::get(),
107 IdlMemberImpl::getTypes() );
108 s_pTypes = &s_aTypes;
111 return s_pTypes->getTypes();
114 Sequence< sal_Int8 > IdlEnumFieldImpl::getImplementationId()
115 throw (css::uno::RuntimeException, std::exception)
117 return css::uno::Sequence<sal_Int8>();
120 // XIdlMember
122 Reference< XIdlClass > IdlEnumFieldImpl::getDeclaringClass()
123 throw(css::uno::RuntimeException, std::exception)
125 return IdlMemberImpl::getDeclaringClass();
128 OUString IdlEnumFieldImpl::getName()
129 throw(css::uno::RuntimeException, std::exception)
131 return IdlMemberImpl::getName();
134 // XIdlField
136 Reference< XIdlClass > IdlEnumFieldImpl::getType()
137 throw(css::uno::RuntimeException, std::exception)
139 return getDeclaringClass();
142 FieldAccessMode IdlEnumFieldImpl::getAccessMode()
143 throw(css::uno::RuntimeException, std::exception)
145 return FieldAccessMode_READONLY;
148 Any IdlEnumFieldImpl::get( const Any & )
149 throw(css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception)
151 return Any( &_nValue, getTypeDescr() );
154 void IdlEnumFieldImpl::set( const Any &, const Any & )
155 throw(css::lang::IllegalArgumentException, css::lang::IllegalAccessException, css::uno::RuntimeException, std::exception)
157 throw IllegalAccessException(
158 "enum field is constant!",
159 (XWeak *)(OWeakObject *)this );
162 void IdlEnumFieldImpl::set( Any &, const Any & )
163 throw(css::lang::IllegalArgumentException, css::lang::IllegalAccessException, css::uno::RuntimeException, std::exception)
165 throw IllegalAccessException(
166 "enum field is constant!",
167 (XWeak *)(OWeakObject *)this );
176 EnumIdlClassImpl::~EnumIdlClassImpl()
178 delete _pFields;
181 // IdlClassImpl modifications
183 Reference< XIdlField > EnumIdlClassImpl::getField( const OUString & rName )
184 throw(css::uno::RuntimeException, std::exception)
186 if (! _pFields)
187 getFields(); // init members
189 const OUString2Field::const_iterator iFind( _aName2Field.find( rName ) );
190 if (iFind != _aName2Field.end())
191 return (*iFind).second;
192 else
193 return Reference< XIdlField >();
196 Sequence< Reference< XIdlField > > EnumIdlClassImpl::getFields()
197 throw(css::uno::RuntimeException, std::exception)
199 if (! _pFields)
201 ::osl::MutexGuard aGuard( getMutexAccess() );
202 if (! _pFields)
204 sal_Int32 nFields = getTypeDescr()->nEnumValues;
205 Sequence< Reference< XIdlField > > * pFields =
206 new Sequence< Reference< XIdlField > >( nFields );
207 Reference< XIdlField > * pSeq = pFields->getArray();
209 while (nFields--)
211 OUString aName( getTypeDescr()->ppEnumNames[nFields] );
212 _aName2Field[aName] = pSeq[nFields] = new IdlEnumFieldImpl(
213 getReflection(), aName, IdlClassImpl::getTypeDescr(), getTypeDescr()->pEnumValues[nFields] );
216 _pFields = pFields;
219 return *_pFields;
222 void EnumIdlClassImpl::createObject( Any & rObj )
223 throw(css::uno::RuntimeException, std::exception)
225 sal_Int32 eVal =
226 reinterpret_cast<typelib_EnumTypeDescription *>(IdlClassImpl::getTypeDescr())->nDefaultEnumValue;
227 rObj.setValue( &eVal, IdlClassImpl::getTypeDescr() );
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */