xref: /AOO41X/main/stoc/source/registry_tdprovider/tdenum.cxx (revision 647a425c57429e1e89af1c7acf2de6af6f1bb730)
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     throw(::com::sun::star::uno::RuntimeException)
46 {
47     return TypeClass_ENUM;
48 }
49 //__________________________________________________________________________________________________
getName()50 OUString EnumTypeDescriptionImpl::getName()
51     throw(::com::sun::star::uno::RuntimeException)
52 {
53     return _aName;
54 }
55 
56 // XEnumTypeDescription
57 //__________________________________________________________________________________________________
getDefaultEnumValue()58 sal_Int32 EnumTypeDescriptionImpl::getDefaultEnumValue()
59     throw(::com::sun::star::uno::RuntimeException)
60 {
61     return _nDefaultValue;
62 }
63 //__________________________________________________________________________________________________
getEnumNames()64 Sequence< OUString > EnumTypeDescriptionImpl::getEnumNames()
65     throw(::com::sun::star::uno::RuntimeException)
66 {
67     if (! _pEnumNames)
68     {
69         typereg::Reader aReader(
70             _aBytes.getConstArray(), _aBytes.getLength(), false,
71             TYPEREG_VERSION_1);
72 
73         sal_uInt16 nFields = aReader.getFieldCount();
74         Sequence< OUString > * pTempEnumNames = new Sequence< OUString >( nFields );
75         OUString * pEnumNames = pTempEnumNames->getArray();
76 
77         while (nFields--)
78         {
79             pEnumNames[nFields] = aReader.getFieldName( nFields );
80         }
81 
82         ClearableMutexGuard aGuard( getMutex() );
83         if (_pEnumNames)
84         {
85             aGuard.clear();
86             delete pTempEnumNames;
87         }
88         else
89         {
90             _pEnumNames = pTempEnumNames;
91         }
92     }
93     return *_pEnumNames;
94 }
95 //__________________________________________________________________________________________________
getEnumValues()96 Sequence< sal_Int32 > EnumTypeDescriptionImpl::getEnumValues()
97     throw(::com::sun::star::uno::RuntimeException)
98 {
99     if (! _pEnumValues)
100     {
101         typereg::Reader aReader(
102             _aBytes.getConstArray(), _aBytes.getLength(), false,
103             TYPEREG_VERSION_1);
104 
105         sal_uInt16 nFields = aReader.getFieldCount();
106         Sequence< sal_Int32 > * pTempEnumValues = new Sequence< sal_Int32 >( nFields );
107         sal_Int32 * pEnumValues = pTempEnumValues->getArray();
108 
109         while (nFields--)
110         {
111             pEnumValues[nFields] = getRTValueAsInt32(
112                 aReader.getFieldValue( nFields ) );
113         }
114 
115         ClearableMutexGuard aGuard( getMutex() );
116         if (_pEnumValues)
117         {
118             aGuard.clear();
119             delete pTempEnumValues;
120         }
121         else
122         {
123             _pEnumValues = pTempEnumValues;
124         }
125     }
126     return *_pEnumValues;
127 }
128 
129 }
130 
131 
132