Line data Source code
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 :
22 : #include "registry/reader.hxx"
23 : #include "registry/version.h"
24 :
25 : namespace stoc_rdbtdp
26 : {
27 :
28 : //__________________________________________________________________________________________________
29 2358 : CompoundTypeDescriptionImpl::~CompoundTypeDescriptionImpl()
30 : {
31 786 : delete _pMembers;
32 786 : delete _pMemberNames;
33 786 : g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
34 1572 : }
35 :
36 : // XTypeDescription
37 : //__________________________________________________________________________________________________
38 1923 : TypeClass CompoundTypeDescriptionImpl::getTypeClass()
39 : throw(::com::sun::star::uno::RuntimeException)
40 : {
41 1923 : return _eTypeClass;
42 : }
43 : //__________________________________________________________________________________________________
44 2290 : OUString CompoundTypeDescriptionImpl::getName()
45 : throw(::com::sun::star::uno::RuntimeException)
46 : {
47 2290 : return _aName;
48 : }
49 :
50 : // XCompoundTypeDescription
51 : //__________________________________________________________________________________________________
52 751 : Reference< XTypeDescription > CompoundTypeDescriptionImpl::getBaseType()
53 : throw(::com::sun::star::uno::RuntimeException)
54 : {
55 751 : if (!_xBaseTD.is() && !_aBaseType.isEmpty())
56 : {
57 : try
58 : {
59 167 : Reference< XTypeDescription > xBaseTD;
60 167 : if (_xTDMgr->getByHierarchicalName( _aBaseType ) >>= xBaseTD)
61 : {
62 167 : MutexGuard aGuard( getMutex() );
63 167 : if (! _xBaseTD.is())
64 167 : _xBaseTD = xBaseTD;
65 167 : return _xBaseTD;
66 167 : }
67 : }
68 0 : catch (NoSuchElementException &)
69 : {
70 : }
71 : // never try again, if no base td was found
72 0 : _aBaseType = OUString();
73 : }
74 584 : return _xBaseTD;
75 : }
76 : //__________________________________________________________________________________________________
77 :
78 : namespace {
79 :
80 32 : class TypeParameter: public WeakImplHelper1< XTypeDescription > {
81 : public:
82 17 : explicit TypeParameter(OUString const & name): m_name(name) {}
83 :
84 128 : virtual TypeClass SAL_CALL getTypeClass() throw (RuntimeException)
85 128 : { return TypeClass_UNKNOWN; }
86 :
87 78 : virtual OUString SAL_CALL getName() throw (RuntimeException)
88 78 : { return m_name; }
89 :
90 : private:
91 : OUString m_name;
92 : };
93 :
94 : }
95 :
96 801 : Sequence< Reference< XTypeDescription > > CompoundTypeDescriptionImpl::getMemberTypes()
97 : throw(::com::sun::star::uno::RuntimeException)
98 : {
99 801 : if (! _pMembers)
100 : {
101 : typereg::Reader aReader(
102 1290 : _aBytes.getConstArray(), _aBytes.getLength(), false,
103 1290 : TYPEREG_VERSION_1);
104 :
105 645 : sal_uInt16 nFields = aReader.getFieldCount();
106 : Sequence< Reference< XTypeDescription > > * pTempMembers =
107 645 : new Sequence< Reference< XTypeDescription > >( nFields );
108 645 : Reference< XTypeDescription > * pMembers = pTempMembers->getArray();
109 :
110 3327 : while (nFields--)
111 : {
112 2037 : if ((aReader.getFieldFlags(nFields) & RT_ACCESS_PARAMETERIZED_TYPE)
113 : != 0)
114 : {
115 : pMembers[nFields] = new TypeParameter(
116 17 : aReader.getFieldTypeName(nFields));
117 : } else {
118 : try {
119 2020 : _xTDMgr->getByHierarchicalName(
120 2020 : aReader.getFieldTypeName(nFields).replace('/', '.'))
121 4040 : >>= pMembers[nFields];
122 0 : } catch (NoSuchElementException &) {}
123 : OSL_ENSURE(
124 : pMembers[nFields].is(), "### compound member unknown!");
125 : }
126 : }
127 :
128 645 : ClearableMutexGuard aGuard( getMutex() );
129 645 : if (_pMembers)
130 : {
131 0 : aGuard.clear();
132 0 : delete pTempMembers;
133 : }
134 : else
135 : {
136 645 : _pMembers = pTempMembers;
137 645 : }
138 : }
139 :
140 801 : return *_pMembers;
141 : }
142 : //__________________________________________________________________________________________________
143 751 : Sequence< OUString > CompoundTypeDescriptionImpl::getMemberNames()
144 : throw(::com::sun::star::uno::RuntimeException)
145 : {
146 751 : if (! _pMemberNames)
147 : {
148 : typereg::Reader aReader(
149 1290 : _aBytes.getConstArray(), _aBytes.getLength(), false,
150 1290 : TYPEREG_VERSION_1);
151 :
152 645 : sal_uInt16 nFields = aReader.getFieldCount();
153 645 : Sequence< OUString > * pTempMemberNames = new Sequence< OUString >( nFields );
154 645 : OUString * pMemberNames = pTempMemberNames->getArray();
155 :
156 3327 : while (nFields--)
157 : {
158 2037 : pMemberNames[nFields] = aReader.getFieldName( nFields );
159 : }
160 :
161 645 : ClearableMutexGuard aGuard( getMutex() );
162 645 : if (_pMemberNames)
163 : {
164 0 : aGuard.clear();
165 0 : delete pTempMemberNames;
166 : }
167 : else
168 : {
169 645 : _pMemberNames = pTempMemberNames;
170 645 : }
171 : }
172 751 : return *_pMemberNames;
173 : }
174 :
175 : }
176 :
177 :
178 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|