rtgui_object.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * File : rtgui_object.h
  3. * This file is part of RTGUI in RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2009-10-04 Bernard first version
  13. */
  14. #ifndef __RTGUI_OBJECT_H__
  15. #define __RTGUI_OBJECT_H__
  16. #include <rtthread.h>
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /* rtgui object type */
  21. /** Casts the function pointer to an rtgui_constructor */
  22. #define RTGUI_CONSTRUCTOR(constructor) ((rtgui_constructor_t)(constructor))
  23. /** Casts the function pointer to an rtgui_constructor */
  24. #define RTGUI_DESTRUCTOR(destructor) ((rtgui_destructor_t)(destructor))
  25. /* pre-definetion */
  26. struct rtgui_object;
  27. typedef struct rtgui_object rtgui_object_t;
  28. typedef void (*rtgui_constructor_t)(rtgui_object_t *object);
  29. typedef void (*rtgui_destructor_t)(rtgui_object_t *object);
  30. /* rtgui type structure */
  31. struct rtgui_type
  32. {
  33. /* type name */
  34. char* name;
  35. /* hierarchy and depth */
  36. struct rtgui_type **hierarchy;
  37. int hierarchy_depth;
  38. /* constructor and destructor */
  39. rtgui_constructor_t constructor;
  40. rtgui_destructor_t destructor;
  41. /* size of type */
  42. int size;
  43. };
  44. typedef struct rtgui_type rtgui_type_t;
  45. rtgui_type_t *rtgui_type_create(const char *type_name, rtgui_type_t *parent_type,
  46. int type_size, rtgui_constructor_t constructor,
  47. rtgui_destructor_t destructor);
  48. void rtgui_type_destroy(rtgui_type_t *type);
  49. void rtgui_type_object_construct(rtgui_type_t *type, rtgui_object_t *object);
  50. void rtgui_type_destructors_call(rtgui_type_t *type, rtgui_object_t *object);
  51. rt_bool_t rtgui_type_inherits_from(rtgui_type_t *type, rtgui_type_t *parent);
  52. rtgui_type_t *rtgui_type_parent_type_get(rtgui_type_t *type);
  53. const char *rtgui_type_name_get(rtgui_type_t *type);
  54. rtgui_type_t *rtgui_type_get_from_name(const char *name);
  55. #ifdef RTGUI_USING_CAST_CHECK
  56. #define RTGUI_OBJECT_CAST(obj, rtgui_type_t, c_type) \
  57. ((c_type *)rtgui_object_check_cast((rtgui_object_t *)(obj), (rtgui_type_t)))
  58. #else
  59. #define RTGUI_OBJECT_CAST(obj, rtgui_type_t, c_type) ((c_type *)(obj))
  60. #endif
  61. #define RTGUI_OBJECT_CHECK_TYPE(_obj, _type) \
  62. (rtgui_type_inherits_from(((rtgui_object_t *)(_obj))->type, (_type)))
  63. /** Gets the type of an object */
  64. #define RTGUI_OBJECT_TYPE (rtgui_object_type_get())
  65. /** Casts the object to an rtgui_object_t */
  66. #define RTGUI_OBJECT(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_OBJECT_TYPE, rtgui_object_t))
  67. /** Checks if the object is an rtgui_Object */
  68. #define RTGUI_IS_OBJECT(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_OBJECT_TYPE))
  69. /* rtgui base object */
  70. struct rtgui_object
  71. {
  72. /* object type */
  73. rtgui_type_t* type;
  74. rt_bool_t is_static;
  75. };
  76. rtgui_type_t *rtgui_object_type_get(void);
  77. rtgui_object_t *rtgui_object_create(rtgui_type_t *object_type);
  78. void rtgui_object_destroy(rtgui_object_t *object);
  79. void rtgui_object_name_set(rtgui_object_t *object, const char *name);
  80. const char *rtgui_object_name_get(rtgui_object_t *object);
  81. rtgui_object_t *rtgui_object_check_cast(rtgui_object_t *object, rtgui_type_t *type);
  82. rtgui_type_t *rtk_object_object_type_get(rtgui_object_t *object);
  83. #ifdef __cplusplus
  84. }
  85. #endif
  86. #endif