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 #ifndef _BRIDGES_CPP_UNO_TYPE_MISC_HXX_
24 #define _BRIDGES_CPP_UNO_TYPE_MISC_HXX_
25
26 #include <sal/types.h>
27 #include <typelib/typedescription.h>
28
29
30 /** Determines whether given type might relate or relates to an interface,
31 i.e. values of this type are interface or may contain interface(s).<br>
32 @param pTypeDescr type description of type
33 @return true if type might relate to an interface, false otherwise
34 */
cppu_relatesToInterface(typelib_TypeDescription * pTypeDescr)35 inline bool cppu_relatesToInterface( typelib_TypeDescription * pTypeDescr ) SAL_THROW( () )
36 {
37 switch (pTypeDescr->eTypeClass)
38 {
39 // case typelib_TypeClass_TYPEDEF:
40 case typelib_TypeClass_SEQUENCE:
41 {
42 switch (((typelib_IndirectTypeDescription *)pTypeDescr)->pType->eTypeClass)
43 {
44 case typelib_TypeClass_INTERFACE:
45 case typelib_TypeClass_UNION: // might relate to interface
46 case typelib_TypeClass_ANY: // might relate to interface
47 return true;
48 case typelib_TypeClass_SEQUENCE:
49 case typelib_TypeClass_STRUCT:
50 case typelib_TypeClass_EXCEPTION:
51 {
52 typelib_TypeDescription * pTD = 0;
53 TYPELIB_DANGER_GET( &pTD, ((typelib_IndirectTypeDescription *)pTypeDescr)->pType );
54 bool bRel = cppu_relatesToInterface( pTD );
55 TYPELIB_DANGER_RELEASE( pTD );
56 return bRel;
57 }
58 default:
59 return false;
60 }
61 }
62 case typelib_TypeClass_STRUCT:
63 case typelib_TypeClass_EXCEPTION:
64 {
65 // ...optimized... to avoid getDescription() calls!
66 typelib_CompoundTypeDescription * pComp = (typelib_CompoundTypeDescription *)pTypeDescr;
67 typelib_TypeDescriptionReference ** pTypes = pComp->ppTypeRefs;
68 for ( sal_Int32 nPos = pComp->nMembers; nPos--; )
69 {
70 switch (pTypes[nPos]->eTypeClass)
71 {
72 case typelib_TypeClass_INTERFACE:
73 case typelib_TypeClass_UNION: // might relate to interface
74 case typelib_TypeClass_ANY: // might relate to interface
75 return true;
76 // case typelib_TypeClass_TYPEDEF:
77 case typelib_TypeClass_SEQUENCE:
78 case typelib_TypeClass_STRUCT:
79 case typelib_TypeClass_EXCEPTION:
80 {
81 typelib_TypeDescription * pTD = 0;
82 TYPELIB_DANGER_GET( &pTD, pTypes[nPos] );
83 bool bRel = cppu_relatesToInterface( pTD );
84 TYPELIB_DANGER_RELEASE( pTD );
85 if (bRel)
86 return true;
87 }
88 default:
89 break;
90 }
91 }
92 if (pComp->pBaseTypeDescription)
93 return cppu_relatesToInterface( (typelib_TypeDescription *)pComp->pBaseTypeDescription );
94 return false;
95 }
96 case typelib_TypeClass_UNION: // might relate to interface
97 case typelib_TypeClass_ANY: // might relate to interface
98 case typelib_TypeClass_INTERFACE:
99 return true;
100 default:
101 return false;
102 }
103 }
104
105 /** Determines whether given type is a cpp simple type, e.g. int, enum.<br>
106 @param eTypeClass type class of type
107 @return true if type is a cpp simple type, false otherwise
108 */
cppu_isSimpleType(typelib_TypeClass eTypeClass)109 inline bool cppu_isSimpleType( typelib_TypeClass eTypeClass ) SAL_THROW( () )
110 {
111 return (eTypeClass <= typelib_TypeClass_ENUM &&
112 eTypeClass != typelib_TypeClass_STRING &&
113 eTypeClass != typelib_TypeClass_ANY &&
114 eTypeClass != typelib_TypeClass_TYPE);
115 }
116 /** Determines whether given type is a cpp simple type, e.g. int, enum.<br>
117 @param pTypeDescr type description of type
118 @return true if type is a cpp simple type, false otherwise
119 */
cppu_isSimpleType(typelib_TypeDescription * pTypeDescr)120 inline bool cppu_isSimpleType( typelib_TypeDescription * pTypeDescr ) SAL_THROW( () )
121 {
122 return cppu_isSimpleType( pTypeDescr->eTypeClass );
123 }
124
125 #endif
126