C++ TargetRTS
Loading...
Searching...
No Matches
RTObject_class.h
1/*
2 * Licensed Materials - Property of HCL and/or IBM
3 * Copyright HCL Technologies Ltd. 2016, 2021. All Rights Reserved.
4 * Copyright IBM Corporation 1999, 2016. All Rights Reserved.
5 *
6 * U.S. Government Users Restricted Rights - Use, duplication or
7 * disclosure restricted by GSA ADP Schedule.
8 */
9
10#ifndef __RTObject_class_h__
11#define __RTObject_class_h__ included
12
13#ifdef PRAGMA
14#pragma interface
15#endif
16
17#ifndef __RTFieldOffset_h__
18#include <RTFieldOffset.h>
19#endif
20
21#ifndef __RTVersionId_h__
22#include <RTVersionId.h>
23#endif
24
26struct RTObject_class;
27
28typedef void * ( * RTSuperAccessFunction )( void * derived );
29
30typedef void ( * RTInitFunction )( const RTObject_class * type,
31 void * target );
32
33typedef void ( * RTCopyFunction )( const RTObject_class *,
34 void * target,
35 const void * source );
36
37typedef void ( * RTMoveFunction )( const RTObject_class *,
38 void * target,
39 void * source );
40
41typedef void ( * RTDestroyFunction )( const RTObject_class * type,
42 void * target );
43
44#if OBJECT_DECODE
45 class RTDecoding;
46 typedef int ( * RTDecodeFunction )( const RTObject_class * type,
47 void * target,
48 RTDecoding * );
49#endif
50
51#if OBJECT_ENCODE
52 class RTEncoding;
53 typedef int ( * RTEncodeFunction )( const RTObject_class * type,
54 const void * source,
55 RTEncoding * );
56#endif
57
64{
65 enum DestroyOption
66 {
67 DestroyOnly,
68 DestroyAndDeallocate
69 };
70
71 // access functions
72
76 RTS_INLINE const RTObject_class * super ( void ) const;
77
81 RTS_INLINE const char * name ( void ) const;
82
87 RTS_INLINE RTVersionId version( void ) const;
88
93 int isKindOf( const RTObject_class * other) const;
94
98 void * allocate( void ) const;
99
104 RTS_INLINE void init( void * data) const;
105
110 RTS_INLINE void copy( void * to, const void * from) const;
111
116 RTS_INLINE void move( void * to, void * from) const;
117
118#if OBJECT_DECODE
119
126 RTS_INLINE int decode( void * data, RTDecoding * decoder) const;
127#endif
128#if OBJECT_ENCODE
129
136 RTS_INLINE int encode( const void * data, RTEncoding * encoder) const;
137#endif
138
144 void destroy( void * inst, DestroyOption opt) const;
145
157 void install( bool warnForDuplicates = true ) const;
158#if OBJECT_DECODE
159
164 static const RTObject_class * lookup( const char * className );
165#endif
166
172 template <typename TYPE> static const RTObject_class * fromType();
173
174 // implementation
175
178
180 RTSuperAccessFunction _super_accessor;
181
183 const char * _name;
184
186 RTVersionId _version;
187
189 RTFieldOffset _size;
190
191 // These function pointers must all be non-nil.
192
194 RTInitFunction _init_func;
195
197 RTCopyFunction _copy_func;
198
200 RTMoveFunction _move_func;
201
202
203#if OBJECT_DECODE
204
206 RTDecodeFunction _decode_func;
207#endif
208#if OBJECT_ENCODE
209
211 RTEncodeFunction _encode_func;
212#endif
213
215 RTDestroyFunction _destroy_func;
216
221
227};
228
229// Trivial (no-op) init, copy and destroy functions.
230 extern void RTnop_init( const RTObject_class *, void * );
231 extern void RTnop_copy( const RTObject_class *, void *, const void * );
232 extern void RTnop_move( const RTObject_class *, void *, void * );
233 extern void RTnop_destroy( const RTObject_class *, void * );
234
235// Functions for instances describing struct or class types
236 extern void RTstruct_init( const RTObject_class *, void * );
237 extern void RTstruct_copy( const RTObject_class *, void *, const void * );
238#if OBJECT_DECODE
239 extern int RTstruct_decode( const RTObject_class * type,
240 void * target,
241 RTDecoding * );
242#endif
243#if OBJECT_ENCODE
244 extern int RTstruct_encode( const RTObject_class * type,
245 const void * target,
246 RTEncoding * );
247#endif
248 extern void RTstruct_destroy( const RTObject_class *, void * );
249
250// Functions for instances describing enum types
251#if OBJECT_DECODE
252 extern int RTenum_decode( const RTObject_class * type,
253 void * target,
254 RTDecoding * );
255#endif
256#if OBJECT_ENCODE
257 extern int RTenum_encode( const RTObject_class * type,
258 const void * target,
259 RTEncoding * );
260#endif
261
262// Functions for instances which can inherit implementations
263#if OBJECT_DECODE
264 extern int RTinherit_decode( const RTObject_class * type,
265 void * target,
266 RTDecoding * );
267#endif
268#if OBJECT_ENCODE
269 extern int RTinherit_encode( const RTObject_class * type,
270 const void * target,
271 RTEncoding * );
272#endif
273
274// Functions for instances of RTObject_class describing arrays.
275 extern void RTarray_init( const RTObject_class *, void * );
276 extern void RTarray_copy( const RTObject_class *, void *, const void * );
277#if OBJECT_DECODE
278 extern int RTarray_decode( const RTObject_class * type,
279 void * target,
280 RTDecoding * );
281#endif
282#if OBJECT_ENCODE
283 extern int RTarray_encode( const RTObject_class * type,
284 const void * target,
285 RTEncoding * );
286#endif
287 extern void RTarray_destroy( const RTObject_class *, void * );
288
289// Init and copy functions for abstract classes: these simply panic.
290 extern void RTabstract_init( const RTObject_class *, void * );
291 extern void RTabstract_copy( const RTObject_class *, void *, const void * );
292 extern void RTabstract_move( const RTObject_class *, void *, void * );
293
294// Reusable basic type descriptors. The convention is that for a type called T,
295// one may refer to its type descriptor using the name RTType_T.
296// In some cases the name RTType_T will refer to a macro.
297
298 extern const RTObject_class RTType_void;
299 extern const RTObject_class RTType_bool;
300 extern const RTObject_class RTType_char;
301#if RTUseFloatingPoint
302 extern const RTObject_class RTType_double;
303 extern const RTObject_class RTType_float;
304#endif
305 extern const RTObject_class RTType_int;
306 extern const RTObject_class RTType_long;
307 extern const RTObject_class RTType_longdouble;
308 extern const RTObject_class RTType_longlong;
309 extern const RTObject_class RTType_short;
310 extern const RTObject_class RTType_unsigned;
311
312 extern const RTObject_class RTType_unsignedint;
313 extern const RTObject_class RTType_unsignedlong;
314 extern const RTObject_class RTType_unsignedlonglong;
315 extern const RTObject_class RTType_unsignedshort;
316 extern const RTObject_class RTType_unsignedchar;
317 typedef char * RTpchar;
318 typedef void * RTpvoid;
319 typedef unsigned char RTuchar;
320 typedef unsigned long RTulong;
321 typedef unsigned short RTushort;
322
323 extern const RTObject_class RTType_RTpchar;
324 extern const RTObject_class RTType_RTpvoid;
325 extern const RTObject_class RTType_RTuchar;
326 extern const RTObject_class RTType_RTulong;
327 extern const RTObject_class RTType_RTushort;
328
329 // Template specializations for mapping built-in types to type descriptors
330 template <> inline const RTObject_class* RTObject_class::fromType<int>() { return &RTType_int; }
331 template <> inline const RTObject_class* RTObject_class::fromType<char>() { return &RTType_char; }
332 template <> inline const RTObject_class* RTObject_class::fromType<float>() { return &RTType_float; }
333 template <> inline const RTObject_class* RTObject_class::fromType<bool>() { return &RTType_bool; }
334 template <> inline const RTObject_class* RTObject_class::fromType<double>() { return &RTType_double; }
335 template <> inline const RTObject_class* RTObject_class::fromType<short>() { return &RTType_short; }
336 template <> inline const RTObject_class* RTObject_class::fromType<long>() { return &RTType_long; }
337 template <> inline const RTObject_class* RTObject_class::fromType<long double>() { return &RTType_longdouble; }
338 template <> inline const RTObject_class* RTObject_class::fromType<long long>() { return &RTType_longlong; }
339 template <> inline const RTObject_class* RTObject_class::fromType<unsigned int>() { return &RTType_unsignedint; } // Same as RTType_unsigned
340 template <> inline const RTObject_class* RTObject_class::fromType<unsigned char>() { return &RTType_unsignedchar; } // Same as RTType_RTuchar
341 template <> inline const RTObject_class* RTObject_class::fromType<unsigned long>() { return &RTType_unsignedlong; } // Same as RTType_RTulong
342 template <> inline const RTObject_class* RTObject_class::fromType<unsigned long long>() { return &RTType_unsignedlonglong; }
343 template <> inline const RTObject_class* RTObject_class::fromType<unsigned short>() { return &RTType_unsignedshort; } // Same as RTType_RTushort
344 template <> inline const RTObject_class* RTObject_class::fromType<char*>() { return &RTType_RTpchar; }
345
346
347#if OBJECT_DECODE
349{
350public:
351 explicit RTTypeInstaller( const RTObject_class & );
352
353 static void installAll( void );
354
355private:
356 static RTTypeInstaller * _head;
357 RTTypeInstaller * _next;
358 const RTObject_class * _type;
359
360 // unavailable methods
362 RTTypeInstaller & operator=( const RTTypeInstaller & );
363}; //lint !e1712
364#endif // OBJECT_DECODE
365
366#if RTS_INLINES
367#include <RTObject_class.inl>
368#endif
369
370#endif // __RTObject_class_h__
Definition: RTDecoding.h:27
Definition: RTEncoding.h:27
Definition: RTObject_class.h:349
Definition: RTFieldDescriptor.h:40
A type descriptor providing information about a type.
Definition: RTObject_class.h:64
RTEncodeFunction _encode_func
The encode function of the type.
Definition: RTObject_class.h:211
RTInitFunction _init_func
The init function of the type, i.e.
Definition: RTObject_class.h:194
int encode(const void *data, RTEncoding *encoder) const
Encode an instance of the described type into an external representation (e.g.
Definition: RTObject_class.inl:64
RTDestroyFunction _destroy_func
The destroy function of the type, i.e.
Definition: RTObject_class.h:215
RTMoveFunction _move_func
The move function of the type, i.e.
Definition: RTObject_class.h:200
int _num_fields
This variable is used for structured and array-like types to specify the number of fields or elements...
Definition: RTObject_class.h:220
void destroy(void *inst, DestroyOption opt) const
Destroy an instance of the described type.
void copy(void *to, const void *from) const
Make a copy of an instance of the described type.
Definition: RTObject_class.inl:41
int isKindOf(const RTObject_class *other) const
Determines if the described type is the same, or a subtype of, another type.
void install(bool warnForDuplicates=true) const
Register the type descriptor so it can be looked up quickly using the name of the described type as t...
void move(void *to, void *from) const
Move an instance of the described type.
Definition: RTObject_class.inl:46
const RTObject_class * _super
The super type from which the type inherits.
Definition: RTObject_class.h:177
const RTObject_class * super(void) const
Get the descriptor for the super type, i.e.
Definition: RTObject_class.inl:21
void init(void *data) const
Initialize an instance of the described type.
Definition: RTObject_class.inl:36
const char * name(void) const
Get the name of the described type.
Definition: RTObject_class.inl:26
RTDecodeFunction _decode_func
The decode function of the type.
Definition: RTObject_class.h:206
void * allocate(void) const
Allocate new memory for holding an instance of the described type.
RTVersionId _version
The version id of the type.
Definition: RTObject_class.h:186
RTVersionId version(void) const
Get the version of the described type.
Definition: RTObject_class.inl:31
RTFieldOffset _size
The size (in bytes) of the type.
Definition: RTObject_class.h:189
RTCopyFunction _copy_func
The copy function of the type, i.e.
Definition: RTObject_class.h:197
const RTFieldDescriptor * _fields
This variable is used for structured and array-like types to specify the type of fields or elements t...
Definition: RTObject_class.h:226
int decode(void *data, RTDecoding *decoder) const
Decode an external representation (e.g.
Definition: RTObject_class.inl:56
RTSuperAccessFunction _super_accessor
The super object accessor function for this type.
Definition: RTObject_class.h:180
static const RTObject_class * lookup(const char *className)
Lookup a type descriptor by the name of the type it describes.
static const RTObject_class * fromType()
Get a type descriptor from a type TYPE at compile-time.
Definition: RTObject_class.inl:72
const char * _name
The name of the type.
Definition: RTObject_class.h:183