60 lines
1.4 KiB
C
60 lines
1.4 KiB
C
|
|
||
|
#define __TEST_CLASS_CLASS_IMPLEMENT__
|
||
|
|
||
|
#include "test_class.h"
|
||
|
|
||
|
#include <stddef.h>
|
||
|
#include <stdint.h>
|
||
|
#include <stdbool.h>
|
||
|
#include <assert.h>
|
||
|
|
||
|
#ifndef ASSERT
|
||
|
#define ASSERT(...) assert(__VA_ARGS__)
|
||
|
#endif
|
||
|
|
||
|
#undef this
|
||
|
#define this (*ptThis)
|
||
|
|
||
|
const i_test_class_t TEST_CLASS = {
|
||
|
.Init = &test_class_init,
|
||
|
.Depose = &test_class_depose,
|
||
|
|
||
|
/* other methods */
|
||
|
};
|
||
|
|
||
|
|
||
|
/*! \brief the constructor of the class: test_class */
|
||
|
test_class_t *test_class_init(test_class_t *ptObj, test_class_cfg_t *ptCFG) {
|
||
|
/* initialise "this" (i.e. ptThis) to access class members */
|
||
|
class_internal(ptObj, ptThis, test_class_t);
|
||
|
|
||
|
ASSERT(NULL != ptObj && NULL != ptCFG);
|
||
|
|
||
|
return ptObj;
|
||
|
}
|
||
|
|
||
|
/*! \brief the destructor of the class: test_class */
|
||
|
void test_class_depose(test_class_t *ptObj) {
|
||
|
/* initialise "this" (i.e. ptThis) to access class members */
|
||
|
class_internal(ptObj, ptThis, test_class_t);
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
/*! \brief a method only visible for current class and derived class */
|
||
|
void test_class_protected_method_example1(test_class_t *ptObj) {
|
||
|
/* initialise "this" (i.e. ptThis) to access class members */
|
||
|
class_internal(ptObj, ptThis, test_class_t);
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
/*! \brief a method only visible for current class and derived class */
|
||
|
void test_class_protected_method_example2(test_class_t *ptObj) {
|
||
|
/* initialise "this" (i.e. ptThis) to access class members */
|
||
|
class_internal(ptObj, ptThis, test_class_t);
|
||
|
|
||
|
|
||
|
}
|