diff --git a/.gitignore b/.gitignore index 9c117ea..41a7b3d 100644 --- a/.gitignore +++ b/.gitignore @@ -65,4 +65,9 @@ dkms.conf example/project/mdk/Objects example/project/mdk/RTE/Compiler/.* example/project/mdk/RTE/Device/ARMCM3/.* -example/project/mdk/plooc_example.uvguix.* \ No newline at end of file +example/project/mdk/plooc_example.uvguix.* +CI/PLOOC_template_gcc/MDK-ARM/DebugConfig/PLOOC_template_gcc_STM32F103RC_1.0.0.dbgconf +*@* +*.uvguix.* +RTE_Components.h + diff --git a/CI/PLOOC_template_gcc/MDK-ARM/PLOOC_template_gcc.uvprojx b/CI/PLOOC_template_gcc/MDK-ARM/PLOOC_template_gcc.uvprojx index 91905c1..9d4f055 100644 --- a/CI/PLOOC_template_gcc/MDK-ARM/PLOOC_template_gcc.uvprojx +++ b/CI/PLOOC_template_gcc/MDK-ARM/PLOOC_template_gcc.uvprojx @@ -10,8 +10,7 @@ PLOOC_template_gcc 0x4 ARM-ADS - 6160000::V6.16::ARMCLANG - 6160000::V6.16::ARMCLANG + 6210000::V6.21::.\ArmCompilerforEmbedded6.21 1 @@ -187,6 +186,7 @@ 0 0 0 + 0 0 0 8 diff --git a/CI/PLOOC_template_gcc/MDK-ARM/PLOOC_template_gcc/PLOOC_template_gcc.sct b/CI/PLOOC_template_gcc/MDK-ARM/PLOOC_template_gcc/PLOOC_template_gcc.sct new file mode 100644 index 0000000..6afe81f --- /dev/null +++ b/CI/PLOOC_template_gcc/MDK-ARM/PLOOC_template_gcc/PLOOC_template_gcc.sct @@ -0,0 +1,16 @@ +; ************************************************************* +; *** Scatter-Loading Description File generated by uVision *** +; ************************************************************* + +LR_IROM1 0x08000000 0x00040000 { ; load region size_region + ER_IROM1 0x08000000 0x00040000 { ; load address = execution address + *.o (RESET, +First) + *(InRoot$$Sections) + .ANY (+RO) + .ANY (+XO) + } + RW_IRAM1 0x20000000 0x0000C000 { ; RW data + .ANY (+RW +ZI) + } +} + diff --git a/GorgonMeducer.PLOOC.pdsc b/GorgonMeducer.PLOOC.pdsc index daa6c0b..7e54a2c 100644 --- a/GorgonMeducer.PLOOC.pdsc +++ b/GorgonMeducer.PLOOC.pdsc @@ -16,7 +16,12 @@ https://github.com/GorgonMeducer/PLOOC.git - + + - Add private_method, protected_method and public_method + - Add plooc_malloc_align and plooc_free + - Other minor changes. + + - Improve compatibility with the latest C++ - Fix template @@ -88,15 +93,15 @@ --> - + A low-overhead OOPC template. - - - - + + + + diff --git a/README.md b/README.md index de84193..456cfdc 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# PLOOC (Protected Low-overhead Object-Oriented Programming with ANSI-C) v4.6.3 +# PLOOC (Protected Low-overhead Object-Oriented Programming with ANSI-C) v4.6.4 ## Introduction @@ -81,12 +81,23 @@ If you have any questions or suggestions, please feel free to let us know. ## Update Log --- -- \[11/02/2022\] Fix class template, version 4.6.3 +- \[08/25/2024\] Fix class template, version 4.6.4 + - Updated Readme -- \[12/05/2022\] Improve compatibility with the latest C++ language, version 4.6.2 + - Add `__plooc_malloc_align()` and `__plooc_free` + + - Add `private_method()`, `protected_method()` and `public_method()` + + - Remove the dependency on the GNU extensions + + - Other minor changes. +- \[11/02/2022\] Fix class template, version 4.6.3 + +- \[12/05/2022\] Improve compatibility with the latest C++ language, version 4.6.2 + - \[02/01/2022\] Add helper macros for heap, version 4.6.1 - - Add ***\_\_new_class()*** and ***\_\_free_class()*** for using malloc and free together with constructors and destructors, i.e. ***xxxx_init()*** and ***xxxx_depose()***. + - Add `__new_class()` and `__free_class()` for using malloc and free together with constructors and destructors, i.e. ***xxxx_init()*** and ***xxxx_depose()***. - Update example project - Add CI to github. diff --git a/cmsis-pack/GorgonMeducer.PLOOC.4.6.3.pack b/cmsis-pack/GorgonMeducer.PLOOC.4.6.3.pack deleted file mode 100644 index 0624537..0000000 Binary files a/cmsis-pack/GorgonMeducer.PLOOC.4.6.3.pack and /dev/null differ diff --git a/cmsis-pack/GorgonMeducer.PLOOC.4.6.4.pack b/cmsis-pack/GorgonMeducer.PLOOC.4.6.4.pack new file mode 100644 index 0000000..115a11d Binary files /dev/null and b/cmsis-pack/GorgonMeducer.PLOOC.4.6.4.pack differ diff --git a/cmsis-pack/GorgonMeducer.PLOOC.pdsc b/cmsis-pack/GorgonMeducer.PLOOC.pdsc index daa6c0b..7e54a2c 100644 --- a/cmsis-pack/GorgonMeducer.PLOOC.pdsc +++ b/cmsis-pack/GorgonMeducer.PLOOC.pdsc @@ -16,7 +16,12 @@ https://github.com/GorgonMeducer/PLOOC.git - + + - Add private_method, protected_method and public_method + - Add plooc_malloc_align and plooc_free + - Other minor changes. + + - Improve compatibility with the latest C++ - Fix template @@ -88,15 +93,15 @@ --> - + A low-overhead OOPC template. - - - - + + + + diff --git a/example/byte_queue/byte_queue.h b/example/byte_queue/byte_queue.h index b129ec5..08a9499 100644 --- a/example/byte_queue/byte_queue.h +++ b/example/byte_queue/byte_queue.h @@ -113,9 +113,10 @@ void *byte_queue_target_get(byte_queue_t *ptObj); extern void byte_queue_target_set(byte_queue_t *ptObj, void *pTarget); -#if defined(__BYTE_QUEUE_CLASS_IMPLEMENT) || defined(__BYTE_QUEUE_CLASS_INHERIT__) -extern mem_t byte_queue_buffer_get(byte_queue_t *ptObj); -#endif +/* protected methods that only derived class can see */ +protected_method( + extern mem_t byte_queue_buffer_get(byte_queue_t *ptObj); +) /*! \note it is very important to undef those macros */ #undef __BYTE_QUEUE_CLASS_INHERIT diff --git a/example/project/mdk/RTE/Device/ARMCM3/ARMCM3_ac6.sct b/example/project/mdk/RTE/Device/ARMCM3/ARMCM3_ac6.sct new file mode 100644 index 0000000..4309a0b --- /dev/null +++ b/example/project/mdk/RTE/Device/ARMCM3/ARMCM3_ac6.sct @@ -0,0 +1,80 @@ +#! armclang -E --target=arm-arm-none-eabi -mcpu=cortex-m3 -xc +; command above MUST be in first line (no comment above!) + +/* +;-------- <<< Use Configuration Wizard in Context Menu >>> ------------------- +*/ + +/*--------------------- Flash Configuration ---------------------------------- +; Flash Configuration +; Flash Base Address <0x0-0xFFFFFFFF:8> +; Flash Size (in Bytes) <0x0-0xFFFFFFFF:8> +; + *----------------------------------------------------------------------------*/ +#define __ROM_BASE 0x00000000 +#define __ROM_SIZE 0x00080000 + +/*--------------------- Embedded RAM Configuration --------------------------- +; RAM Configuration +; RAM Base Address <0x0-0xFFFFFFFF:8> +; RAM Size (in Bytes) <0x0-0xFFFFFFFF:8> +; + *----------------------------------------------------------------------------*/ +#define __RAM_BASE 0x20000000 +#define __RAM_SIZE 0x00040000 + +/*--------------------- Stack / Heap Configuration --------------------------- +; Stack / Heap Configuration +; Stack Size (in Bytes) <0x0-0xFFFFFFFF:8> +; Heap Size (in Bytes) <0x0-0xFFFFFFFF:8> +; + *----------------------------------------------------------------------------*/ +#define __STACK_SIZE 0x00000200 +#define __HEAP_SIZE 0x00000C00 + +/* +;------------- <<< end of configuration section >>> --------------------------- +*/ + + +/*---------------------------------------------------------------------------- + User Stack & Heap boundary definition + *----------------------------------------------------------------------------*/ +#define __STACK_TOP (__RAM_BASE + __RAM_SIZE) /* starts at end of RAM */ +#define __HEAP_BASE (AlignExpr(+0, 8)) /* starts after RW_RAM section, 8 byte aligned */ + + +/*---------------------------------------------------------------------------- + Scatter File Definitions definition + *----------------------------------------------------------------------------*/ +#define __RO_BASE __ROM_BASE +#define __RO_SIZE __ROM_SIZE + +#define __RW_BASE __RAM_BASE +#define __RW_SIZE (__RAM_SIZE - __STACK_SIZE - __HEAP_SIZE) + + +LR_ROM __RO_BASE __RO_SIZE { ; load region size_region + ER_ROM __RO_BASE __RO_SIZE { ; load address = execution address + *.o (RESET, +First) + *(InRoot$$Sections) + .ANY (+RO) + .ANY (+XO) + } + + RW_NOINIT __RW_BASE UNINIT __RW_SIZE { + *(.bss.noinit) + } + + RW_RAM AlignExpr(+0, 8) (__RW_SIZE - AlignExpr(ImageLength(RW_NOINIT), 8)) { + *(+RW +ZI) + } + +#if __HEAP_SIZE > 0 + ARM_LIB_HEAP __HEAP_BASE EMPTY __HEAP_SIZE { ; Reserve empty region for heap + } +#endif + + ARM_LIB_STACK __STACK_TOP EMPTY -__STACK_SIZE { ; Reserve empty region for stack + } +} diff --git a/example/project/mdk/RTE/Device/ARMCM3/startup_ARMCM3.c b/example/project/mdk/RTE/Device/ARMCM3/startup_ARMCM3.c new file mode 100644 index 0000000..b541573 --- /dev/null +++ b/example/project/mdk/RTE/Device/ARMCM3/startup_ARMCM3.c @@ -0,0 +1,150 @@ +/****************************************************************************** + * @file startup_ARMCM3.c + * @brief CMSIS-Core(M) Device Startup File for a Cortex-M3 Device + * @version V2.0.3 + * @date 31. March 2020 + ******************************************************************************/ +/* + * Copyright (c) 2009-2020 Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#if defined (ARMCM3) + #include "ARMCM3.h" +#else + #error device not specified! +#endif + +/*---------------------------------------------------------------------------- + External References + *----------------------------------------------------------------------------*/ +extern uint32_t __INITIAL_SP; + +extern __NO_RETURN void __PROGRAM_START(void); + +/*---------------------------------------------------------------------------- + Internal References + *----------------------------------------------------------------------------*/ +__NO_RETURN void Reset_Handler (void); + void Default_Handler(void); + +/*---------------------------------------------------------------------------- + Exception / Interrupt Handler + *----------------------------------------------------------------------------*/ +/* Exceptions */ +void NMI_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); +void HardFault_Handler (void) __attribute__ ((weak)); +void MemManage_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); +void BusFault_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); +void UsageFault_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); +void SVC_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); +void DebugMon_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); +void PendSV_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); +void SysTick_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); + +void Interrupt0_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); +void Interrupt1_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); +void Interrupt2_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); +void Interrupt3_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); +void Interrupt4_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); +void Interrupt5_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); +void Interrupt6_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); +void Interrupt7_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); +void Interrupt8_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); +void Interrupt9_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); + + +/*---------------------------------------------------------------------------- + Exception / Interrupt Vector table + *----------------------------------------------------------------------------*/ + +#if defined ( __GNUC__ ) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpedantic" +#endif + +extern const VECTOR_TABLE_Type __VECTOR_TABLE[240]; + const VECTOR_TABLE_Type __VECTOR_TABLE[240] __VECTOR_TABLE_ATTRIBUTE = { + (VECTOR_TABLE_Type)(&__INITIAL_SP), /* Initial Stack Pointer */ + Reset_Handler, /* Reset Handler */ + NMI_Handler, /* -14 NMI Handler */ + HardFault_Handler, /* -13 Hard Fault Handler */ + MemManage_Handler, /* -12 MPU Fault Handler */ + BusFault_Handler, /* -11 Bus Fault Handler */ + UsageFault_Handler, /* -10 Usage Fault Handler */ + 0, /* Reserved */ + 0, /* Reserved */ + 0, /* Reserved */ + 0, /* Reserved */ + SVC_Handler, /* -5 SVC Handler */ + DebugMon_Handler, /* -4 Debug Monitor Handler */ + 0, /* Reserved */ + PendSV_Handler, /* -2 PendSV Handler */ + SysTick_Handler, /* -1 SysTick Handler */ + + /* Interrupts */ + Interrupt0_Handler, /* 0 Interrupt 0 */ + Interrupt1_Handler, /* 1 Interrupt 1 */ + Interrupt2_Handler, /* 2 Interrupt 2 */ + Interrupt3_Handler, /* 3 Interrupt 3 */ + Interrupt4_Handler, /* 4 Interrupt 4 */ + Interrupt5_Handler, /* 5 Interrupt 5 */ + Interrupt6_Handler, /* 6 Interrupt 6 */ + Interrupt7_Handler, /* 7 Interrupt 7 */ + Interrupt8_Handler, /* 8 Interrupt 8 */ + Interrupt9_Handler /* 9 Interrupt 9 */ + /* Interrupts 10 .. 223 are left out */ +}; + +#if defined ( __GNUC__ ) +#pragma GCC diagnostic pop +#endif + +/*---------------------------------------------------------------------------- + Reset Handler called on controller reset + *----------------------------------------------------------------------------*/ +__NO_RETURN void Reset_Handler(void) +{ + SystemInit(); /* CMSIS System Initialization */ + __PROGRAM_START(); /* Enter PreMain (C library entry point) */ +} + + +#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wmissing-noreturn" +#endif + +/*---------------------------------------------------------------------------- + Hard Fault Handler + *----------------------------------------------------------------------------*/ +void HardFault_Handler(void) +{ + while(1); +} + +/*---------------------------------------------------------------------------- + Default Handler for Exceptions / Interrupts + *----------------------------------------------------------------------------*/ +void Default_Handler(void) +{ + while(1); +} + +#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) + #pragma clang diagnostic pop +#endif + diff --git a/example/project/mdk/plooc_example.uvoptx b/example/project/mdk/plooc_example.uvoptx index 7843a8e..da3c158 100644 --- a/example/project/mdk/plooc_example.uvoptx +++ b/example/project/mdk/plooc_example.uvoptx @@ -153,10 +153,27 @@ (105=-1,-1,-1,-1,0)(106=-1,-1,-1,-1,0)(107=-1,-1,-1,-1,0) - + + + 0 + 0 + 84 + 1 +
13596
+ 0 + 0 + 0 + 0 + 0 + 1 + ..\..\enhanced_byte_queue\enhanced_byte_queue.c + + \\plooc_example\../../enhanced_byte_queue/enhanced_byte_queue.c\84 +
+
C:\Users\gabriel\AppData\Local\Arm\Packs\Keil\ARM_Compiler\1.7.2\EventRecorder.scvd - Keil.ARM_Compiler.1.7.2 + Keil::ARM_Compiler@1.7.2 1 @@ -165,7 +182,7 @@ 0 1 - 1 + 0 0 0 0 @@ -182,7 +199,7 @@ 0 0 0 - 1 + 0 0 0 0 diff --git a/example/project/mdk/plooc_example.uvprojx b/example/project/mdk/plooc_example.uvprojx index b3b6d36..881675b 100644 --- a/example/project/mdk/plooc_example.uvprojx +++ b/example/project/mdk/plooc_example.uvprojx @@ -10,14 +10,14 @@ arm_compiler_6_example 0x4 ARM-ADS - 6180000::V6.18::ARMCLANG + 6220000::V6.22::ARMCLANG 1 ARMCM3 ARM - ARM.CMSIS.5.9.0 - http://www.keil.com/pack/ + ARM.Cortex_DFP.1.1.0 + https://www.keil.com/pack/ IRAM(0x20000000,0x00020000) IROM(0x00000000,0x00040000) CPUTYPE("Cortex-M3") CLOCK(12000000) ESEL ELITTLE @@ -190,7 +190,7 @@ 0 0 8 - 1 + 0 1 0 0 @@ -362,7 +362,7 @@ - 1 + 0 0 0 0 @@ -371,7 +371,7 @@ 0x00000000 0x20000000 - + .\RTE\Device\ARMCM3\ARMCM3_ac6.sct @@ -505,18 +505,32 @@ - - RTE\Device\ARMCM3\startup_ARMCM3.s - - + + RTE\Device\ARMCM3\ARMCM3_ac6.sct + + - - RTE\Device\ARMCM3\system_ARMCM3.c + + RTE\Device\ARMCM3\startup_ARMCM3.c + + + + + + + + RTE\Device\ARMCM3\startup_ARMCM3.s + + + + RTE\Device\ARMCM3\system_ARMCM3.c + + diff --git a/gen_pack.sh b/gen_pack.sh index 1254da0..7825d0a 100644 --- a/gen_pack.sh +++ b/gen_pack.sh @@ -135,6 +135,8 @@ if [ ! -d $PACK_BUILD ]; then mkdir -p $PACK_BUILD fi + + # Copy files into build base directory: $PACK_BUILD # pdsc file is mandatory in base directory: cp -f ./$PACK_VENDOR.$PACK_NAME.pdsc ${PACK_BUILD} @@ -158,6 +160,10 @@ do cp -f "$f" $PACK_BUILD/ done +echo clean project... +rm -rf $PACK_BUILD/example/project/mdk/Objects +rm -rf $PACK_BUILD/example/project/mdk/Listings +rm -rf $PACK_BUILD/example/project/mdk/*.uvguix.* # Run Schema Check (for Linux only): diff --git a/plooc.h b/plooc.h index 8371ddd..23902a3 100644 --- a/plooc.h +++ b/plooc.h @@ -75,6 +75,15 @@ extern "C" { # endif #endif +#ifndef plooc_malloc_align +# define plooc_malloc_align(__size, __align) malloc(__size) +#endif + +#ifndef plooc_free +# define plooc_free free +#endif + + /*============================ MACROFIED FUNCTIONS ===========================*/ diff --git a/plooc_class.h b/plooc_class.h index c60fd3b..1a556c5 100644 --- a/plooc_class.h +++ b/plooc_class.h @@ -267,7 +267,6 @@ extern "C" { # define __PLOOC_PRO__which(...) PLOOC_VISIBLE(__VA_ARGS__) # endif - #endif #if defined(__cplusplus) @@ -276,7 +275,8 @@ extern "C" { #endif -# if (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L) && !defined(__cplusplus) +#if (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L) + && !defined(__cplusplus) # undef which # define which(__declare) ,_which(__declare) #else @@ -294,7 +294,8 @@ extern "C" { #define public_member ,_public_member - +#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) \ + || defined(__cplusplus) /*! \brief helper macros for heap managed objects. They use malloc() and free() *! internally. @@ -304,20 +305,48 @@ extern "C" { *! *! \note Make sure your destructor is named as _depose. */ -#define __new_class(__name, ...) \ - ({__name##_cfg_t tCFG = { \ - __VA_ARGS__ \ - }; \ +# undef __new_class +# define __new_class(__name, ...) \ __name##_init( \ - (__name##_t *)malloc(sizeof(__name##_t)), \ - &tCFG);}) + (__name##_t *)plooc_malloc_align( sizeof(__name##_t), \ + PLOOC_ALIGNOF(__name##_t)), \ + (__name##_cfg_t []) {{__VA_ARGS__}} \ + ) -#define __free_class(__name, __obj) \ +# undef __free_class +# define __free_class(__name, __obj) \ do { \ __name##_depose((__name##_t *)(__obj)); \ - free(__obj); \ + plooc_free(__obj); \ } while(0) + +# undef private_method +# undef protected_method +# undef public_method + +# if defined(__PLOOC_CLASS_IMPLEMENT) || defined(__PLOOC_CLASS_IMPLEMENT__) + +# define private_method(...) __VA_ARGS__ +# define protected_method(...) __VA_ARGS__ +# define public_method(...) __VA_ARGS__ + +# elif defined(__PLOOC_CLASS_INHERIT) || defined(__PLOOC_CLASS_INHERIT__) + +# define private_method(...) +# define protected_method(...) __VA_ARGS__ +# define public_method(...) __VA_ARGS__ + +# else + +# define private_method(...) +# define protected_method(...) +# define public_method(...) __VA_ARGS__ + +# endif + +#endif + /*============================ TYPES =========================================*/ /*============================ GLOBAL VARIABLES ==============================*/ /*============================ PROTOTYPES ====================================*/ diff --git a/template/class/class_name.c b/template/class/class_name.c index 336913f..3104d86 100644 --- a/template/class/class_name.c +++ b/template/class/class_name.c @@ -71,7 +71,16 @@ void _depose(_t *ptObj) /*! \brief a method only visible for current class and derived class */ -void _protected_method_example(_t *ptObj) +void _protected_method_example1(_t *ptObj) +{ + /* initialise "this" (i.e. ptThis) to access class members */ + class_internal(ptObj, ptThis, _t); + + +} + +/*! \brief a method only visible for current class and derived class */ +void _protected_method_example2(_t *ptObj) { /* initialise "this" (i.e. ptThis) to access class members */ class_internal(ptObj, ptThis, _t); diff --git a/template/class/class_name.h b/template/class/class_name.h index 85a066d..788ec7a 100644 --- a/template/class/class_name.h +++ b/template/class/class_name.h @@ -93,10 +93,13 @@ extern extern void _depose(_t *ptObj); -#if defined(___CLASS_IMPLEMENT__) || defined(___CLASS_INHERIT__) -/*! \brief a method only visible for current class and derived class */ -extern void _protected_method_example(_t *ptObj); -#endif +protected_method( + /*! \brief a method only visible for current class and derived class */ + extern void _protected_method_example1(_t *ptObj); + + /*! \brief a method only visible for current class and derived class */ + extern void _protected_method_example2(_t *ptObj); +) /*! \note it is very important to undef those macros */ #undef ___CLASS_INHERIT__ diff --git a/template/derived_class/class_name.c b/template/derived_class/class_name.c index e05a812..997753b 100644 --- a/template/derived_class/class_name.c +++ b/template/derived_class/class_name.c @@ -82,7 +82,20 @@ void _depose(_t *ptObj) /*! \brief a method only visible for current class and derived class */ -void _protected_method_example(_t *ptObj) +void _protected_method_example1(_t *ptObj) +{ + /* initialise "this" (i.e. ptThis) to access class members */ + class_internal(ptObj, ptThis, _t); + + /* initialise "base" (i.e. ptBase) to access protected members */ + protected_internal(&this.use_as___t, ptBase, _t); + + + +} + +/*! \brief a method only visible for current class and derived class */ +void _protected_method_example2(_t *ptObj) { /* initialise "this" (i.e. ptThis) to access class members */ class_internal(ptObj, ptThis, _t); diff --git a/template/derived_class/class_name.h b/template/derived_class/class_name.h index d9df4b7..1cbaf4c 100644 --- a/template/derived_class/class_name.h +++ b/template/derived_class/class_name.h @@ -94,10 +94,13 @@ extern extern void _depose(_t *ptObj); -#if defined(___CLASS_IMPLEMENT__) || defined(___CLASS_INHERIT__) -/*! \brief a method only visible for current class and derived class */ -extern void _protected_method_example(_t *ptObj); -#endif +protected_method( + /*! \brief a method only visible for current class and derived class */ + extern void _protected_method_example1(_t *ptObj); + + /*! \brief a method only visible for current class and derived class */ + extern void _protected_method_example2(_t *ptObj); +) /*! \note it is very important to undef those macros */ #undef ___CLASS_INHERIT__