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 
27 #include "structtypedescription.hxx"
28 
29 #include "base.hxx"
30 
31 #include "com/sun/star/reflection/XTypeDescription.hpp"
32 #include "com/sun/star/uno/Reference.hxx"
33 #include "com/sun/star/uno/RuntimeException.hpp"
34 #include "com/sun/star/uno/Sequence.hxx"
35 #include "com/sun/star/uno/TypeClass.hpp"
36 #include "cppuhelper/weak.hxx"
37 #include "osl/diagnose.h"
38 #include "registry/reader.hxx"
39 #include "registry/types.h"
40 #include "registry/version.h"
41 #include "rtl/ustring.h"
42 #include "rtl/ustring.hxx"
43 
44 #include <new>
45 
46 namespace css = com::sun::star;
47 using stoc::registry_tdprovider::StructTypeDescription;
48 
StructTypeDescription(css::uno::Reference<css::container::XHierarchicalNameAccess> const & manager,rtl::OUString const & name,rtl::OUString const & baseTypeName,css::uno::Sequence<sal_Int8> const & data,bool published)49 StructTypeDescription::StructTypeDescription(
50     css::uno::Reference< css::container::XHierarchicalNameAccess > const &
51         manager,
52     rtl::OUString const & name, rtl::OUString const & baseTypeName,
53     css::uno::Sequence< sal_Int8 > const & data, bool published):
54     m_data(data),
55     m_base(
56         new stoc_rdbtdp::CompoundTypeDescriptionImpl(
57             manager, css::uno::TypeClass_STRUCT, name, baseTypeName, data,
58             published))
59 {}
60 
~StructTypeDescription()61 StructTypeDescription::~StructTypeDescription()
62 {}
63 
getTypeClass()64 css::uno::TypeClass StructTypeDescription::getTypeClass()
65     throw (css::uno::RuntimeException)
66 {
67     return m_base->getTypeClass();
68 }
69 
getName()70 rtl::OUString StructTypeDescription::getName()
71     throw (css::uno::RuntimeException)
72 {
73     return m_base->getName();
74 }
75 
76 css::uno::Reference< css::reflection::XTypeDescription >
getBaseType()77 StructTypeDescription::getBaseType() throw (css::uno::RuntimeException)
78 {
79     return m_base->getBaseType();
80 }
81 
82 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
getMemberTypes()83 StructTypeDescription::getMemberTypes() throw (css::uno::RuntimeException)
84 {
85     return m_base->getMemberTypes();
86 }
87 
getMemberNames()88 css::uno::Sequence< rtl::OUString > StructTypeDescription::getMemberNames()
89     throw (css::uno::RuntimeException)
90 {
91     return m_base->getMemberNames();
92 }
93 
getTypeParameters()94 css::uno::Sequence< rtl::OUString > StructTypeDescription::getTypeParameters()
95     throw (css::uno::RuntimeException)
96 {
97     try {
98         typereg::Reader reader(
99             m_data.getConstArray(), m_data.getLength(), false,
100             TYPEREG_VERSION_1);
101         OSL_ASSERT(reader.isValid());
102         sal_uInt16 n = reader.getReferenceCount();
103         css::uno::Sequence< rtl::OUString > parameters(n);
104         for (sal_uInt16 i = 0; i < n; ++i) {
105             if (reader.getReferenceFlags(i) != RT_ACCESS_INVALID
106                 || reader.getReferenceSort(i) != RT_REF_TYPE_PARAMETER)
107             {
108                 throw css::uno::RuntimeException(
109                     rtl::OUString(
110                         RTL_CONSTASCII_USTRINGPARAM(
111                             "type parameter of polymorphic struct type template"
112                             " not RT_ACCESS_INVALID/RT_REF_TYPE_PARAMETER")),
113                     static_cast< cppu::OWeakObject * >(this));
114             }
115             parameters[i] = reader.getReferenceTypeName(i);
116         }
117         return parameters;
118     } catch (std::bad_alloc &) {
119         throw css::uno::RuntimeException(
120             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("std::bad_alloc")),
121             static_cast< cppu::OWeakObject * >(this));
122     }
123 }
124 
125 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
getTypeArguments()126 StructTypeDescription::getTypeArguments() throw (css::uno::RuntimeException)
127 {
128     return css::uno::Sequence<
129         css::uno::Reference< css::reflection::XTypeDescription > >();
130 }
131 
isPublished()132 sal_Bool StructTypeDescription::isPublished() throw (css::uno::RuntimeException)
133 {
134     return m_base->isPublished();
135 }
136