1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_stoc.hxx"
26 #include "base.hxx"
27
28 #include "registry/reader.hxx"
29 #include "registry/version.h"
30
31 namespace stoc_rdbtdp
32 {
33
34 //__________________________________________________________________________________________________
~EnumTypeDescriptionImpl()35 EnumTypeDescriptionImpl::~EnumTypeDescriptionImpl()
36 {
37 delete _pEnumNames;
38 delete _pEnumValues;
39 g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
40 }
41
42 // XTypeDescription
43 //__________________________________________________________________________________________________
getTypeClass()44 TypeClass EnumTypeDescriptionImpl::getTypeClass()
45 {
46 return TypeClass_ENUM;
47 }
48 //__________________________________________________________________________________________________
getName()49 OUString EnumTypeDescriptionImpl::getName()
50 {
51 return _aName;
52 }
53
54 // XEnumTypeDescription
55 //__________________________________________________________________________________________________
getDefaultEnumValue()56 sal_Int32 EnumTypeDescriptionImpl::getDefaultEnumValue()
57 {
58 return _nDefaultValue;
59 }
60 //__________________________________________________________________________________________________
getEnumNames()61 Sequence< OUString > EnumTypeDescriptionImpl::getEnumNames()
62 {
63 if (! _pEnumNames)
64 {
65 typereg::Reader aReader(
66 _aBytes.getConstArray(), _aBytes.getLength(), false,
67 TYPEREG_VERSION_1);
68
69 sal_uInt16 nFields = aReader.getFieldCount();
70 Sequence< OUString > * pTempEnumNames = new Sequence< OUString >( nFields );
71 OUString * pEnumNames = pTempEnumNames->getArray();
72
73 while (nFields--)
74 {
75 pEnumNames[nFields] = aReader.getFieldName( nFields );
76 }
77
78 ClearableMutexGuard aGuard( getMutex() );
79 if (_pEnumNames)
80 {
81 aGuard.clear();
82 delete pTempEnumNames;
83 }
84 else
85 {
86 _pEnumNames = pTempEnumNames;
87 }
88 }
89 return *_pEnumNames;
90 }
91 //__________________________________________________________________________________________________
getEnumValues()92 Sequence< sal_Int32 > EnumTypeDescriptionImpl::getEnumValues()
93 {
94 if (! _pEnumValues)
95 {
96 typereg::Reader aReader(
97 _aBytes.getConstArray(), _aBytes.getLength(), false,
98 TYPEREG_VERSION_1);
99
100 sal_uInt16 nFields = aReader.getFieldCount();
101 Sequence< sal_Int32 > * pTempEnumValues = new Sequence< sal_Int32 >( nFields );
102 sal_Int32 * pEnumValues = pTempEnumValues->getArray();
103
104 while (nFields--)
105 {
106 pEnumValues[nFields] = getRTValueAsInt32(
107 aReader.getFieldValue( nFields ) );
108 }
109
110 ClearableMutexGuard aGuard( getMutex() );
111 if (_pEnumValues)
112 {
113 aGuard.clear();
114 delete pTempEnumValues;
115 }
116 else
117 {
118 _pEnumValues = pTempEnumValues;
119 }
120 }
121 return *_pEnumValues;
122 }
123
124 }
125