LibreOffice Module cppu (master) 1
constr.hxx
Go to the documentation of this file.
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#pragma once
20
21#include "prim.hxx"
22#include <osl/diagnose.h>
23
24namespace cppu
25{
26
27
28//#### construction ################################################################################
29
30
32 void * pMem,
33 typelib_CompoundTypeDescription * pCompType );
34
36 void * pMem,
37 typelib_CompoundTypeDescription * pTypeDescr )
38{
39 if (pTypeDescr->pBaseTypeDescription)
40 {
41 defaultConstructStruct( pMem, pTypeDescr->pBaseTypeDescription );
42 }
43
44 typelib_TypeDescriptionReference ** ppTypeRefs = pTypeDescr->ppTypeRefs;
45 sal_Int32 * pMemberOffsets = pTypeDescr->pMemberOffsets;
46 sal_Int32 nDescr = pTypeDescr->nMembers;
47
48 while (nDescr--)
49 {
50 ::uno_type_constructData( static_cast<char *>(pMem) + pMemberOffsets[nDescr], ppTypeRefs[nDescr] );
51 }
52}
53
54
56 void * pMem,
57 typelib_TypeDescriptionReference * pType,
58 typelib_TypeDescription * pTypeDescr )
59{
60 switch (pType->eTypeClass)
61 {
62 case typelib_TypeClass_CHAR:
63 *static_cast<sal_Unicode *>(pMem) = '\0';
64 break;
65 case typelib_TypeClass_BOOLEAN:
66 *static_cast<sal_Bool *>(pMem) = false;
67 break;
68 case typelib_TypeClass_BYTE:
69 *static_cast<sal_Int8 *>(pMem) = 0;
70 break;
71 case typelib_TypeClass_SHORT:
72 case typelib_TypeClass_UNSIGNED_SHORT:
73 *static_cast<sal_Int16 *>(pMem) = 0;
74 break;
75 case typelib_TypeClass_LONG:
76 case typelib_TypeClass_UNSIGNED_LONG:
77 *static_cast<sal_Int32 *>(pMem) = 0;
78 break;
79 case typelib_TypeClass_HYPER:
80 case typelib_TypeClass_UNSIGNED_HYPER:
81 *static_cast<sal_Int64 *>(pMem) = 0;
82 break;
83 case typelib_TypeClass_FLOAT:
84 *static_cast<float *>(pMem) = 0.0;
85 break;
86 case typelib_TypeClass_DOUBLE:
87 *static_cast<double *>(pMem) = 0.0;
88 break;
89 case typelib_TypeClass_STRING:
90 *static_cast<rtl_uString **>(pMem) = nullptr;
91 ::rtl_uString_new( static_cast<rtl_uString **>(pMem) );
92 break;
93 case typelib_TypeClass_TYPE:
94 *static_cast<typelib_TypeDescriptionReference **>(pMem) = _getVoidType();
95 break;
96 case typelib_TypeClass_ANY:
97 CONSTRUCT_EMPTY_ANY( static_cast<uno_Any *>(pMem) );
98 break;
99 case typelib_TypeClass_ENUM:
100 if (pTypeDescr)
101 {
102 *static_cast<sal_Int32 *>(pMem) = reinterpret_cast<typelib_EnumTypeDescription *>(pTypeDescr)->nDefaultEnumValue;
103 }
104 else
105 {
106 TYPELIB_DANGER_GET( &pTypeDescr, pType );
107 *static_cast<sal_Int32 *>(pMem) = reinterpret_cast<typelib_EnumTypeDescription *>(pTypeDescr)->nDefaultEnumValue;
108 TYPELIB_DANGER_RELEASE( pTypeDescr );
109 }
110 break;
111 case typelib_TypeClass_STRUCT:
112 case typelib_TypeClass_EXCEPTION:
113 if (pTypeDescr)
114 {
115 _defaultConstructStruct( pMem, reinterpret_cast<typelib_CompoundTypeDescription *>(pTypeDescr) );
116 }
117 else
118 {
119 TYPELIB_DANGER_GET( &pTypeDescr, pType );
120 _defaultConstructStruct( pMem, reinterpret_cast<typelib_CompoundTypeDescription *>(pTypeDescr) );
121 TYPELIB_DANGER_RELEASE( pTypeDescr );
122 }
123 break;
124 case typelib_TypeClass_SEQUENCE:
125 *static_cast<uno_Sequence **>(pMem) = createEmptySequence();
126 break;
127 case typelib_TypeClass_INTERFACE:
128 *static_cast<void **>(pMem) = nullptr; // either cpp or c-uno interface
129 break;
130 default:
131 OSL_ASSERT(false);
132 break;
133 }
134}
135
136}
137
138/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SAL_CALL uno_type_constructData(void *pMem, typelib_TypeDescriptionReference *pType) SAL_THROW_EXTERN_C()
Definition: data.cxx:171
struct _typelib_TypeDescription typelib_TypeDescription
struct _uno_Any uno_Any
void _defaultConstructStruct(void *pMem, typelib_CompoundTypeDescription *pTypeDescr)
Definition: constr.hxx:35
void _defaultConstructData(void *pMem, typelib_TypeDescriptionReference *pType, typelib_TypeDescription *pTypeDescr)
Definition: constr.hxx:55
typelib_TypeDescriptionReference * _getVoidType()
Definition: prim.hxx:114
void defaultConstructStruct(void *pMem, typelib_CompoundTypeDescription *pCompType)
Definition: data.cxx:99
void CONSTRUCT_EMPTY_ANY(uno_Any *pAny)
Definition: prim.hxx:124
uno_Sequence * createEmptySequence()
Definition: prim.hxx:108
unsigned char sal_Bool
sal_uInt16 sal_Unicode
signed char sal_Int8