xref: /trunk/main/stoc/source/registry_tdprovider/tdenum.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_stoc.hxx"
30 #include "base.hxx"
31 
32 #include "registry/reader.hxx"
33 #include "registry/version.h"
34 
35 namespace stoc_rdbtdp
36 {
37 
38 //__________________________________________________________________________________________________
39 EnumTypeDescriptionImpl::~EnumTypeDescriptionImpl()
40 {
41     delete _pEnumNames;
42     delete _pEnumValues;
43     g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
44 }
45 
46 // XTypeDescription
47 //__________________________________________________________________________________________________
48 TypeClass EnumTypeDescriptionImpl::getTypeClass()
49     throw(::com::sun::star::uno::RuntimeException)
50 {
51     return TypeClass_ENUM;
52 }
53 //__________________________________________________________________________________________________
54 OUString EnumTypeDescriptionImpl::getName()
55     throw(::com::sun::star::uno::RuntimeException)
56 {
57     return _aName;
58 }
59 
60 // XEnumTypeDescription
61 //__________________________________________________________________________________________________
62 sal_Int32 EnumTypeDescriptionImpl::getDefaultEnumValue()
63     throw(::com::sun::star::uno::RuntimeException)
64 {
65     return _nDefaultValue;
66 }
67 //__________________________________________________________________________________________________
68 Sequence< OUString > EnumTypeDescriptionImpl::getEnumNames()
69     throw(::com::sun::star::uno::RuntimeException)
70 {
71     if (! _pEnumNames)
72     {
73         typereg::Reader aReader(
74             _aBytes.getConstArray(), _aBytes.getLength(), false,
75             TYPEREG_VERSION_1);
76 
77         sal_uInt16 nFields = aReader.getFieldCount();
78         Sequence< OUString > * pTempEnumNames = new Sequence< OUString >( nFields );
79         OUString * pEnumNames = pTempEnumNames->getArray();
80 
81         while (nFields--)
82         {
83             pEnumNames[nFields] = aReader.getFieldName( nFields );
84         }
85 
86         ClearableMutexGuard aGuard( getMutex() );
87         if (_pEnumNames)
88         {
89             aGuard.clear();
90             delete pTempEnumNames;
91         }
92         else
93         {
94             _pEnumNames = pTempEnumNames;
95         }
96     }
97     return *_pEnumNames;
98 }
99 //__________________________________________________________________________________________________
100 Sequence< sal_Int32 > EnumTypeDescriptionImpl::getEnumValues()
101     throw(::com::sun::star::uno::RuntimeException)
102 {
103     if (! _pEnumValues)
104     {
105         typereg::Reader aReader(
106             _aBytes.getConstArray(), _aBytes.getLength(), false,
107             TYPEREG_VERSION_1);
108 
109         sal_uInt16 nFields = aReader.getFieldCount();
110         Sequence< sal_Int32 > * pTempEnumValues = new Sequence< sal_Int32 >( nFields );
111         sal_Int32 * pEnumValues = pTempEnumValues->getArray();
112 
113         while (nFields--)
114         {
115             pEnumValues[nFields] = getRTValueAsInt32(
116                 aReader.getFieldValue( nFields ) );
117         }
118 
119         ClearableMutexGuard aGuard( getMutex() );
120         if (_pEnumValues)
121         {
122             aGuard.clear();
123             delete pTempEnumValues;
124         }
125         else
126         {
127             _pEnumValues = pTempEnumValues;
128         }
129     }
130     return *_pEnumValues;
131 }
132 
133 }
134 
135 
136