plooc_class_simple_c90.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*****************************************************************************
  2. * Copyright(C)2009-2019 by GorgonMeducer<embedded_zhuoran@hotmail.com> *
  3. * and SimonQian<simonqian@simonqian.com> * with
  4. *support from HenryLong<henry_long@163.com> *
  5. * *
  6. * Licensed under the Apache License, Version 2.0 (the "License"); * you may
  7. *not use this file except in compliance with the License. * You may
  8. *obtain a copy of the License at *
  9. * *
  10. * http://www.apache.org/licenses/LICENSE-2.0 *
  11. * *
  12. * Unless required by applicable law or agreed to in writing, software *
  13. * distributed under the License is distributed on an "AS IS" BASIS, *
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. ** See the License for the specific language governing permissions and *
  16. * limitations under the License. *
  17. * *
  18. ****************************************************************************/
  19. /******************************************************************************
  20. * HOW TO USE *
  21. ******************************************************************************/
  22. //! Add following content to your module header file, e.g. xxxxxx.h
  23. //#include "plooc_class.h"
  24. /*============================ INCLUDES ======================================*/
  25. //#include <stdint.h>
  26. /*! \NOTE the uint_fast8_t used in this header file is defined in stdint.h
  27. if you don't have stdint.h supported in your toolchain, you should
  28. define uint_fast8_t all by yourself with following rule:
  29. a. if the target processor is 8 bits, define it as uint8_t
  30. b. if the target processor is 16 bits, define it as uint16_t
  31. c. if the target processor is 32 bits, define it as uint32_t
  32. d. if the target processor is 64 bits, define it as either uint32_t or
  33. uint64_t
  34. */
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. /*============================ MACROS ========================================*/
  39. #undef private_member
  40. #undef protected_member
  41. #undef public_member
  42. /*============================ MACROFIED FUNCTIONS
  43. * ===========================*/
  44. #ifndef __PLOOC_CLASS_SIMPLE_C90_H__
  45. #define __PLOOC_CLASS_SIMPLE_C90_H__
  46. #define __def_simple_class(__name) struct __name
  47. #define def_simple_class(__name) __def_simple_class(__name)
  48. #define define_simple_class(__name) def_simple_class(__name)
  49. #define declare_simple_class(__name) typedef struct __name __name;
  50. #define dcl_simple_class(__name) declare_simple_class(__name)
  51. #endif /* __PLOOC_CLASS_SIMPLE_H__ */
  52. #define private_member(__member) __member
  53. #define protected_member(__member) __member
  54. #define public_member(__member) __member
  55. // code below is just try to be compatible with plooc_class_strict
  56. #undef declare_class
  57. #undef dcl_class
  58. #undef def_class
  59. #undef define_class
  60. #undef __def_class
  61. #undef end_def_class
  62. #undef end_define_class
  63. #undef __end_def_class
  64. #undef extern_class
  65. #undef __extern_class
  66. #undef end_extern_class
  67. #undef __end_extern_class
  68. #define __end_def_class(__name)
  69. #define __def_class(__name, __member) \
  70. /*typedef struct __name __name; */ \
  71. struct __name { \
  72. __member \
  73. };
  74. #if defined(__PLOOC_CLASS_IMPLEMENT__) || defined(__PLOOC_CLASS_IMPLEMENT)
  75. #undef __class
  76. #define __class(__name) __name
  77. #undef class
  78. #define class(__name) __class(__name)
  79. #undef __class_internal
  80. #define __class_internal(__src, __des, __type) \
  81. class(__type) * (__des) = (class(__type)*)(__src);
  82. #undef class_internal
  83. #define class_internal(__src, __des, __type) \
  84. __class_internal(__src, __des, __type)
  85. #define __extern_class(__name, __member)
  86. #define __end_extern_class(__name)
  87. #elif defined(__PLOOC_CLASS_INHERIT__) || defined(__PLOOC_CLASS_INHERIT)
  88. #undef __class_protected
  89. #define __class_protected(__name) __name
  90. #undef class_protected
  91. #define class_protected(__name) __class_protected(__name)
  92. #undef __protected_internal
  93. #define __protected_internal(__src, __des, __type) \
  94. class_protected(__type) * (__des) = (class_protected(__type)*)(__src);
  95. #undef protected_internal
  96. #define protected_internal(__src, __des, __type) \
  97. __protected_internal(__src, __des, __type)
  98. #define __extern_class(__name, __member)
  99. #define __end_extern_class(__name)
  100. #else /* __PLOOC_CLASS_EXTERN */
  101. #define __extern_class(__name, __member) __def_class(__name, __member)
  102. #define __end_extern_class(__name)
  103. #endif
  104. #undef which
  105. #define which(__type) __type
  106. #define def_class(__name, __member) __def_class(__name, __member)
  107. #define define_class(__name, __member) def_class(__name, __member)
  108. #define end_def_class(__name) __end_def_class(__name)
  109. #define end_define_class(__name) end_def_class(__name)
  110. #define declare_class(__name) typedef struct __name __name;
  111. #define dcl_class(__name) declare_class(__name)
  112. #define extern_class(__name, __member) __extern_class(__name, __member)
  113. #define end_extern_class(__name) __end_extern_class(__name)
  114. #undef __PLOOC_CLASS_IMPLEMENT__
  115. #undef __PLOOC_CLASS_INHERIT__
  116. #undef __PLOOC_CLASS_IMPLEMENT
  117. #undef __PLOOC_CLASS_INHERIT
  118. /*============================ TYPES
  119. * =========================================*/
  120. /*============================ GLOBAL VARIABLES
  121. * ==============================*/
  122. /*============================ LOCAL VARIABLES
  123. * ===============================*/
  124. /*============================ PROTOTYPES
  125. * ====================================*/
  126. #ifdef __cplusplus
  127. }
  128. #endif