UP font generate
This commit is contained in:
59
demo/plooc/test_class.c
Normal file
59
demo/plooc/test_class.c
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
|
||||||
|
#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);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
71
demo/plooc/test_class.h
Normal file
71
demo/plooc/test_class.h
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
#ifndef __TEST_CLASS_H__
|
||||||
|
#define __TEST_CLASS_H__
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
/*! \NOTE: Make sure #include "plooc_class.h" is close to the class definition
|
||||||
|
*/
|
||||||
|
#if defined(__TEST_CLASS_CLASS_IMPLEMENT__)
|
||||||
|
#define __PLOOC_CLASS_IMPLEMENT__
|
||||||
|
#elif defined(__TEST_CLASS_CLASS_INHERIT__)
|
||||||
|
#define __PLOOC_CLASS_INHERIT__
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "plooc_class.h"
|
||||||
|
|
||||||
|
|
||||||
|
//! \name class test_class_t
|
||||||
|
//! @{
|
||||||
|
declare_class(test_class_t)
|
||||||
|
def_class(test_class_t,
|
||||||
|
public_member(
|
||||||
|
//!< place your public members here
|
||||||
|
)
|
||||||
|
private_member(
|
||||||
|
//!< place your private members here
|
||||||
|
)
|
||||||
|
protected_member(
|
||||||
|
//!< place your protected members here
|
||||||
|
)
|
||||||
|
)
|
||||||
|
end_def_class(test_class_t) /* do not remove this for forward compatibility */
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
typedef struct test_class_cfg_t {
|
||||||
|
|
||||||
|
//! put your configuration members here
|
||||||
|
|
||||||
|
} test_class_cfg_t;
|
||||||
|
|
||||||
|
//! \name interface i_test_class_t
|
||||||
|
//! @{
|
||||||
|
def_interface(i_test_class_t)
|
||||||
|
test_class_t *(*Init)(test_class_t *ptObj, test_class_cfg_t *ptCFG);
|
||||||
|
|
||||||
|
void (*Depose)(test_class_t *ptObj);
|
||||||
|
/* other methods */
|
||||||
|
|
||||||
|
end_def_interface(i_test_class_t) /*do not remove this for forward compatibility */
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
extern const i_test_class_t TEST_CLASS;
|
||||||
|
|
||||||
|
/*! \brief the constructor of the class: test_class */
|
||||||
|
extern test_class_t *test_class_init(test_class_t *ptObj, test_class_cfg_t *ptCFG);
|
||||||
|
|
||||||
|
/*! \brief the destructor of the class: test_class */
|
||||||
|
extern void test_class_depose(test_class_t *ptObj);
|
||||||
|
|
||||||
|
protected_method(
|
||||||
|
/*! \brief a method only visible for current class and derived class */
|
||||||
|
extern void test_class_protected_method_example1(test_class_t *ptObj);
|
||||||
|
/*! \brief a method only visible for current class and derived class */
|
||||||
|
extern void test_class_protected_method_example2(test_class_t *ptObj);
|
||||||
|
)
|
||||||
|
|
||||||
|
/*! \note it is very important to undef those macros */
|
||||||
|
#undef __TEST_CLASS_CLASS_INHERIT__
|
||||||
|
#undef __TEST_CLASS_CLASS_IMPLEMENT__
|
||||||
|
|
||||||
|
#endif
|
370
lib/utils/inc/plooc.h
Normal file
370
lib/utils/inc/plooc.h
Normal file
@@ -0,0 +1,370 @@
|
|||||||
|
#ifndef HW_LIB_PLOOC_H
|
||||||
|
#define HW_LIB_PLOOC_H
|
||||||
|
|
||||||
|
/*============================ INCLUDES ======================================*/
|
||||||
|
#if (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L) && !defined(__cplusplus)
|
||||||
|
//! you have to define this by yourselves
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*! \NOTE the uint_fast8_t used in this header file is defined in stdint.h
|
||||||
|
if you don't have stdint.h supported in your toolchain, you should
|
||||||
|
define uint_fast8_t all by yourself with following rule:
|
||||||
|
a. if the target processor is 8 bits, define it as uint8_t
|
||||||
|
b. if the target processor is 16 bits, define it as uint16_t
|
||||||
|
c. if the target processor is 32 bits, define it as uint32_t
|
||||||
|
d. if the target processor is 64 bits, define it as either uint32_t or
|
||||||
|
uint64_t
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(__clang__)
|
||||||
|
# pragma clang diagnostic push
|
||||||
|
# pragma clang diagnostic ignored "-Wunknown-warning-option"
|
||||||
|
# pragma clang diagnostic ignored "-Wreserved-identifier"
|
||||||
|
# pragma clang diagnostic ignored "-Wtypedef-redefinition"
|
||||||
|
# pragma clang diagnostic ignored "-Wmissing-declarations"
|
||||||
|
# pragma clang diagnostic ignored "-Wempty-body"
|
||||||
|
# pragma clang diagnostic ignored "-Wmicrosoft-anon-tag"
|
||||||
|
#elif ((__ARMCC_VERSION >= 5000000) && (__ARMCC_VERSION < 6000000))
|
||||||
|
/*! arm compiler 5 */
|
||||||
|
# pragma push
|
||||||
|
# pragma diag_suppress 1,64,174,177,188,68,513,144,2525
|
||||||
|
#elif defined(__IAR_SYSTEMS_ICC__)
|
||||||
|
/*! IAR */
|
||||||
|
#elif defined(__GNUC__)
|
||||||
|
# pragma GCC diagnostic push
|
||||||
|
# pragma GCC diagnostic ignored "-Wmissing-declarations"
|
||||||
|
# pragma GCC diagnostic ignored "-Wempty-body"
|
||||||
|
# pragma GCC diagnostic ignored "-Wpragmas"
|
||||||
|
# pragma GCC diagnostic ignored "-Wformat="
|
||||||
|
# pragma GCC diagnostic ignored "-Wmissing-braces"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*============================ MACROS ========================================*/
|
||||||
|
#ifndef __cplusplus
|
||||||
|
# ifndef plooc_private
|
||||||
|
# define plooc_private static
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# ifndef plooc_public
|
||||||
|
# define plooc_public
|
||||||
|
# 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 ===========================*/
|
||||||
|
|
||||||
|
|
||||||
|
/*! \note add which macro to support multiple inheriting and implementations
|
||||||
|
*!
|
||||||
|
*! declare_interface( i_lv0_abc_t )
|
||||||
|
*! declare_interface( i_lv0_efg_t )
|
||||||
|
*! def_interface( i_lv0_abc_t )
|
||||||
|
*! ...
|
||||||
|
*! end_def_interface( i_lv0_abc_t )
|
||||||
|
*!
|
||||||
|
*! def_interface( i_lv0_efg_t )
|
||||||
|
*! ...
|
||||||
|
*! end_def_interface( i_lv0_efg_t )
|
||||||
|
*!
|
||||||
|
*! declare_interface( i_lv1_t )
|
||||||
|
*! def_interface( i_lv1_t, which( inherit( i_lv0_abc_t )
|
||||||
|
*! inherit( i_lv0_efg_t ) ) )
|
||||||
|
*! ...
|
||||||
|
*! end_def_interface( i_lv1_t )
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define __declare_interface(__name) typedef struct __name __name;
|
||||||
|
#define __declare_structure(__name) typedef struct __name __name;
|
||||||
|
|
||||||
|
#if (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L) && !defined(__cplusplus)
|
||||||
|
|
||||||
|
//! \name interface definition
|
||||||
|
//! @{
|
||||||
|
#define __def_interface(__name) \
|
||||||
|
/*typedef struct __name __name;*/ \
|
||||||
|
struct __name {
|
||||||
|
|
||||||
|
#define __end_def_interface(__name) \
|
||||||
|
};
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
//! \name structure definition
|
||||||
|
//! @{
|
||||||
|
#define __def_structure(__name) \
|
||||||
|
/*typedef struct __name __name; */ \
|
||||||
|
struct __name {
|
||||||
|
|
||||||
|
#define __end_def_structure(__name) \
|
||||||
|
};
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
#else
|
||||||
|
//! \name interface definition
|
||||||
|
//! @{
|
||||||
|
#define __def_interface(__name, ...) \
|
||||||
|
typedef struct __name __name; \
|
||||||
|
__VA_ARGS__ \
|
||||||
|
struct __name {
|
||||||
|
|
||||||
|
#define __end_def_interface(__name) \
|
||||||
|
};
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
//! \name structure definition
|
||||||
|
//! @{
|
||||||
|
#define __def_structure(__name, ...) \
|
||||||
|
typedef struct __name __name; \
|
||||||
|
__VA_ARGS__ \
|
||||||
|
struct __name {
|
||||||
|
|
||||||
|
#define __end_def_structure(__name) \
|
||||||
|
};
|
||||||
|
//! @}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//! \brief macro for inheritance
|
||||||
|
|
||||||
|
#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
|
||||||
|
#define __IMPLEMENT_EX(__TYPE, __NAME) \
|
||||||
|
__TYPE __NAME;
|
||||||
|
#else
|
||||||
|
#define __IMPLEMENT_EX(__TYPE, __NAME) \
|
||||||
|
union { \
|
||||||
|
__TYPE __NAME; \
|
||||||
|
__TYPE; \
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define __INHERIT_EX(__TYPE, __NAME) __TYPE __NAME;
|
||||||
|
#define INHERIT_EX(__TYPE, __NAME) __INHERIT_EX(__TYPE, __NAME)
|
||||||
|
|
||||||
|
#define __INHERIT(__TYPE) INHERIT_EX(__TYPE, use_as__##__TYPE)
|
||||||
|
#define INHERIT(__TYPE) __INHERIT(__TYPE)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*! \note You can only use IMPLEMENT when defining INTERFACE. For Implement
|
||||||
|
* interface when defining class, you should use DEF_CLASS_IMPLEMENT
|
||||||
|
* instead.
|
||||||
|
*/
|
||||||
|
#define __IMPLEMENT(__INTERFACE) __IMPLEMENT_EX( __INTERFACE, \
|
||||||
|
use_as__##__INTERFACE)
|
||||||
|
#define IMPLEMENT(__INTERFACE) __IMPLEMENT(__INTERFACE)
|
||||||
|
|
||||||
|
/*! \note if you have used INHERIT or IMPLEMENT to define a class / INTERFACE,
|
||||||
|
you can use OBJ_CONVERT_AS to extract the reference to the inherited
|
||||||
|
object.
|
||||||
|
\*/
|
||||||
|
#define __OBJ_CONVERT_AS(__OBJ, __INTERFACE) (__OBJ.use_as__##__INTERFACE)
|
||||||
|
#define OBJ_CONVERT_AS(__OBJ, __INTERFACE) __OBJ_CONVERT_AS( (__OBJ), \
|
||||||
|
__INTERFACE)
|
||||||
|
|
||||||
|
#define __REF_OBJ_AS(__OBJ, __TYPE) (&(__OBJ.use_as__##__TYPE))
|
||||||
|
#define REF_OBJ_AS(__OBJ, __TYPE) __REF_OBJ_AS((__OBJ), __TYPE)
|
||||||
|
|
||||||
|
|
||||||
|
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__cplusplus)
|
||||||
|
/*! \brief You can use __PLOOC_EVAL() to dynamically select the right API which
|
||||||
|
*! has the right number of parameters (no more than 8).
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define __PLOOC_VA_NUM_ARGS_IMPL(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, \
|
||||||
|
_13, _14, _15, _16, __N, ...) __N
|
||||||
|
#define __PLOOC_VA_NUM_ARGS(...) \
|
||||||
|
__PLOOC_VA_NUM_ARGS_IMPL( 0,##__VA_ARGS__,16,15,14,13,12,11,10,9, \
|
||||||
|
8,7,6,5,4,3,2,1,0)
|
||||||
|
|
||||||
|
#define __16_PLOOC_EVAL(__FUNC, __NO_ARGS) __FUNC##__NO_ARGS
|
||||||
|
#define __15_PLOOC_EVAL(__FUNC, __NO_ARGS) __16_PLOOC_EVAL(__FUNC, __NO_ARGS)
|
||||||
|
#define __14_PLOOC_EVAL(__FUNC, __NO_ARGS) __15_PLOOC_EVAL(__FUNC, __NO_ARGS)
|
||||||
|
#define __13_PLOOC_EVAL(__FUNC, __NO_ARGS) __14_PLOOC_EVAL(__FUNC, __NO_ARGS)
|
||||||
|
|
||||||
|
#define __12_PLOOC_EVAL(__FUNC, __NO_ARGS) __13_PLOOC_EVAL(__FUNC, __NO_ARGS)
|
||||||
|
#define __11_PLOOC_EVAL(__FUNC, __NO_ARGS) __12_PLOOC_EVAL(__FUNC, __NO_ARGS)
|
||||||
|
#define __10_PLOOC_EVAL(__FUNC, __NO_ARGS) __11_PLOOC_EVAL(__FUNC, __NO_ARGS)
|
||||||
|
#define __9_PLOOC_EVAL(__FUNC, __NO_ARGS) __10_PLOOC_EVAL(__FUNC, __NO_ARGS)
|
||||||
|
#define __8_PLOOC_EVAL(__FUNC, __NO_ARGS) __9_PLOOC_EVAL(__FUNC, __NO_ARGS)
|
||||||
|
|
||||||
|
#define __7_PLOOC_EVAL(__FUNC, __NO_ARGS) __8_PLOOC_EVAL(__FUNC, __NO_ARGS)
|
||||||
|
#define __6_PLOOC_EVAL(__FUNC, __NO_ARGS) __7_PLOOC_EVAL(__FUNC, __NO_ARGS)
|
||||||
|
#define __5_PLOOC_EVAL(__FUNC, __NO_ARGS) __6_PLOOC_EVAL(__FUNC, __NO_ARGS)
|
||||||
|
#define __4_PLOOC_EVAL(__FUNC, __NO_ARGS) __5_PLOOC_EVAL(__FUNC, __NO_ARGS)
|
||||||
|
#define __3_PLOOC_EVAL(__FUNC, __NO_ARGS) __4_PLOOC_EVAL(__FUNC, __NO_ARGS)
|
||||||
|
#define __2_PLOOC_EVAL(__FUNC, __NO_ARGS) __3_PLOOC_EVAL(__FUNC, __NO_ARGS)
|
||||||
|
#define __1_PLOOC_EVAL(__FUNC, __NO_ARGS) __2_PLOOC_EVAL(__FUNC, __NO_ARGS)
|
||||||
|
#define __0_PLOOC_EVAL(__FUNC, __NO_ARGS) __1_PLOOC_EVAL(__FUNC, __NO_ARGS)
|
||||||
|
|
||||||
|
#define __PLOOC_EVAL(__FUNC, ...) __0_PLOOC_EVAL( \
|
||||||
|
__FUNC, \
|
||||||
|
__PLOOC_VA_NUM_ARGS(__VA_ARGS__))
|
||||||
|
//! @}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------*
|
||||||
|
* new standard (lower case) *
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
|
||||||
|
# define def_interface(__name) __def_interface(__name)
|
||||||
|
# define define_interface(__name) __def_interface(__name)
|
||||||
|
# define def_structure(__name) __def_structure(__name)
|
||||||
|
# define define_structure(__name) __def_structure(__name)
|
||||||
|
# define def_params(__code) __code
|
||||||
|
# define define_params(__code) __code
|
||||||
|
# define end_def_params()
|
||||||
|
# define end_define_params()
|
||||||
|
# define def_members(__code) __code
|
||||||
|
# define define_members(__code) __code
|
||||||
|
# define end_def_members()
|
||||||
|
# define end_define_members()
|
||||||
|
#else
|
||||||
|
# define def_interface(__name, ...) __def_interface(__name, __VA_ARGS__)
|
||||||
|
# define define_interface(__name, ...) __def_interface(__name, __VA_ARGS__)
|
||||||
|
# define def_structure(__name, ...) __def_structure(__name, __VA_ARGS__)
|
||||||
|
# define define_structure(__name, ...) __def_structure(__name, __VA_ARGS__)
|
||||||
|
# define def_params(...) __VA_ARGS__
|
||||||
|
# define define_params(...) __VA_ARGS__
|
||||||
|
# define end_def_params(...)
|
||||||
|
# define end_define_params(...)
|
||||||
|
# define def_members(...) __VA_ARGS__
|
||||||
|
# define define_members(...) __VA_ARGS__
|
||||||
|
# define end_def_members(...)
|
||||||
|
# define end_define_members(...)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define implement(__type) IMPLEMENT(__type)
|
||||||
|
#define implement_ex(__type, __name) __IMPLEMENT_EX(__type, __name)
|
||||||
|
#define inherit_ex(__type, __name) INHERIT_EX(__type, __name)
|
||||||
|
#define inherit(__type) INHERIT(__type)
|
||||||
|
#define ref_interface(__INTERFACE) const __INTERFACE *ptMethod;
|
||||||
|
#define convert_obj_as(__obj, __type) OBJ_CONVERT_AS(__obj, __type)
|
||||||
|
#define obj_convert_as(__obj, __type) OBJ_CONVERT_AS(__obj, __type) /* obsolete */
|
||||||
|
#define ref_obj_as(__obj, __type) REF_OBJ_AS(__obj, __type)
|
||||||
|
|
||||||
|
#define end_def_interface(__name) __end_def_interface(__name)
|
||||||
|
#define end_define_interface(__name) __end_def_interface(__name)
|
||||||
|
#define dcl_interface(__name) __declare_interface(__name)
|
||||||
|
#define declare_interface(__name) __declare_interface(__name)
|
||||||
|
#define end_def_structure(__name) __end_def_structure(__name)
|
||||||
|
#define end_define_structure(__name) __end_def_structure(__name)
|
||||||
|
#define dcl_structure(__name) __declare_structure(__name)
|
||||||
|
#define declare_structure(__name) __declare_structure(__name)
|
||||||
|
|
||||||
|
#define this_interface(__INTERFACE) convert_obj_as(this, __INTERFACE)
|
||||||
|
#define base_obj(__type) convert_obj_as(this, __type)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*============================ TYPES =========================================*/
|
||||||
|
|
||||||
|
//! \name interface: u32_property_t
|
||||||
|
//! @{
|
||||||
|
dcl_interface(u32_property_t)
|
||||||
|
def_interface(u32_property_t)
|
||||||
|
bool (*Set)(uint32_t wValue);
|
||||||
|
|
||||||
|
uint32_t (*Get)(void);
|
||||||
|
end_def_interface(u32_property_t)
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
//! \name interface: u16_property_t
|
||||||
|
//! @{
|
||||||
|
dcl_interface(u16_property_t)
|
||||||
|
def_interface(u16_property_t)
|
||||||
|
bool (*Set)(uint_fast16_t wValue);
|
||||||
|
|
||||||
|
uint_fast16_t (*Get)(void);
|
||||||
|
end_def_interface(u16_property_t)
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
//! \name interface: u8_property_t
|
||||||
|
//! @{
|
||||||
|
dcl_interface(u8_property_t)
|
||||||
|
def_interface(u8_property_t)
|
||||||
|
bool (*Set)(uint_fast8_t wValue);
|
||||||
|
|
||||||
|
uint_fast8_t (*Get)(void);
|
||||||
|
end_def_interface(u8_property_t)
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
|
||||||
|
//! \name interface: i32_property_t
|
||||||
|
//! @{
|
||||||
|
dcl_interface(i32_property_t)
|
||||||
|
def_interface(i32_property_t)
|
||||||
|
bool (*Set)(int32_t wValue);
|
||||||
|
|
||||||
|
int32_t (*Get)(void);
|
||||||
|
end_def_interface(i32_property_t)
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
//! \name interface: i16_property_t
|
||||||
|
//! @{
|
||||||
|
dcl_interface(i16_property_t)
|
||||||
|
def_interface(i16_property_t)
|
||||||
|
bool (*Set)(int_fast16_t wValue);
|
||||||
|
|
||||||
|
int_fast16_t (*Get)(void);
|
||||||
|
end_def_interface(i16_property_t)
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
//! \name interface: u8_property_t
|
||||||
|
//! @{
|
||||||
|
dcl_interface(i8_property_t)
|
||||||
|
def_interface(i8_property_t)
|
||||||
|
bool (*Set)(int_fast8_t wValue);
|
||||||
|
|
||||||
|
int_fast8_t (*Get)(void);
|
||||||
|
end_def_interface(i8_property_t)
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
//! \name interface: bool_property_t
|
||||||
|
//! @{
|
||||||
|
dcl_interface(bool_property_t)
|
||||||
|
def_interface(bool_property_t)
|
||||||
|
bool (*Set)(bool bValue);
|
||||||
|
|
||||||
|
bool (*Get)(void);
|
||||||
|
end_def_interface(bool_property_t)
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
//! \name interface: bool_property_t
|
||||||
|
//! @{
|
||||||
|
dcl_interface(en_property_t)
|
||||||
|
def_interface(en_property_t)
|
||||||
|
bool (*Enable)(void);
|
||||||
|
|
||||||
|
bool (*Disable)(void);
|
||||||
|
end_def_interface(en_property_t)
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
/*============================ GLOBAL VARIABLES ==============================*/
|
||||||
|
/*============================ LOCAL VARIABLES ===============================*/
|
||||||
|
/*============================ PROTOTYPES ====================================*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//#if defined(__clang__)
|
||||||
|
//# pragma clang diagnostic pop
|
||||||
|
//#endif
|
||||||
|
|
||||||
|
#endif //HW_LIB_PLOOC_H
|
386
lib/utils/inc/plooc_class.h
Normal file
386
lib/utils/inc/plooc_class.h
Normal file
@@ -0,0 +1,386 @@
|
|||||||
|
#ifndef HW_LIB_PLOOC_CLASS_H
|
||||||
|
#define HW_LIB_PLOOC_CLASS_H
|
||||||
|
|
||||||
|
#if defined(__cplusplus) || defined(__OOC_CPP__)
|
||||||
|
# undef __PLOOC_CLASS_USE_STRICT_TEMPLATE__
|
||||||
|
# undef PLOOC_CFG_REMOVE_MEMORY_LAYOUT_BOUNDARY___USE_WITH_CAUTION___
|
||||||
|
# define PLOOC_CFG_REMOVE_MEMORY_LAYOUT_BOUNDARY___USE_WITH_CAUTION___
|
||||||
|
# ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__OOC_RELEASE__) || defined(__OOC_CPP__)
|
||||||
|
# undef __OOC_DEBUG__
|
||||||
|
# define __OOC_DEBUG__ 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(__PLOOC_CLASS_USE_STRICT_TEMPLATE__) \
|
||||||
|
&& !defined(__PLOOC_CLASS_USE_SIMPLE_TEMPLATE__) \
|
||||||
|
&& !defined(__PLOOC_CLASS_USE_BLACK_BOX_TEMPLATE__)
|
||||||
|
# define __PLOOC_CLASS_USE_SIMPLE_TEMPLATE__ 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L) && !defined(__cplusplus)
|
||||||
|
|
||||||
|
#ifndef __OOC_DEBUG__
|
||||||
|
# define __OOC_DEBUG__
|
||||||
|
# warning For C89/90, __OOC_DEBUG__ is enforced.
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__PLOOC_CLASS_USE_STRICT_TEMPLATE__)
|
||||||
|
# undef __PLOOC_CLASS_USE_STRICT_TEMPLATE__
|
||||||
|
# define __PLOOC_CLASS_USE_SIMPLE_TEMPLATE__
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__PLOOC_CLASS_USE_BLACK_BOX_TEMPLATE__)
|
||||||
|
# undef __PLOOC_CLASS_USE_BLACK_BOX_TEMPLATE__
|
||||||
|
# define __PLOOC_CLASS_USE_SIMPLE_TEMPLATE__
|
||||||
|
#endif
|
||||||
|
|
||||||
|
# if !defined(__OOC_DEBUG__) || !defined(__PLOOC_CLASS_USE_SIMPLE_TEMPLATE__)
|
||||||
|
# error \
|
||||||
|
You must use __OOC_DEBUG__ (or __OOC_RELEASE__) together with the\
|
||||||
|
__PLOOC_CLASS_USE_SIMPLE_TEMPLATE__ in ANSI-C89/90.
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __PLOOC_CLASS_H__
|
||||||
|
#define __PLOOC_CLASS_H__
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* HOW TO USE *
|
||||||
|
******************************************************************************/
|
||||||
|
//! TODO: Add How to use
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*============================ INCLUDES ======================================*/
|
||||||
|
//#include <stdint.h>
|
||||||
|
/*! \NOTE the uint_fast8_t used in this header file is defined in stdint.h
|
||||||
|
if you don't have stdint.h supported in your toolchain, you should
|
||||||
|
define uint_fast8_t all by yourself with following rule:
|
||||||
|
a. if the target processor is 8 bits, define it as uint8_t
|
||||||
|
b. if the target processor is 16 bits, define it as uint16_t
|
||||||
|
c. if the target processor is 32 bits, define it as uint32_t
|
||||||
|
d. if the target processor is 64 bits, define it as either uint32_t or
|
||||||
|
uint64_t
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "plooc.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
/*============================ MACROS ========================================*/
|
||||||
|
/*!\ node if you want your code more "elegent", say you want to use "this" with
|
||||||
|
* "." rather than a pointer with "->", you can add following macros to
|
||||||
|
* your code, assuming the variable name of the object pointer is "ptThis".
|
||||||
|
* If your object pointer has a different name, please feel free to change
|
||||||
|
* the macro by yourself
|
||||||
|
|
||||||
|
#undef this
|
||||||
|
#define this (*ptThis)
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*============================ MACROFIED FUNCTIONS ===========================*/
|
||||||
|
|
||||||
|
//! @{
|
||||||
|
#ifndef __PLOOC_CONNECT2
|
||||||
|
# define __PLOOC_CONNECT2( __A, __B) __A##__B
|
||||||
|
#endif
|
||||||
|
#ifndef __PLOOC_CONNECT3
|
||||||
|
# define __PLOOC_CONNECT3( __A, __B, __C) __A##__B##__C
|
||||||
|
#endif
|
||||||
|
#ifndef __PLOOC_CONNECT4
|
||||||
|
# define __PLOOC_CONNECT4( __A, __B, __C, __D) __A##__B##__C##__D
|
||||||
|
#endif
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
#ifndef __PLOOC_ALIGN
|
||||||
|
# define __PLOOC_ALIGN(__N) __attribute__((aligned(__N)))
|
||||||
|
#endif
|
||||||
|
#ifndef PLOOC_ALIGN
|
||||||
|
# define PLOOC_ALIGN(__N) __PLOOC_ALIGN(__N)
|
||||||
|
#endif
|
||||||
|
/*
|
||||||
|
#ifndef PLOOC_DEFAULT_OBJ_ALIGN
|
||||||
|
# define PLOOC_DEFAULT_OBJ_ALIGN sizeof(uint_fast8_t)
|
||||||
|
#endif
|
||||||
|
*/
|
||||||
|
#ifndef PLOOC_PACKED
|
||||||
|
# define PLOOC_PACKED __attribute__((packed))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//! @{
|
||||||
|
#ifndef PLOOC_CONNECT2
|
||||||
|
# define PLOOC_CONNECT2( __A, __B) __PLOOC_CONNECT2( __A, __B)
|
||||||
|
#endif
|
||||||
|
#ifndef PLOOC_CONNECT3
|
||||||
|
# define PLOOC_CONNECT3( __A, __B, __C) __PLOOC_CONNECT3( __A, __B, __C)
|
||||||
|
#endif
|
||||||
|
#ifndef PLOOC_CONNECT4
|
||||||
|
# define PLOOC_CONNECT4( __A, __B, __C, __D) __PLOOC_CONNECT4( __A, __B, __C, __D)
|
||||||
|
#endif
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
#ifndef PLOOC_UNUSED_PARAM
|
||||||
|
# define PLOOC_UNUSED_PARAM(__N) do {(__N) = (__N);}while(0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L) && !defined(__cplusplus)
|
||||||
|
|
||||||
|
# ifndef PLOOC_ALIGNOF
|
||||||
|
# define PLOOC_ALIGNOF(__TYPE) __alignof__(__TYPE)
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# define PLOOC_ALIGNOF_STRUCT(__TYPE) PLOOC_ALIGNOF(struct {__TYPE})
|
||||||
|
# define PLOOC_SIZEOF_STRUCT(__TYPE) sizeof(struct {__TYPE})
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
# ifndef PLOOC_ALIGNOF
|
||||||
|
# define PLOOC_ALIGNOF(...) __alignof__(__VA_ARGS__)
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# define PLOOC_ALIGNOF_STRUCT(...) PLOOC_ALIGNOF(struct {__VA_ARGS__})
|
||||||
|
# define PLOOC_SIZEOF_STRUCT(...) sizeof(struct {__VA_ARGS__})
|
||||||
|
|
||||||
|
/*! \note When both __OOC_DEBUG__ and
|
||||||
|
*! PLOOC_CFG_REMOVE_MEMORY_LAYOUT_BOUNDARY___USE_WITH_CAUTION___ are
|
||||||
|
*! defined, memory layout boundary, i.e. struct wrapper inside PLOOC
|
||||||
|
*! VISIBLE will be removed. This enables some platform to use the gaps
|
||||||
|
*! between members with different memory aligments to add members with
|
||||||
|
*! correct size and aligment for saving space.
|
||||||
|
*!
|
||||||
|
*! You can do this when you have all the source code and compile all
|
||||||
|
*! the source code with the same presence of "__OOC_DEBUG__".
|
||||||
|
*! If some of the code is compiled with different presence of
|
||||||
|
*! "__OOC_DEBUG__", i.e. using Lib + source, removing the memory
|
||||||
|
*! layout boundaries will cause different view of the structure and hence
|
||||||
|
*! cause undefined behaviours.
|
||||||
|
*/
|
||||||
|
# if defined(PLOOC_CFG_REMOVE_MEMORY_LAYOUT_BOUNDARY___USE_WITH_CAUTION___)
|
||||||
|
# define PLOOC_VISIBLE(...) __VA_ARGS__
|
||||||
|
# else
|
||||||
|
# define PLOOC_VISIBLE(...) \
|
||||||
|
struct { \
|
||||||
|
__VA_ARGS__ \
|
||||||
|
}PLOOC_ALIGN(PLOOC_ALIGNOF_STRUCT(__VA_ARGS__));
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# if !defined (__PLOOC_CLASS_USE_NO_STRUCT_MASK__)
|
||||||
|
|
||||||
|
# define PLOOC_INVISIBLE(...) \
|
||||||
|
uint8_t PLOOC_CONNECT3(chMask_,__LINE__,__COUNTER__) \
|
||||||
|
[PLOOC_SIZEOF_STRUCT(__VA_ARGS__)] \
|
||||||
|
PLOOC_ALIGN(PLOOC_ALIGNOF_STRUCT(__VA_ARGS__));
|
||||||
|
|
||||||
|
# else
|
||||||
|
# define PLOOC_INVISIBLE(...) \
|
||||||
|
struct { \
|
||||||
|
__VA_ARGS__ \
|
||||||
|
} PLOOC_CONNECT3(zzz_, __LINE__,__COUNTER__) \
|
||||||
|
PLOOC_ALIGN(PLOOC_ALIGNOF_STRUCT(__VA_ARGS__));
|
||||||
|
# endif /* __PLOOC_CLASS_USE_NO_STRUCT_MASK__ */
|
||||||
|
|
||||||
|
# define __PLOOC_PRO_struct struct
|
||||||
|
# define __PLOOC_PRI_struct struct
|
||||||
|
# define __PLOOC_EXT_struct struct
|
||||||
|
# define __PLOOC_PRO_union union
|
||||||
|
# define __PLOOC_PRI_union union
|
||||||
|
# define __PLOOC_EXT_union union
|
||||||
|
# define __PLOOC_EXT_uint8_t uint8_t
|
||||||
|
# define __PLOOC_PRI_uint8_t uint8_t
|
||||||
|
# define __PLOOC_PRO_uint8_t uint8_t
|
||||||
|
# define __PLOOC_EXT_
|
||||||
|
# define __PLOOC_PRI_
|
||||||
|
# define __PLOOC_PRO_
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# ifdef __OOC_DEBUG__
|
||||||
|
|
||||||
|
//! \brief wrapper for shell type
|
||||||
|
# define __PLOOC_EXT__public_member(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
# define __PLOOC_EXT__private_member(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
# define __PLOOC_EXT__protected_member(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
# define __PLOOC_EXT__which(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
|
||||||
|
//! \brief wrapper for internal private type
|
||||||
|
# define __PLOOC_PRI__public_member(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
# define __PLOOC_PRI__private_member(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
# define __PLOOC_PRI__protected_member(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
# define __PLOOC_PRI__which(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
|
||||||
|
//! \brief wrapper for internal protected type
|
||||||
|
# define __PLOOC_PRO__public_member(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
# define __PLOOC_PRO__private_member(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
# define __PLOOC_PRO__protected_member(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
# define __PLOOC_PRO__which(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
# else
|
||||||
|
|
||||||
|
//! \brief wrapper for shell type
|
||||||
|
# define __PLOOC_EXT__public_member(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
# define __PLOOC_EXT__private_member(...) PLOOC_INVISIBLE(__VA_ARGS__)
|
||||||
|
# define __PLOOC_EXT__protected_member(...) PLOOC_INVISIBLE(__VA_ARGS__)
|
||||||
|
# define __PLOOC_EXT__which(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
|
||||||
|
//! \brief wrapper for internal private type
|
||||||
|
# define __PLOOC_PRI__public_member(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
# define __PLOOC_PRI__private_member(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
# define __PLOOC_PRI__protected_member(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
# define __PLOOC_PRI__which(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
|
||||||
|
//! \brief wrapper for internal protected type
|
||||||
|
# define __PLOOC_PRO__public_member(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
# define __PLOOC_PRO__private_member(...) PLOOC_INVISIBLE(__VA_ARGS__)
|
||||||
|
# define __PLOOC_PRO__protected_member(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
# define __PLOOC_PRO__which(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
# endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L)
|
||||||
|
&& !defined(__cplusplus)
|
||||||
|
# undef which
|
||||||
|
# define which(__declare) ,_which(__declare)
|
||||||
|
#else
|
||||||
|
# undef which
|
||||||
|
# define which(...) ,_which(__VA_ARGS__)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#undef private_member
|
||||||
|
#define private_member ,_private_member
|
||||||
|
|
||||||
|
#undef protected_member
|
||||||
|
#define protected_member ,_protected_member
|
||||||
|
|
||||||
|
#undef public_member
|
||||||
|
#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.
|
||||||
|
*!
|
||||||
|
*! \note Make sure your constractor is named as <class_name>_init and it takes
|
||||||
|
*! an configuration structure with a type named as <class_name>_cfg_t.
|
||||||
|
*!
|
||||||
|
*! \note Make sure your destructor is named as <class_name>_depose.
|
||||||
|
*/
|
||||||
|
# undef __new_class
|
||||||
|
# define __new_class(__name, ...) \
|
||||||
|
__name##_init( \
|
||||||
|
(__name##_t *)plooc_malloc_align( sizeof(__name##_t), \
|
||||||
|
PLOOC_ALIGNOF(__name##_t)), \
|
||||||
|
(__name##_cfg_t []) {{__VA_ARGS__}} \
|
||||||
|
)
|
||||||
|
|
||||||
|
# undef __free_class
|
||||||
|
# define __free_class(__name, __obj) \
|
||||||
|
do { \
|
||||||
|
__name##_depose((__name##_t *)(__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 ====================================*/
|
||||||
|
/*============================ INCLUDES ======================================*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(__PLOOC_CLASS_USE_STRICT_TEMPLATE__)
|
||||||
|
# include "plooc_class_strict.h"
|
||||||
|
#elif defined(__PLOOC_CLASS_USE_SIMPLE_TEMPLATE__)
|
||||||
|
# if (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L) && !defined(__cplusplus)
|
||||||
|
# include "plooc_class_simple_c90.h"
|
||||||
|
# else
|
||||||
|
# include "plooc_class_simple.h"
|
||||||
|
# endif
|
||||||
|
#elif defined(__PLOOC_CLASS_USE_BLACK_BOX_TEMPLATE__)
|
||||||
|
# ifndef __PLOOC_I_KNOW_BLACK_BOX_IS_INCOMPATIBLE_WITH_OTHER_TEMPLATES__
|
||||||
|
# warning The black box template is incompatible with other templates. When\
|
||||||
|
header files which contains different templates mixing together, the one contains\
|
||||||
|
black box template will cause conflicts in other header files. To avoid such\
|
||||||
|
conflicts, you can either use black box alone in a project or in the source code of\
|
||||||
|
the target module avoid including header files which directly or indirectly \
|
||||||
|
including the header file of the very same module. To suppress this warning, please\
|
||||||
|
find the macro __PLOOC_I_KNOW_BLACK_BOX_IS_INCOMPATIBLE_WITH_OTHER_TEMPLATES__ in your\
|
||||||
|
project to acknowledge that you understand the facts and consequences.
|
||||||
|
# endif
|
||||||
|
# include "plooc_class_black_box.h"
|
||||||
|
#else
|
||||||
|
# include "plooc_class_simple.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#undef __PLOOC_CLASS_USE_STRICT_TEMPLATE__
|
||||||
|
#undef __PLOOC_CLASS_USE_SIMPLE_TEMPLATE__
|
||||||
|
#undef __PLOOC_CLASS_USE_BLACK_BOX_TEMPLATE__
|
||||||
|
#undef __PLOOC_CLASS_IMPLEMENT
|
||||||
|
#undef __PLOOC_CLASS_IMPLEMENT__
|
||||||
|
#undef __PLOOC_CLASS_INHERIT__
|
||||||
|
#undef __PLOOC_CLASS_INHERIT
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
# undef class
|
||||||
|
# undef this
|
||||||
|
# undef private
|
||||||
|
# undef public
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif //HW_LIB_PLOOC_CLASS_H
|
231
lib/utils/inc/plooc_class_black_box.h
Normal file
231
lib/utils/inc/plooc_class_black_box.h
Normal file
@@ -0,0 +1,231 @@
|
|||||||
|
#ifndef HW_LIB_PLOOC_CLASS_BLACK_BOX_H
|
||||||
|
#define HW_LIB_PLOOC_CLASS_BLACK_BOX_H
|
||||||
|
/*============================ INCLUDES ======================================*/
|
||||||
|
//#include <stdint.h>
|
||||||
|
//#include <stdbool.h>
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*============================ MACROS ========================================*/
|
||||||
|
#undef declare_class
|
||||||
|
#undef dcl_class
|
||||||
|
#undef def_class
|
||||||
|
#undef define_class
|
||||||
|
#undef __def_class
|
||||||
|
#undef end_def_class
|
||||||
|
#undef end_define_class
|
||||||
|
#undef __end_def_class
|
||||||
|
#undef extern_class
|
||||||
|
#undef __extern_class
|
||||||
|
#undef end_extern_class
|
||||||
|
#undef __end_extern_class
|
||||||
|
#undef class
|
||||||
|
#undef __class
|
||||||
|
/*============================ MACROFIED FUNCTIONS ===========================*/
|
||||||
|
|
||||||
|
#if defined(__PLOOC_CLASS_IMPLEMENT__) || defined(__PLOOC_CLASS_IMPLEMENT)
|
||||||
|
|
||||||
|
# ifdef __OOC_DEBUG__
|
||||||
|
# define __def_class(__name, __public ,...) \
|
||||||
|
typedef struct __name __name; \
|
||||||
|
typedef struct __##__name __##__name; \
|
||||||
|
struct __##__name { \
|
||||||
|
__public \
|
||||||
|
PLOOC_VISIBLE(__VA_ARGS__) \
|
||||||
|
}; \
|
||||||
|
struct __name { \
|
||||||
|
__public \
|
||||||
|
PLOOC_VISIBLE(__VA_ARGS__) \
|
||||||
|
};
|
||||||
|
# else
|
||||||
|
# define __def_class(__name, __public, ...) \
|
||||||
|
typedef struct __name __name; \
|
||||||
|
typedef struct __##__name __##__name; \
|
||||||
|
struct __##__name { \
|
||||||
|
__public \
|
||||||
|
PLOOC_VISIBLE(__VA_ARGS__) \
|
||||||
|
}; \
|
||||||
|
struct __name { \
|
||||||
|
__public \
|
||||||
|
PLOOC_INVISIBLE(__VA_ARGS__) \
|
||||||
|
};
|
||||||
|
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# define __end_def_class(__name, ...)
|
||||||
|
|
||||||
|
# undef private_member
|
||||||
|
# define private_member(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
|
||||||
|
# undef public_member
|
||||||
|
# define public_member(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
|
||||||
|
# undef __class
|
||||||
|
# define __class(__name) __##__name
|
||||||
|
|
||||||
|
# define class(__name) __class(__name)
|
||||||
|
|
||||||
|
#define __extern_class(__name,...)
|
||||||
|
#define __end_extern_class(__name, ...)
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#ifndef __OOC_DEBUG__
|
||||||
|
|
||||||
|
# define __def_class(__name, __public, ...) \
|
||||||
|
typedef struct __name __name; \
|
||||||
|
typedef struct __##__name __##__name; \
|
||||||
|
struct __##__name { \
|
||||||
|
__public \
|
||||||
|
PLOOC_VISIBLE(__VA_ARGS__) \
|
||||||
|
};
|
||||||
|
|
||||||
|
#define __extern_class(__name, __public, ...) \
|
||||||
|
typedef struct __name __name; \
|
||||||
|
struct __name { \
|
||||||
|
__public \
|
||||||
|
PLOOC_INVISIBLE(__VA_ARGS__) \
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#define __end_extern_class(__name, ...)
|
||||||
|
|
||||||
|
# undef private_member
|
||||||
|
# define private_member(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
|
||||||
|
# undef public_member
|
||||||
|
# define public_member(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
# define __def_class(__name, __public, ...) \
|
||||||
|
typedef struct __name __name; \
|
||||||
|
typedef struct __##__name __##__name; \
|
||||||
|
struct __##__name { \
|
||||||
|
__public \
|
||||||
|
PLOOC_VISIBLE(__VA_ARGS__) \
|
||||||
|
};
|
||||||
|
|
||||||
|
#define __extern_class(__name,__public, ...) \
|
||||||
|
typedef struct __name __name; \
|
||||||
|
struct __name { \
|
||||||
|
__public \
|
||||||
|
PLOOC_VISIBLE(__VA_ARGS__) \
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#define __end_extern_class(__name, ...)
|
||||||
|
|
||||||
|
# undef private_member
|
||||||
|
# define private_member(...) PLOOC_INVISIBLE(__VA_ARGS__)
|
||||||
|
|
||||||
|
# undef public_member
|
||||||
|
# define public_member(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
# define __end_def_class(__name, ...)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
# undef __class
|
||||||
|
# define __class(__name) __##__name
|
||||||
|
|
||||||
|
# undef class
|
||||||
|
# define class(__name) __class(__name)
|
||||||
|
|
||||||
|
|
||||||
|
#define declare_class(__name) typedef struct __name __name;
|
||||||
|
#define dcl_class(__name) declare_class(__name)
|
||||||
|
|
||||||
|
#define end_def_class(__name, ...) __end_def_class(__name, __VA_ARGS__)
|
||||||
|
#define end_define_class(__name, ...) end_def_class(__name, ...)
|
||||||
|
|
||||||
|
#define def_class(__name, __public, ...) \
|
||||||
|
__def_class(__name, __public, __VA_ARGS__)
|
||||||
|
#define define_class(__name, __public, ...) \
|
||||||
|
def_class(__name,__public, __VA_ARGS__)
|
||||||
|
|
||||||
|
#define class(__name) __class(__name)
|
||||||
|
|
||||||
|
#define extern_class(__name, __public, ...) \
|
||||||
|
__extern_class(__name, __public,__VA_ARGS__)
|
||||||
|
#define end_extern_class(__name, ...) __end_extern_class(__name, __VA_ARGS__)
|
||||||
|
|
||||||
|
#ifndef __PLOOC_CLASS_BLACK_BOX_H__
|
||||||
|
#define __PLOOC_CLASS_BLACK_BOX_H__
|
||||||
|
|
||||||
|
/*! \brief macro for initializing class in compiler-time
|
||||||
|
*! \param __type class name
|
||||||
|
*! \param __obj target object
|
||||||
|
*! \param ... initialization list
|
||||||
|
*/
|
||||||
|
#define __INIT_CLASS_OBJ(__type, __obj, ...) \
|
||||||
|
union { \
|
||||||
|
class(__type) __##__obj; \
|
||||||
|
__type; \
|
||||||
|
} __obj = { \
|
||||||
|
.__##__obj = __VA_ARGS__ \
|
||||||
|
}
|
||||||
|
#define init_class_obj(__type, __obj, ...) \
|
||||||
|
__INIT_CLASS_OBJ(__type, __obj, __VA_ARGS__)
|
||||||
|
|
||||||
|
#define __EXTERN_CLASS_OBJ(__type, __obj) \
|
||||||
|
extern union { \
|
||||||
|
class(__type) __##__obj; \
|
||||||
|
__type; \
|
||||||
|
}__obj;
|
||||||
|
#define extern_class_obj(__type, __obj) \
|
||||||
|
__EXTERN_CLASS_OBJ( __type, __obj )
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------*
|
||||||
|
* new standard (lower case) *
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
# undef __class_internal
|
||||||
|
# define __class_internal(__src, __des, __type, ...) \
|
||||||
|
class(__type) *(__des) = (class(__type) *)(__src); \
|
||||||
|
PLOOC_UNUSED_PARAM(__des); \
|
||||||
|
__with_class(__type, (__src), __VA_ARGS__)
|
||||||
|
|
||||||
|
# undef class_internal
|
||||||
|
# define class_internal(__src, __des, __type, ...) \
|
||||||
|
__class_internal(__src, __des, __type, __VA_ARGS__)
|
||||||
|
|
||||||
|
# undef __with_class
|
||||||
|
# define __with_class(__type, __src, ...) \
|
||||||
|
{ \
|
||||||
|
class(__type)*_ =(class(__type) *)(__src); \
|
||||||
|
PLOOC_UNUSED_PARAM(_); \
|
||||||
|
__VA_ARGS__; \
|
||||||
|
} \
|
||||||
|
for (class(__type)*_ =(class(__type) *)(__src); NULL != _; _ = NULL)
|
||||||
|
|
||||||
|
# undef with_class
|
||||||
|
# define with_class(__type, __src, ...) \
|
||||||
|
__with_class(__type, __src, __VA_ARGS__)
|
||||||
|
|
||||||
|
#undef which
|
||||||
|
#define which(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
|
||||||
|
/*============================ TYPES =========================================*/
|
||||||
|
|
||||||
|
/*============================ GLOBAL VARIABLES ==============================*/
|
||||||
|
/*============================ LOCAL VARIABLES ===============================*/
|
||||||
|
/*============================ PROTOTYPES ====================================*/
|
||||||
|
|
||||||
|
#undef __PLOOC_CLASS_IMPLEMENT__
|
||||||
|
#undef __PLOOC_CLASS_INHERIT__
|
||||||
|
#undef __PLOOC_CLASS_IMPLEMENT
|
||||||
|
#undef __PLOOC_CLASS_INHERIT
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif //HW_LIB_PLOOC_CLASS_BLACK_BOX_H
|
200
lib/utils/inc/plooc_class_simple.h
Normal file
200
lib/utils/inc/plooc_class_simple.h
Normal file
@@ -0,0 +1,200 @@
|
|||||||
|
#ifndef HW_LIB_PLOOC_CLASS_SIMPLE_H
|
||||||
|
#define HW_LIB_PLOOC_CLASS_SIMPLE_H
|
||||||
|
|
||||||
|
//#include "plooc_class.h"
|
||||||
|
|
||||||
|
/*============================ INCLUDES ======================================*/
|
||||||
|
//#include <stdint.h>
|
||||||
|
|
||||||
|
/*! \NOTE the uint_fast8_t used in this header file is defined in stdint.h
|
||||||
|
if you don't have stdint.h supported in your toolchain, you should
|
||||||
|
define uint_fast8_t all by yourself with following rule:
|
||||||
|
a. if the target processor is 8 bits, define it as uint8_t
|
||||||
|
b. if the target processor is 16 bits, define it as uint16_t
|
||||||
|
c. if the target processor is 32 bits, define it as uint32_t
|
||||||
|
d. if the target processor is 64 bits, define it as either uint32_t or
|
||||||
|
uint64_t
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
/*============================ MACROS ========================================*/
|
||||||
|
#undef private_member
|
||||||
|
#undef protected_member
|
||||||
|
#undef public_member
|
||||||
|
|
||||||
|
|
||||||
|
/*============================ MACROFIED FUNCTIONS ===========================*/
|
||||||
|
|
||||||
|
#ifndef __PLOOC_CLASS_SIMPLE_H__
|
||||||
|
#define __PLOOC_CLASS_SIMPLE_H__
|
||||||
|
|
||||||
|
# define __def_simple_class(__name) struct __name
|
||||||
|
# define def_simple_class(__name) __def_simple_class(__name)
|
||||||
|
# define define_simple_class(__name) def_simple_class(__name)
|
||||||
|
# define declare_simple_class(__name) typedef struct __name __name;
|
||||||
|
# define dcl_simple_class(__name) declare_simple_class(__name)
|
||||||
|
|
||||||
|
#endif /* __PLOOC_CLASS_SIMPLE_H__ */
|
||||||
|
|
||||||
|
#if defined(__OOC_DEBUG__)
|
||||||
|
|
||||||
|
# define private_member(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
# define protected_member(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
# define public_member(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
|
||||||
|
#elif defined(__PLOOC_CLASS_IMPLEMENT__) || defined(__PLOOC_CLASS_IMPLEMENT)
|
||||||
|
|
||||||
|
# define private_member(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
# define protected_member(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
# define public_member(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
|
||||||
|
#elif defined(__PLOOC_CLASS_INHERIT__) || defined(__PLOOC_CLASS_INHERIT)
|
||||||
|
|
||||||
|
# define private_member(...) PLOOC_INVISIBLE(__VA_ARGS__)
|
||||||
|
# define protected_member(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
# define public_member(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
|
||||||
|
#else /* __PLOOC_CLASS_EXTERN */
|
||||||
|
|
||||||
|
# define private_member(...) PLOOC_INVISIBLE(__VA_ARGS__)
|
||||||
|
# define protected_member(...) PLOOC_INVISIBLE(__VA_ARGS__)
|
||||||
|
# define public_member(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// code below is just try to be compatible with plooc_class_strict
|
||||||
|
#undef declare_class
|
||||||
|
#undef dcl_class
|
||||||
|
#undef def_class
|
||||||
|
#undef define_class
|
||||||
|
#undef __def_class
|
||||||
|
#undef end_def_class
|
||||||
|
#undef end_define_class
|
||||||
|
#undef __end_def_class
|
||||||
|
#undef extern_class
|
||||||
|
#undef __extern_class
|
||||||
|
#undef end_extern_class
|
||||||
|
#undef __end_extern_class
|
||||||
|
|
||||||
|
|
||||||
|
#define __end_def_class(...)
|
||||||
|
|
||||||
|
#define __def_class(__name, ...) \
|
||||||
|
typedef struct __name __name; \
|
||||||
|
struct __name { \
|
||||||
|
__VA_ARGS__ \
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(__PLOOC_CLASS_IMPLEMENT__) || defined(__PLOOC_CLASS_IMPLEMENT)
|
||||||
|
|
||||||
|
# undef __class
|
||||||
|
# define __class(__name) __name
|
||||||
|
|
||||||
|
# undef class
|
||||||
|
# define class(__name) __class(__name)
|
||||||
|
|
||||||
|
# undef __with_class
|
||||||
|
# define __with_class(__type, __src, ...) \
|
||||||
|
{ \
|
||||||
|
class(__type)*_ =(class(__type) *)(__src); \
|
||||||
|
PLOOC_UNUSED_PARAM(_); \
|
||||||
|
__VA_ARGS__; \
|
||||||
|
} \
|
||||||
|
for (class(__type)*_ =(class(__type) *)(__src); NULL != _; _ = NULL)
|
||||||
|
|
||||||
|
# undef with_class
|
||||||
|
# define with_class(__type, __src, ...) \
|
||||||
|
__with_class(__type, __src, __VA_ARGS__)
|
||||||
|
|
||||||
|
# undef __class_internal
|
||||||
|
# define __class_internal(__src, __des, __type, ...) \
|
||||||
|
class(__type) *(__des) = (class(__type) *)(__src); \
|
||||||
|
PLOOC_UNUSED_PARAM(__des); \
|
||||||
|
__with_class(__type, (__src), __VA_ARGS__)
|
||||||
|
|
||||||
|
# undef class_internal
|
||||||
|
# define class_internal(__src, __des, __type, ...) \
|
||||||
|
__class_internal(__src, __des, __type, __VA_ARGS__)
|
||||||
|
|
||||||
|
#define __extern_class(...)
|
||||||
|
|
||||||
|
#define __end_extern_class(...)
|
||||||
|
|
||||||
|
#elif defined(__PLOOC_CLASS_INHERIT__) || defined(__PLOOC_CLASS_INHERIT)
|
||||||
|
|
||||||
|
# undef __class_protected
|
||||||
|
# define __class_protected(__name) __name
|
||||||
|
|
||||||
|
# undef class_protected
|
||||||
|
# define class_protected(__name) __class_protected(__name)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# undef __with_protected
|
||||||
|
# define __with_protected(__type, __src, ...) \
|
||||||
|
{ \
|
||||||
|
class_protected(__type)*_ =(class_protected(__type) *)(__src); \
|
||||||
|
PLOOC_UNUSED_PARAM(_); \
|
||||||
|
__VA_ARGS__; \
|
||||||
|
}
|
||||||
|
|
||||||
|
# undef with_protected
|
||||||
|
# define with_protected(__type, __src, ...) \
|
||||||
|
__with_protected(__type, __src, __VA_ARGS__)
|
||||||
|
|
||||||
|
|
||||||
|
# undef __protected_internal
|
||||||
|
# define __protected_internal(__src, __des, __type, ...) \
|
||||||
|
class_protected(__type) *(__des)=(class_protected(__type) *)(__src);\
|
||||||
|
PLOOC_UNUSED_PARAM(__des); \
|
||||||
|
__with_protected(__type, __src, __VA_ARGS__)
|
||||||
|
|
||||||
|
# undef protected_internal
|
||||||
|
# define protected_internal(__src, __des, __type, ...) \
|
||||||
|
__protected_internal(__src, __des, __type, __VA_ARGS__)
|
||||||
|
|
||||||
|
#define __extern_class(...)
|
||||||
|
|
||||||
|
#define __end_extern_class(...)
|
||||||
|
|
||||||
|
#else /* __PLOOC_CLASS_EXTERN */
|
||||||
|
|
||||||
|
#define __extern_class(...) __def_class(__VA_ARGS__)
|
||||||
|
|
||||||
|
#define __end_extern_class(...)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#undef which
|
||||||
|
#define which(...) PLOOC_VISIBLE(__VA_ARGS__)
|
||||||
|
|
||||||
|
#define def_class(__name, ...) __def_class(__name, __VA_ARGS__)
|
||||||
|
#define define_class(__name, ...) def_class(__name, __VA_ARGS__)
|
||||||
|
|
||||||
|
#define end_def_class(...) __end_def_class(__VA_ARGS__)
|
||||||
|
#define end_define_class(...) end_def_class(__VA_ARGS__)
|
||||||
|
|
||||||
|
#define dcl_class(__name) typedef struct __name __name;
|
||||||
|
#define declare_class(__name) typedef struct __name __name;
|
||||||
|
|
||||||
|
#define extern_class(__name, ...) __extern_class(__name, __VA_ARGS__)
|
||||||
|
|
||||||
|
#define end_extern_class(__name, ...) __end_extern_class(__name, __VA_ARGS__)
|
||||||
|
|
||||||
|
#undef __PLOOC_CLASS_IMPLEMENT__
|
||||||
|
#undef __PLOOC_CLASS_INHERIT__
|
||||||
|
#undef __PLOOC_CLASS_IMPLEMENT
|
||||||
|
#undef __PLOOC_CLASS_INHERIT
|
||||||
|
/*============================ TYPES =========================================*/
|
||||||
|
/*============================ GLOBAL VARIABLES ==============================*/
|
||||||
|
/*============================ LOCAL VARIABLES ===============================*/
|
||||||
|
/*============================ PROTOTYPES ====================================*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif //HW_LIB_PLOOC_CLASS_SIMPLE_H
|
444
lib/utils/inc/plooc_class_strict.h
Normal file
444
lib/utils/inc/plooc_class_strict.h
Normal file
@@ -0,0 +1,444 @@
|
|||||||
|
#ifndef HW_LIB_PLOOC_CLASS_STRICT_H
|
||||||
|
#define HW_LIB_PLOOC_CLASS_STRICT_H
|
||||||
|
|
||||||
|
|
||||||
|
//#include "plooc_class.h"
|
||||||
|
|
||||||
|
/*============================ INCLUDES ======================================*/
|
||||||
|
//#include <stdint.h>
|
||||||
|
|
||||||
|
/*! \NOTE the uint_fast8_t used in this header file is defined in stdint.h
|
||||||
|
if you don't have stdint.h supported in your toolchain, you should
|
||||||
|
define uint_fast8_t all by yourself with following rule:
|
||||||
|
a. if the target processor is 8 bits, define it as uint8_t
|
||||||
|
b. if the target processor is 16 bits, define it as uint16_t
|
||||||
|
c. if the target processor is 32 bits, define it as uint32_t
|
||||||
|
d. if the target processor is 64 bits, define it as either uint32_t or
|
||||||
|
uint64_t
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
/*============================ MACROS ========================================*/
|
||||||
|
#undef dcl_class
|
||||||
|
#undef declare_class
|
||||||
|
#undef def_class
|
||||||
|
#undef define_class
|
||||||
|
#undef __def_class2
|
||||||
|
#undef __def_class3
|
||||||
|
#undef __def_class4
|
||||||
|
#undef __def_class5
|
||||||
|
#undef __def_class6
|
||||||
|
#undef __def_class7
|
||||||
|
#undef __def_class8
|
||||||
|
#undef __def_class
|
||||||
|
#undef end_def_class
|
||||||
|
#undef end_define_class
|
||||||
|
#undef __end_def_class
|
||||||
|
#undef extern_class
|
||||||
|
#undef __extern_class
|
||||||
|
#undef end_extern_class
|
||||||
|
#undef __end_extern_class
|
||||||
|
|
||||||
|
/*============================ MACROFIED FUNCTIONS ===========================*/
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(__PLOOC_CLASS_IMPLEMENT__) || defined(__PLOOC_CLASS_IMPLEMENT)
|
||||||
|
|
||||||
|
# define __def_class2(__name, _1) \
|
||||||
|
typedef struct __name __name; \
|
||||||
|
typedef struct __##__name __##__name; \
|
||||||
|
struct __##__name { \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRI_,_1) \
|
||||||
|
}; \
|
||||||
|
struct __name { \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
|
||||||
|
};
|
||||||
|
|
||||||
|
# define __def_class3(__name, _1, _2) \
|
||||||
|
typedef struct __name __name; \
|
||||||
|
typedef struct __##__name __##__name; \
|
||||||
|
struct __##__name { \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRI_,_1) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRI_,_2) \
|
||||||
|
}; \
|
||||||
|
struct __name { \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_2) \
|
||||||
|
};
|
||||||
|
|
||||||
|
# define __def_class4(__name, _1, _2, _3) \
|
||||||
|
typedef struct __name __name; \
|
||||||
|
typedef struct __##__name __##__name; \
|
||||||
|
struct __##__name { \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRI_,_1) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRI_,_2) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRI_,_3) \
|
||||||
|
}; \
|
||||||
|
struct __name { \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_2) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_3) \
|
||||||
|
};
|
||||||
|
|
||||||
|
# define __def_class5(__name, _1, _2, _3, _4) \
|
||||||
|
typedef struct __name __name; \
|
||||||
|
typedef struct __##__name __##__name; \
|
||||||
|
struct __##__name { \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRI_,_1) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRI_,_2) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRI_,_3) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRI_,_4) \
|
||||||
|
}; \
|
||||||
|
struct __name { \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_2) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_3) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_4) \
|
||||||
|
};
|
||||||
|
|
||||||
|
# define __def_class6(__name, _1, _2, _3, _4, _5) \
|
||||||
|
typedef struct __name __name; \
|
||||||
|
typedef struct __##__name __##__name; \
|
||||||
|
struct __##__name { \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRI_,_1) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRI_,_2) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRI_,_3) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRI_,_4) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRI_,_5) \
|
||||||
|
}; \
|
||||||
|
struct __name { \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_2) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_3) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_4) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_5) \
|
||||||
|
};
|
||||||
|
|
||||||
|
# define __def_class7(__name, _1, _2, _3, _4, _5, _6) \
|
||||||
|
typedef struct __name __name; \
|
||||||
|
typedef struct __##__name __##__name; \
|
||||||
|
struct __##__name { \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRI_,_1) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRI_,_2) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRI_,_3) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRI_,_4) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRI_,_5) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRI_,_6) \
|
||||||
|
}; \
|
||||||
|
struct __name { \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_2) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_3) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_4) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_5) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_6) \
|
||||||
|
};
|
||||||
|
|
||||||
|
# define __def_class8(__name, _1, _2, _3, _4, _5, _6, _7) \
|
||||||
|
typedef struct __name __name; \
|
||||||
|
typedef struct __##__name __##__name; \
|
||||||
|
struct __##__name { \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRI_,_1) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRI_,_2) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRI_,_3) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRI_,_4) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRI_,_5) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRI_,_6) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRI_,_7) \
|
||||||
|
}; \
|
||||||
|
struct __name { \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_2) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_3) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_4) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_5) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_6) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_7) \
|
||||||
|
};
|
||||||
|
|
||||||
|
# define __end_def_class(...)
|
||||||
|
|
||||||
|
# define __extern_class(...)
|
||||||
|
# define __end_extern_class(...)
|
||||||
|
|
||||||
|
|
||||||
|
# undef __class
|
||||||
|
# define __class(__name) __##__name
|
||||||
|
|
||||||
|
# undef class
|
||||||
|
# define class(__name) __class(__name)
|
||||||
|
|
||||||
|
|
||||||
|
# undef __with_class
|
||||||
|
# define __with_class(__type, __src, ...) \
|
||||||
|
{ \
|
||||||
|
class(__type)*_ =(class(__type) *)(__src); \
|
||||||
|
PLOOC_UNUSED_PARAM(_); \
|
||||||
|
__VA_ARGS__; \
|
||||||
|
} \
|
||||||
|
for (class(__type)*_ =(class(__type) *)(__src);NULL != _; _ = NULL)
|
||||||
|
|
||||||
|
# undef with_class
|
||||||
|
# define with_class(__type, __src, ...) \
|
||||||
|
__with_class(__type, __src, __VA_ARGS__)
|
||||||
|
|
||||||
|
# undef __class_internal
|
||||||
|
# define __class_internal(__src, __des, __type, ...) \
|
||||||
|
class(__type) *(__des) = (class(__type) *)(__src); \
|
||||||
|
PLOOC_UNUSED_PARAM(__des); \
|
||||||
|
__with_class(__type, (__src), __VA_ARGS__)
|
||||||
|
|
||||||
|
|
||||||
|
# undef class_internal
|
||||||
|
# define class_internal(__src, __des, __type,...) \
|
||||||
|
__class_internal(__src, __des, __type, __VA_ARGS__)
|
||||||
|
|
||||||
|
|
||||||
|
#elif defined(__PLOOC_CLASS_INHERIT__) || defined(__PLOOC_CLASS_INHERIT)
|
||||||
|
|
||||||
|
# define __def_class2(__name, _1) \
|
||||||
|
typedef struct __name __name; \
|
||||||
|
struct __protected_##__name { \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRO_,_1) \
|
||||||
|
}; \
|
||||||
|
struct __name { \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
|
||||||
|
};
|
||||||
|
|
||||||
|
# define __def_class3(__name, _1, _2) \
|
||||||
|
typedef struct __name __name; \
|
||||||
|
struct __protected_##__name { \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRO_,_1) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRO_,_2) \
|
||||||
|
}; \
|
||||||
|
struct __name { \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_2) \
|
||||||
|
};
|
||||||
|
|
||||||
|
# define __def_class4(__name, _1, _2, _3) \
|
||||||
|
typedef struct __name __name; \
|
||||||
|
struct __protected_##__name { \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRO_,_1) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRO_,_2) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRO_,_3) \
|
||||||
|
}; \
|
||||||
|
struct __name { \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_2) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_3) \
|
||||||
|
};
|
||||||
|
|
||||||
|
# define __def_class5(__name, _1, _2, _3, _4) \
|
||||||
|
typedef struct __name __name; \
|
||||||
|
struct __protected_##__name { \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRO_,_1) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRO_,_2) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRO_,_3) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRO_,_4) \
|
||||||
|
}; \
|
||||||
|
struct __name { \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_2) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_3) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_4) \
|
||||||
|
};
|
||||||
|
|
||||||
|
# define __def_class6(__name, _1, _2, _3, _4, _5) \
|
||||||
|
typedef struct __name __name; \
|
||||||
|
struct __protected_##__name { \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRO_,_1) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRO_,_2) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRO_,_3) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRO_,_4) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRO_,_5) \
|
||||||
|
}; \
|
||||||
|
struct __name { \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_2) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_3) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_4) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_5) \
|
||||||
|
};
|
||||||
|
|
||||||
|
# define __def_class7(__name, _1, _2, _3, _4, _5, _6) \
|
||||||
|
typedef struct __name __name; \
|
||||||
|
struct __protected_##__name { \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRO_,_1) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRO_,_2) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRO_,_3) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRO_,_4) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRO_,_5) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRO_,_6) \
|
||||||
|
}; \
|
||||||
|
struct __name { \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_2) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_3) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_4) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_5) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_6) \
|
||||||
|
};
|
||||||
|
|
||||||
|
# define __def_class8(__name, _1, _2, _3, _4, _5, _6, _7) \
|
||||||
|
typedef struct __name __name; \
|
||||||
|
struct __protected_##__name { \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRO_,_1) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRO_,_2) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRO_,_3) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRO_,_4) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRO_,_5) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRO_,_6) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_PRO_,_7) \
|
||||||
|
}; \
|
||||||
|
struct __name { \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_2) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_3) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_4) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_5) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_6) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_7) \
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# define __end_def_class(...)
|
||||||
|
|
||||||
|
# define __extern_class(...)
|
||||||
|
|
||||||
|
# define __end_extern_class(...)
|
||||||
|
|
||||||
|
# undef __class_protected
|
||||||
|
# define __class_protected(__name) struct __protected_##__name
|
||||||
|
|
||||||
|
# undef class_protected
|
||||||
|
# define class_protected(__name) __class_protected(__name)
|
||||||
|
|
||||||
|
|
||||||
|
# undef __with_protected
|
||||||
|
# define __with_protected(__type, __src, ...) \
|
||||||
|
{ \
|
||||||
|
class_protected(__type)*_ =(class_protected(__type) *)(__src); \
|
||||||
|
PLOOC_UNUSED_PARAM(_); \
|
||||||
|
__VA_ARGS__; \
|
||||||
|
} \
|
||||||
|
for ( class_protected(__type)*_ =(class_protected(__type) *)(__src); \
|
||||||
|
NULL != _; \
|
||||||
|
_ = NULL)
|
||||||
|
|
||||||
|
# undef with_protected
|
||||||
|
# define with_protected(__type, __src, ...) \
|
||||||
|
__with_protected(__type, __src, __VA_ARGS__)
|
||||||
|
|
||||||
|
# undef __protected_internal
|
||||||
|
# define __protected_internal(__src, __des, __type, ...) \
|
||||||
|
class_protected(__type) *(__des)=(class_protected(__type) *)(__src);\
|
||||||
|
PLOOC_UNUSED_PARAM(__des); \
|
||||||
|
__with_protected(__type, __src, __VA_ARGS__)
|
||||||
|
|
||||||
|
# undef protected_internal
|
||||||
|
# define protected_internal(__src, __des, __type, ...) \
|
||||||
|
__protected_internal(__src, __des, __type, __VA_ARGS__)
|
||||||
|
|
||||||
|
|
||||||
|
#else /* __PLOOC_CLASS_EXTERN */
|
||||||
|
|
||||||
|
# define __def_class2(__name, _1) \
|
||||||
|
typedef struct __name __name; \
|
||||||
|
struct __name { \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
|
||||||
|
};
|
||||||
|
|
||||||
|
# define __def_class3(__name, _1, _2) \
|
||||||
|
typedef struct __name __name; \
|
||||||
|
struct __name { \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_2) \
|
||||||
|
};
|
||||||
|
|
||||||
|
# define __def_class4(__name, _1, _2, _3) \
|
||||||
|
typedef struct __name __name; \
|
||||||
|
struct __name { \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_2) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_3) \
|
||||||
|
};
|
||||||
|
|
||||||
|
# define __def_class5(__name, _1, _2, _3, _4) \
|
||||||
|
typedef struct __name __name; \
|
||||||
|
struct __name { \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_2) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_3) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_4) \
|
||||||
|
};
|
||||||
|
|
||||||
|
# define __def_class6(__name, _1, _2, _3, _4, _5) \
|
||||||
|
typedef struct __name __name; \
|
||||||
|
struct __name { \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_2) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_3) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_4) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_5) \
|
||||||
|
};
|
||||||
|
|
||||||
|
# define __def_class7(__name, _1, _2, _3, _4, _5, _6) \
|
||||||
|
typedef struct __name __name; \
|
||||||
|
struct __name { \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_2) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_3) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_4) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_5) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_6) \
|
||||||
|
};
|
||||||
|
|
||||||
|
# define __def_class8(__name, _1, _2, _3, _4, _5, _6, _7) \
|
||||||
|
typedef struct __name __name; \
|
||||||
|
struct __name { \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_2) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_3) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_4) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_5) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_6) \
|
||||||
|
__PLOOC_CONNECT2(__PLOOC_EXT_,_7) \
|
||||||
|
};
|
||||||
|
|
||||||
|
# define __end_def_class(...)
|
||||||
|
|
||||||
|
#define __extern_class(...) __PLOOC_EVAL(__def_class, __VA_ARGS__) \
|
||||||
|
(__VA_ARGS__)
|
||||||
|
|
||||||
|
#define __end_extern_class(...)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define def_class(...) __PLOOC_EVAL(__def_class, __VA_ARGS__) \
|
||||||
|
(__VA_ARGS__)
|
||||||
|
#define define_class(...) def_class(__VA_ARGS__)
|
||||||
|
|
||||||
|
#define end_def_class(...) __end_def_class(__VA_ARGS__)
|
||||||
|
#define end_define_class(...) end_def_class(__VA_ARGS__)
|
||||||
|
|
||||||
|
#define declare_class(__name) typedef struct __name __name;
|
||||||
|
#define dcl_class(__name) declare_class(__name)
|
||||||
|
|
||||||
|
#define extern_class(...) __extern_class(__VA_ARGS__)
|
||||||
|
#define end_extern_class(...) __end_extern_class(__VA_ARGS__)
|
||||||
|
|
||||||
|
|
||||||
|
#undef __PLOOC_CLASS_IMPLEMENT__
|
||||||
|
#undef __PLOOC_CLASS_INHERIT__
|
||||||
|
#undef __PLOOC_CLASS_IMPLEMENT
|
||||||
|
#undef __PLOOC_CLASS_INHERIT
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif //HW_LIB_PLOOC_CLASS_STRICT_H
|
BIN
tools/font_lib/HZK16C
Normal file
BIN
tools/font_lib/HZK16C
Normal file
Binary file not shown.
BIN
tools/font_lib/HZK16F
Normal file
BIN
tools/font_lib/HZK16F
Normal file
Binary file not shown.
BIN
tools/font_lib/HZK16H
Normal file
BIN
tools/font_lib/HZK16H
Normal file
Binary file not shown.
BIN
tools/font_lib/HZK16K
Normal file
BIN
tools/font_lib/HZK16K
Normal file
Binary file not shown.
BIN
tools/font_lib/HZK16L
Normal file
BIN
tools/font_lib/HZK16L
Normal file
Binary file not shown.
BIN
tools/font_lib/HZK16S
Normal file
BIN
tools/font_lib/HZK16S
Normal file
Binary file not shown.
BIN
tools/font_lib/HZK16V
Normal file
BIN
tools/font_lib/HZK16V
Normal file
Binary file not shown.
BIN
tools/font_lib/HZK16X
Normal file
BIN
tools/font_lib/HZK16X
Normal file
Binary file not shown.
BIN
tools/font_lib/HZK16Y
Normal file
BIN
tools/font_lib/HZK16Y
Normal file
Binary file not shown.
BIN
tools/font_lib/HZK24F
Normal file
BIN
tools/font_lib/HZK24F
Normal file
Binary file not shown.
BIN
tools/font_lib/HZK24H
Normal file
BIN
tools/font_lib/HZK24H
Normal file
Binary file not shown.
BIN
tools/font_lib/HZK24K
Normal file
BIN
tools/font_lib/HZK24K
Normal file
Binary file not shown.
BIN
tools/font_lib/HZK24S
Normal file
BIN
tools/font_lib/HZK24S
Normal file
Binary file not shown.
BIN
tools/font_lib/HZK24T
Normal file
BIN
tools/font_lib/HZK24T
Normal file
Binary file not shown.
BIN
tools/font_lib/HZK32
Normal file
BIN
tools/font_lib/HZK32
Normal file
Binary file not shown.
BIN
tools/font_lib/HZK40S
Normal file
BIN
tools/font_lib/HZK40S
Normal file
Binary file not shown.
BIN
tools/font_lib/HZK40T
Normal file
BIN
tools/font_lib/HZK40T
Normal file
Binary file not shown.
BIN
tools/font_lib/HZK48S
Normal file
BIN
tools/font_lib/HZK48S
Normal file
Binary file not shown.
BIN
tools/font_lib/HZK48T
Normal file
BIN
tools/font_lib/HZK48T
Normal file
Binary file not shown.
@@ -1,154 +1,106 @@
|
|||||||
import numpy as np
|
Font_Lib = {
|
||||||
import PIL.ImageFont as pilfont
|
"HZK12": {"size": 12, "desc": "宋体优化"},
|
||||||
import PIL.Image as pilimage
|
"HZK16": {"size": 16, "desc": "宋体优化"},
|
||||||
import PIL.ImageDraw as pildraw
|
"HZK32": {"size": 32, "desc": "宋体优化"},
|
||||||
|
"HZK16S": {"size": 16, "desc": "宋体"},
|
||||||
|
"HZK16F": {"size": 16, "desc": "仿宋"},
|
||||||
|
"HZK16H": {"size": 16, "desc": "黑体"},
|
||||||
|
"HZK16K": {"size": 16, "desc": "楷体"},
|
||||||
|
"HZK16Y": {"size": 16, "desc": "幼圆"},
|
||||||
|
"HZK16L": {"size": 16, "desc": "隶书(效果较差)"},
|
||||||
|
"HZK16C": {"size": 16, "desc": "粗体"},
|
||||||
|
"HZK16X": {"size": 16, "desc": "细"},
|
||||||
|
"HZK16V": {"size": 16, "desc": "繁"},
|
||||||
|
"HZK24F": {"size": 24, "desc": "仿宋汉字打印点阵"},
|
||||||
|
"HZK24H": {"size": 24, "desc": "黑体汉字打印点阵"},
|
||||||
|
"HZK24K": {"size": 24, "desc": "楷体汉字打印点阵"},
|
||||||
|
"HZK24S": {"size": 24, "desc": "宋体汉字打印点阵"},
|
||||||
|
"HZK24T": {"size": 24, "desc": "宋体符号打印点阵"},
|
||||||
|
"HZK40S": {"size": 40, "desc": "宋体汉字"},
|
||||||
|
"HZK40T": {"size": 40, "desc": "宋体符号"},
|
||||||
|
"HZK48S": {"size": 48, "desc": "宋体汉字"},
|
||||||
|
"HZK48T": {"size": 48, "desc": "宋体符号"},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# def generate_chinese_struct(char_code, font, size):
|
class ChineseFontLibrary:
|
||||||
# image = pilimage.new('L', size)
|
def __init__(self, name, path="./font_lib/"):
|
||||||
# draw = pildraw.Draw(image)
|
self.size = Font_Lib.get(name)['size']
|
||||||
# draw.text((0, 0), char_code, font=font, fill=255)
|
self.path = path
|
||||||
# pixel_array = np.array(image)
|
self.fontname = name
|
||||||
# result = np.zeros(size[0] * size[1] // 8, dtype=np.uint8)
|
self.chinese_array = []
|
||||||
# for i in range(size[1]):
|
self.linecache = self.size * ((self.size + 7) // 8 * 8) // 8
|
||||||
# for j in range(size[0] // 8):
|
|
||||||
# for k in range(8):
|
|
||||||
# if pixel_array[j * 8 + k, i]:
|
|
||||||
# result[j * size[1] + i] |= (1 << k)
|
|
||||||
# return result
|
|
||||||
|
|
||||||
|
def format_chinese_array_as_text(self):
|
||||||
|
text_output = "#pragma once\n\n"
|
||||||
|
text_output += "#ifndef HW_LIB_FONT_CHUC_H\n"
|
||||||
|
text_output += "#define HW_LIB_FONT_CHUC_H\n\n"
|
||||||
|
text_output += f"typedef struct {{\n"
|
||||||
|
text_output += " uint8_t unicode[2];\n"
|
||||||
|
text_output += f" uint8_t data[{self.size * ((self.size + 7) // 8 * 8) // 8}];\n"
|
||||||
|
text_output += "} Chinese_t;\n\n"
|
||||||
|
text_output += f"static uint8_t Hzk_size={self.size};\n\n"
|
||||||
|
text_output += "static Chinese_t Hzk[] = {\n"
|
||||||
|
line_size = self.size * self.size // 8
|
||||||
|
line_size = line_size // 2
|
||||||
|
for item in self.chinese_array:
|
||||||
|
unicode_hex = ', '.join(f"0x{ord(char) >> 8:02X}, 0x{ord(char) & 0xFF:02X}" for char in item['name'])
|
||||||
|
print(unicode_hex, end=",")
|
||||||
|
text_output += f" {{\n // Original: {item['name']}\n"
|
||||||
|
text_output += f" {{ {unicode_hex} }},\n {{\n "
|
||||||
|
bytes_str = ', '.join(f"0x{byte:02X}" for byte in item['data'])
|
||||||
|
bytes_lines = [bytes_str[i:i + 6 * line_size] for i in range(0, len(bytes_str), 6 * line_size)]
|
||||||
|
# 每行显示line_size个字节
|
||||||
|
text_output += '\n '.join(bytes_lines)
|
||||||
|
text_output += ",\n }\n },\n"
|
||||||
|
text_output += "};\n\n"
|
||||||
|
text_output += "static Chinese_t* find_chinese_data(uint8_t unicode_high, uint8_t unicode_low) {\n"
|
||||||
|
text_output += " for (int i = 0; i < sizeof(Hzk) / sizeof(Chinese_t); ++i) {\n"
|
||||||
|
text_output += " if (Hzk[i].unicode[0] == unicode_high && Hzk[i].unicode[1] == unicode_low) {\n"
|
||||||
|
text_output += " return &Hzk[i];\n"
|
||||||
|
text_output += " }\n"
|
||||||
|
text_output += " }\n"
|
||||||
|
text_output += " return NULL;\n"
|
||||||
|
text_output += "}\n"
|
||||||
|
text_output += "\n#endif //HW_LIB_FONT_CHUC_H"
|
||||||
|
return text_output
|
||||||
|
|
||||||
def generate_chinese_struct(char_code, font, size):
|
def generate_chinese_struct(self, code):
|
||||||
incode = char_code.encode('gb2312') # 要读出的汉字
|
incode = code.encode('gb2312') # 要读出的汉字
|
||||||
qh, wh = incode[0] - 0xa0, incode[1] - 0xa0 # 占两个字节, 取其区位号
|
qh, wh = incode[0] - 0xa0, incode[1] - 0xa0 # 占两个字节, 取其区位号
|
||||||
|
offset = (94 * (qh - 1) + (wh - 1)) * self.linecache # 得到偏移位置
|
||||||
if size[0] == 12:
|
with open(self.path + self.fontname, "rb") as HZK:
|
||||||
offset = (94 * (qh - 1) + (wh - 1)) * 24 # 得到偏移位置
|
|
||||||
with open("HZK12", "rb") as HZK:
|
|
||||||
HZK.seek(offset)
|
HZK.seek(offset)
|
||||||
return HZK.read(24)
|
return HZK.read(self.linecache)
|
||||||
if size[0] == 16:
|
|
||||||
offset = (94 * (qh - 1) + (wh - 1)) * 32 # 得到偏移位置
|
def add_chinese_array(self, input_str: str):
|
||||||
with open("HZK16", "rb") as HZK:
|
for char_code in input_str:
|
||||||
HZK.seek(offset)
|
char_struct = self.generate_chinese_struct(char_code)
|
||||||
return HZK.read(32)
|
self.chinese_array.append({'name': char_code, 'data': char_struct})
|
||||||
|
return self
|
||||||
|
|
||||||
|
def write_chinese_array_output(self, filename='font_chuc.h'):
|
||||||
|
text_output = self.format_chinese_array_as_text()
|
||||||
|
with open(filename, 'w', encoding="utf8") as file:
|
||||||
|
file.write(text_output)
|
||||||
|
|
||||||
|
|
||||||
# from bitarray import bitarray
|
if __name__ == '__main__':
|
||||||
# # from PIL import Image, ImageDraw
|
i = 0
|
||||||
# # from bitarray import bitarray
|
for k, v in Font_Lib.items():
|
||||||
|
print(f"{i}:{k} - {v['size']} {v['desc']}")
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
input_c = input(f"请输入需要的字体序号(q退出):")
|
||||||
# def generate_chinese_struct(char_code, font, size):
|
if input_c == 'q':
|
||||||
# height=(size[1] + 7) // 8 * 8
|
exit()
|
||||||
# wight=(size[0] + 7) // 8 * 8
|
values_list = list(Font_Lib.values())
|
||||||
# image = Image.new('1', size, 1)
|
keys_list = list(Font_Lib.keys())
|
||||||
# draw = ImageDraw.Draw(image)
|
key_index = list(Font_Lib.values()).index(values_list[int(input_c)])
|
||||||
# draw.text((0, -1), char_code, font=font, fill=0)
|
print(
|
||||||
# image.show()
|
f"已选择{int(input_c)}:{keys_list[key_index]} - {Font_Lib[keys_list[key_index]]['size']} {Font_Lib[keys_list[key_index]]['desc']}")
|
||||||
# bitmap = bitarray()
|
font = ChineseFontLibrary(keys_list[key_index])
|
||||||
# for w in range(size[1]):
|
input_c = input(f"请输入需要生成的字符(顺序无关):")
|
||||||
# for h in range(size[0]):
|
print("将生成以下字符\n" + input_c)
|
||||||
# # if h > size[1] or w > size[0]:
|
font.add_chinese_array(input_c)
|
||||||
# # bitmap.append(False)
|
font.write_chinese_array_output()
|
||||||
# # else:
|
|
||||||
# if image.getpixel((w, h)) == 0:
|
|
||||||
# bitmap.append(True)
|
|
||||||
# print('■', end=' ')
|
|
||||||
# else:
|
|
||||||
# bitmap.append(False)
|
|
||||||
# print('0', end=' ')
|
|
||||||
# print()
|
|
||||||
# result = np.zeros(size[0] * size[1] // 8, dtype=np.uint8)
|
|
||||||
# # for i in range(height):
|
|
||||||
# # for j in range(wight // 8):
|
|
||||||
# # for k in range(8):
|
|
||||||
# # if bitmap[j * 8 + k, i]==1:
|
|
||||||
# # result[j * height + i] |= (1 << k)
|
|
||||||
# for h in range(height):
|
|
||||||
# for w in range(wight):
|
|
||||||
# if bitmap[w+h]:
|
|
||||||
# #前景字符(即用来表示汉字笔画的输出字符)
|
|
||||||
# print('■', end=' ')
|
|
||||||
# else:
|
|
||||||
#
|
|
||||||
# # 背景字符(即用来表示背景的输出字符)
|
|
||||||
# print('0', end=' ')
|
|
||||||
# print()
|
|
||||||
# return result
|
|
||||||
|
|
||||||
|
|
||||||
def generate_chinese_array(input_str, font_str, size):
|
|
||||||
font = pilfont.truetype(font_str, size=size[1])
|
|
||||||
chinese_array = []
|
|
||||||
for char_code in input_str:
|
|
||||||
char_struct = generate_chinese_struct(char_code, font, size)
|
|
||||||
chinese_array.append({'name': char_code, 'data': char_struct})
|
|
||||||
return chinese_array
|
|
||||||
|
|
||||||
|
|
||||||
def format_chinese_array_as_text(chinese_array, size):
|
|
||||||
text_output = "#pragma once\n\n"
|
|
||||||
text_output += "#ifndef HW_LIB_FONT_CHUC_H\n"
|
|
||||||
text_output += "#define HW_LIB_FONT_CHUC_H\n\n"
|
|
||||||
text_output += f"typedef struct {{\n"
|
|
||||||
text_output += " uint8_t unicode[2];\n"
|
|
||||||
text_output += f" uint8_t data[{size[0] * ((size[1] + 7) // 8 * 8) // 8}];\n"
|
|
||||||
text_output += "} Chinese_t;\n\n"
|
|
||||||
text_output += f"static uint8_t Hzk_size={size[0]};\n\n"
|
|
||||||
text_output += "static Chinese_t Hzk[] = {\n"
|
|
||||||
line_size = size[0] * size[1] // 8
|
|
||||||
line_size = line_size // 2
|
|
||||||
# line_size = 16 if line_size >= 16 else 8
|
|
||||||
for item in chinese_array:
|
|
||||||
unicode_hex = ', '.join(f"0x{ord(char) >> 8:02X}, 0x{ord(char) & 0xFF:02X}" for char in item['name'])
|
|
||||||
print(unicode_hex, end=",")
|
|
||||||
text_output += f" {{\n // Original: {item['name']}\n"
|
|
||||||
text_output += f" {{ {unicode_hex} }},\n {{\n "
|
|
||||||
bytes_str = ', '.join(f"0x{byte:02X}" for byte in item['data'])
|
|
||||||
bytes_lines = [bytes_str[i:i + 6 * line_size] for i in range(0, len(bytes_str), 6 * line_size)]
|
|
||||||
# 每行显示line_size个字节
|
|
||||||
text_output += '\n '.join(bytes_lines)
|
|
||||||
text_output += ",\n }\n },\n"
|
|
||||||
text_output += "};\n\n"
|
|
||||||
text_output += "static Chinese_t* find_chinese_data(uint8_t unicode_high, uint8_t unicode_low) {\n"
|
|
||||||
text_output += " for (int i = 0; i < sizeof(Hzk) / sizeof(Chinese_t); ++i) {\n"
|
|
||||||
text_output += " if (Hzk[i].unicode[0] == unicode_high && Hzk[i].unicode[1] == unicode_low) {\n"
|
|
||||||
text_output += " return &Hzk[i];\n"
|
|
||||||
text_output += " }\n"
|
|
||||||
text_output += " }\n"
|
|
||||||
text_output += " return NULL;\n"
|
|
||||||
text_output += "}\n"
|
|
||||||
text_output += "\n#endif //HW_LIB_FONT_CHUC_H"
|
|
||||||
return text_output
|
|
||||||
|
|
||||||
|
|
||||||
def generate_and_write_chinese_array_output():
|
|
||||||
# 生成包含汉字结构体的数组
|
|
||||||
# simsun: 宋体
|
|
||||||
# kaiti: 楷体
|
|
||||||
# size = (12, 12)
|
|
||||||
size = (16, 16)
|
|
||||||
# chinese_array = generate_chinese_array("当前液位", 'simsun', size)
|
|
||||||
chinese_array = generate_chinese_array("星海科技机械师", 'simsun', size)
|
|
||||||
|
|
||||||
# 将数组格式化为文本输出并写入文件
|
|
||||||
text_output = format_chinese_array_as_text(chinese_array, size)
|
|
||||||
with open('font_chuc.h', 'w', encoding="utf8") as file:
|
|
||||||
file.write(text_output)
|
|
||||||
|
|
||||||
|
|
||||||
# 调用函数生成并写入汉字数组输出文件
|
|
||||||
generate_and_write_chinese_array_output()
|
|
||||||
|
|
||||||
|
|
||||||
def generate_unicode_bin_file():
|
|
||||||
font = pilfont.truetype('simsun', size=16)
|
|
||||||
with open('cao.bin', 'wb') as file:
|
|
||||||
for char_code in range(0x4e00, 0xa000):
|
|
||||||
result = generate_chinese_struct(chr(char_code), font)
|
|
||||||
file.write(result)
|
|
||||||
file.close()
|
|
||||||
|
|
||||||
# 调用函数生成Unicode二进制文件
|
|
||||||
# generate_unicode_bin_file()
|
|
||||||
|
Reference in New Issue
Block a user