1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
24 #include <tools/solar.h>
26 typedef void* (*TypeId
)();
29 static void* CreateType(); \
30 static TypeId StaticType(); \
31 static sal_Bool IsOf( TypeId aSameOrSuperType ); \
32 virtual TypeId Type() const; \
33 virtual sal_Bool IsA( TypeId aSameOrSuperType ) const
35 #define TYPEINFO_VISIBILITY(visibility) \
36 visibility static void* CreateType(); \
37 visibility static TypeId StaticType(); \
38 visibility static sal_Bool IsOf( TypeId aSameOrSuperType ); \
39 visibility virtual TypeId Type() const; \
40 visibility virtual sal_Bool IsA( TypeId aSameOrSuperType ) const
42 #define TYPEINIT_FACTORY(sType, Factory ) \
43 void* sType::CreateType() { return Factory; } \
44 TypeId sType::StaticType() { return &CreateType; } \
45 TypeId sType::Type() const { return &CreateType; } \
46 sal_Bool sType::IsOf( TypeId aSameOrSuperType ) \
48 if ( aSameOrSuperType == StaticType() ) \
51 #define STATICTYPE(sType) (sType::StaticType())
53 #define SUPERTYPE(sSuper) \
54 if ( sSuper::IsOf(aSameOrSuperType ) ) \
57 #define TYPEINIT_END(sType) \
60 sal_Bool sType::IsA( TypeId aSameOrSuperType ) const \
61 { return IsOf( aSameOrSuperType ); }
63 #define TYPEINIT0_FACTORY(sType, Factory) \
64 TYPEINIT_FACTORY(sType, Factory); \
66 #define TYPEINIT0_AUTOFACTORY(sType) TYPEINIT0_FACTORY(sType, new sType)
67 #define TYPEINIT0(sType) TYPEINIT0_FACTORY(sType, 0)
69 #define TYPEINIT1_FACTORY(sType, sSuper, Factory) \
70 TYPEINIT_FACTORY(sType, Factory); \
73 #define TYPEINIT1_AUTOFACTORY(sType, sSuper) \
74 TYPEINIT1_FACTORY(sType, sSuper, new sType)
75 #define TYPEINIT1(sType, sSuper) \
76 TYPEINIT1_FACTORY(sType, sSuper, 0)
78 #define TYPEINIT2_FACTORY(sType, sSuper1, sSuper2, Factory) \
79 TYPEINIT_FACTORY(sType, Factory); \
83 #define TYPEINIT2_AUTOFACTORY(sType, sSuper1, sSuper2) \
84 TYPEINIT2_FACTORY(sType, sSuper1, sSuper2, new sType)
85 #define TYPEINIT2(sType, sSuper1, sSuper2) \
86 TYPEINIT2_FACTORY(sType, sSuper1, sSuper2, 0)
88 #define TYPEINIT3_FACTORY(sType, sSuper1, sSuper2, sSuper3, Factory) \
89 TYPEINIT_FACTORY(sType, Factory); \
94 #define TYPEINIT3(sType, sSuper1, sSuper2, sSuper3) \
95 TYPEINIT3_FACTORY(sType, sSuper1, sSuper2, sSuper3, 0)
97 #define TYPE(sType) (sType::StaticType())
98 #define ISA(sType) IsA(sType::StaticType())
99 #define ISOF(sType) IsOf(sType::StaticType())
100 #define CREATE(TypeId) (TypeId())
102 /** Exemplary application macros for pointers
103 (can be extended for use with references)
105 PTR_CAST: Safe pointer casting to a derived class.
106 Returns NULL pointer on cast error
108 T: Target type to cast into
109 p: Pointer to be cast into T
111 #define PTR_CAST( T, pObj ) \
112 ( pObj && (pObj)->IsA( TYPE(T) ) ? (T*)(pObj) : 0 )
114 /** Check whether object pObj has a Base Class T
115 (or if pObj is an instance of T) */
116 #define HAS_BASE( T, pObj ) \
117 ( pObj && (pObj)->IsA( TYPE(T) ) )
119 /** Check whether a pointer is targetting and object of type T. */
120 #define IS_TYPE(T,pObj) \
121 ( pObj && (pObj)->Type() == TYPE(T) )
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */