move PLOOC to package and use as optional

This commit is contained in:
lyon 2022-05-24 09:19:44 +08:00
parent c611408bd8
commit e2a630358c
21 changed files with 2327 additions and 4 deletions

0
package/PLOOC/PLOOC.pyi Normal file
View File

View File

View File

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
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
http://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.

View File

@ -0,0 +1,265 @@
# PLOOC (Protected Low-overhead Object Oriented programming with ANSI-C) v4.6.2
## Introduction
---
The Protected Low-overhead Object Oriented Programming with ANSI-C, a.k.a PLOOC ['plu:k] is a set of well-polished C macro templates which:
- Provide __protection for private__ class members
> NOTE: The protection can be disabled by defining macro __\_\_OOC_DEBUG\_\___ to facilitate debug.
- Support __protected__ members
- Support __multiple inheritance__
- Support interface implementation
- Support strict type checking/validation in certain compilers, such as IAR with multi-file compilation enabled.
- Compliant with __ANSI-C99__
- ANSI-C90 is also supported but the protection for private feature is disabled.
- Support **Overload**
- Require C11 or _Generic
- Low-overhead
> NOTE: Almost ZERO OVERHEAD. The template fully utilises the ANSI-C enforced compilation rules to deliver desired OO features with the the least necessary cost.
- Suitable for both bare-metal and RTOS.
- Suitable for both 8bit and 32bit MCU
### What makes PLOOC different from other OOCs?
The concept of OOC is not new. There are plenty of libraries, SDKs, templates providing objected-oriented programming extensions to ANSI-C language. Although PLOOC emphasises its low-overhead feature in both code size and performance, but a lot of macro template based ooc solutions are also low-overhead. PLOOC doesn't force you to use heap or pool for memory management, it doesn't provide GC feature. It simply leaves those options to users, so it is suitable for even 8bit system. Well, you can take this as draw-backs of PLOOC. I don't want to argue about this.
**So what really sets PLOOC different from the others? Is it simply another re-invented wheel?**
The answer is NO. Of course.
PLOOC brings an unique feature most of others don't have. It lets private members of a class truly become private, i.e. protected. So users outside of the class source code are prevented from accessing the private members. What they see will be a solid memory, a mask created with byte array. Since class is mimicked by structure in C, the class in PLOOC is implemented with the masked-structure. As people expected, only class source code can access the private members, only class source code of a derived class can access the protected members of the base class and everyone can access the public members.
How could this be? You might already figure it out simply through the word "masked-structure". As you noticed, it could be nothing more than a fancy type-cheating trick in header files.
The type-cheating trick works well until some strict-type-checking compiler is encountered. The most famous (notorious) one is IAR with multi-file compilation mode enabled. No type-cheating can survive from the bloody axe of IAR multi-file compilation mode.
//! the original structure in class source code
struct byte_queue_t {
uint8_t *pchBuffer;
uint16_t hwBufferSize;
uint16_t hwHead;
uint16_t hwTail;
uint16_t hwCount;
};
//! the masked structure: the class byte_queue_t in header file
typedef struct byte_queue_t {
uint8_t chMask [sizeof(struct {
uint8_t *pchBuffer;
uint16_t hwBufferSize;
uint16_t hwHead;
uint16_t hwTail;
uint16_t hwCount;
})];
} byte_queue_t;
In order to make it work, we have to make sure the class source codes don't include their own interface header file.
you can even do this...if you are serious about the content
//! the masked structure: the class byte_queue_t in header file
typedef struct byte_queue_t {
uint8_t chMask [sizeof(struct {
uint32_t : 32;
uint16_t : 16;
uint16_t : 16;
uint16_t : 16;
uint16_t : 16;
})];
} byte_queue_t;
> NOTE: Aforementioned code pieces are only used to show the underlying scheme but are not practical, as you can see, the alignment of the original structure is missing when creating the mask array. To solve the problem, you have to extract the alignment information via \_\_alignof\_\_() operator and set the mask array alignment attribute accordingly using \_\_attribute\_\_((aligned())).
PLOOC provides the "private-protection" feature with a different scheme other than type-cheating, so it support almost all C compilers with C99 feature enabled. As the author, I have to confess that it took me a lot of time to figure it out how to deal with strict-type-checking and the initial scheme was ugly and counter-intuition. Thanks to some inspiring contribution of SimonQian, it took me another 3 months to make PLOOC elegant and simple. The supports from HenryLong are also vital.
I hope you can enjoy this unique trying for the object-oriented programming challenge.
If you have any questions or suggestions, please feel free to let us know.
## Update Log
---
- \[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()***.
- Update example project
- Add CI to github.
- \[30/12/2021\] Improved CMSIS-Pac, version 4.6.0
- Added example project to CMSIS-Pack
- Added code templates for creating new base classes and derived classes.
- Other minor updates
- \[29/12/2021\] Add CMSIS-Pack, version 4.5.9
- Suppressed warnings when c99 is used for the LLVM and GCC.
- Fixed an unaligned access issue in the example
- Added CMSIS-Pack
- \[28/11/2020\] Minor update, version 4.5.7
- Fixed a typo in plooc.h
- Applied unified capitalisation in macros, i.e. if the macro is uppercase, the parameters are in uppercase, if the macro is lowercase, the parameters are in lowercase.
- Added warning to indicate that black box template is incompatible with other templates and should be used alone or under special rule when mixed with other templates.
- \[05/08/2020\] Add \_\_PLOOC\_CLASS\_IMPLEMENT\_\_ and \_\_PLOOC\_CLASS\_INHERIT\_\_ version 4.5.6
- used \_\_xxxxx\_\_ as emphasis because \_\_xxxxx usually means "internal"
- The original \_\_PLOOC\_CLASS\_IMPLEMENT and \_\_PLOOC\_CLASS\_INHERIT are deprecated and will be kept for a while before completely removed.
- \[18/05/2020\] Introduce both short- and long- style of macro, version 4.5.5
- dcl_xxxxx/declare_xxxxx
- def_xxxx/define_xxxxx; end_def_xxxx/end_define_xxxx
- \[16/05/2020\] Minor Update, version 4.5.4a
- Introduced \_\_OOC\_CPP\_\_ to replace \_\_OOC\_DEBUG\_\_ when you want to mix C source code with C++ source code. Please put it in the project global configuration.
- \[11/05/2020\] Minor Update, version 4.5.4
- Made it possible to use PLOOC based C source code in C++ project
- Please make sure \_\_OOC\_DEBUG\_\_ is defined in the project
- \[15/04/2020\] Update __PLOOC_EVAL, version 4.5.3
- Increased the range of number of arguments, from 1~8 to 0~16.
- [19/02/2020] Minor update to enable RAM footprint optimisation, version 4.52
- Introduced macro PLOOC_CFG_REMOVE_MEMORY_LAYOUT_BOUNDARY___USE_WITH_CAUTION which removes structure layout boundaries for PLOOC_VISIBLE. It can save RAM when certain condition is met and \_\_OOC\_DEBUG\_\_ is defined. Please use it with caution as it will cause different memory layouts when \_\_OOC\_DEBUG\_\_ is not defined.
- \[21/01/2020\] Misc update for C90, version 4.51
- \[09/06/2019\] Added support for C89/90, version 4.50
- Added full support for overload \(require C11\)
- \[09/05/2019\] Added support for C89/90, version 4.40
- When C89/90 is enforced, \_\_OOC_DEBUG\_\_ should always be defined.
- The protection for private and protected members is turned off.
- \[08/15/2019\] Updated plooc_class_strict.h to use more soften syntax, version 4.31
- Users now can use arbitrary order for public_member, private_member and protected_member.
- The separator "," can be ignored.
- Simplified the plooc_class_strict.h template. Some common macros are moved to plooc_class.h, which will be shared by other template later.
- \[08/14/2019\] Introduced support for limited support for overload, version 4.30
- Used can use macro \_\_PLOOC_EVAL() to select the right API which has the corresponding number of parameters.
- \[07/26/2019\] Syntax update, version 4.21
- Modified plooc_class_black_box.h to use unified syntax as other templates.
- Added extern_class and end_extern_class to all templates
- \[07/24/2019\] Added new ooc class template, version 4.20
- Added plooc_class_black_box.h. This template is used for creating true-black-box module. It only support "private" and "public" but no "protected".
- \[07/12/2019\] Minor Update, version 4.13
- Added "\_\_OOC_RELEASE\_\_". The struct requires protection only at development stage. For private properties, setters and getters are provided for controlling the access. It is possible to remove masks and allow private members observable in release stage, during this stage, the setters and getters can be changed from API functions to macros. By doing so, the code size can be smaller.
- \[05/30/2019\] Minor Update, version 4.12
- removed "this", "target" and "base" to prevent naming pollution.
- removed PLOOC_ALIGN from top-level class definition to prevent inconsistent compiler interpretation towards this alignment decoration.
- \[05/02/2019\] Efficiency improve, version 4.11
- Used \_\_alignof\_\_ to improve the code efficiency when dealing with masked structure
- Used PLOOC_INVISIABLE and PLOOC_VISIBLE in both simple and strict version
- Simplified the structure
- Improved capability between IAR and armclang (LLVM)
- \[05/01/2019\] Compatibility Improving, version 4.04
- Added PLOOC_PACKED and PLOOC_ALIGN to add alignment support
- Used uint_fast8_t to replace uint8_t to use target machine implied alignment.
- \[04/20/2019\] Upload PLOOC to github, version 4.03
- Added default class alignment control
- updated examples and readme
- \[04/17/2019\] Uploaded PLOOC to github, version 4.01
- Added method definition which support private method, protected method and public method
- Added readme and example byte_queue
## License
---
The PLOOC library was written by GorgonMeducer(王卓然)<embedded_zhuoran@hotmail.com> and Simon Qian钱晓晨<https://github.com/versaloon> with support from Henry Long <henry_long@163.com>.
The PLOOC library is released under an open source license Apache 2.0 that allows both commercial and non-commercial use without restrictions. The only requirement is that credits is given in the source code and in the documentation for your product.
The full license text follows:
/*****************************************************************************
* Copyright(C)2009-2019 by GorgonMeducer<embedded_zhuoran@hotmail.com> *
* and SimonQian<simonqian@simonqian.com> *
* with support from HenryLong<henry_long@163.com> *
* *
* 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 *
* *
* http://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. *
* *
****************************************************************************/
## Contribution
---
### Template
| module | Contrinutor |
| ------ | ------ |
| plooc.h | GorgonMeducer |
| plooc_class.h | GorgonMeducer, Simon Qian |
| plooc_class_strict.h | GorgonMeducer |
| plooc_class_back_box.h | GorgonMeducer |
| plooc_class_simple.h | Simon Qian |
| plooc_class_simple_c90.h | GorgonMeducer |
### Examples
| module | Contrinutor |
| ------ | ------ |
| How to define a class | GorgonMeducer |
| How to access protected members | GorgonMeducer |
| How to implement Polymorphism | GorgonMeducer |
## Applications / Projects which claim to use PLOOC
---
- [VSF][https://github.com/vsfteam/vsf]
- [GMSI][https://github.com/GorgonMeducer/Generic_MCU_Software_Infrastructure]
- [mqttclient][https://github.com/jiejieTop/mqttclient]
## How to Use
---
### Examples for PLOOC
#### Introduction
In order to show how PLOOC is easy and simple to use, examples are provided to demonstrate different aspects of the new OOPC method. Currently, the available examples are:
- byte_queue
- enhanced_byte_queue
More examples will be added later...
- ### [Example 1: How to define a class](https://github.com/GorgonMeducer/PLOOC/tree/master/example/byte_queue)
This example shows
- How to define a class
- How to add private member
- How to add protected member
- How to access class members
- How to define user friendly interface
### [Example 2: How to access protected members](https://github.com/GorgonMeducer/PLOOC/tree/master/example/enhanced_byte_queue)
- How to inherit from a base class
- How to access protected members which are inherited from base
- How to inherit a interface
- How to override base methods
### [Example 3: How to implement Overload ](https://github.com/GorgonMeducer/PLOOC/tree/master/example/trace)
- How to implement overload using PLOOC
- Require C11 support
```
LOG_OUT("\r\n-[Demo of overload]------------------------------\r\n");
LOG_OUT((uint32_t) 0x12345678);
LOG_OUT("\r\n");
LOG_OUT(0x12345678);
LOG_OUT("\r\n");
LOG_OUT("PI is ");
LOG_OUT(3.1415926f);
LOG_OUT("\r\n");
LOG_OUT("\r\nShow BYTE Array:\r\n");
LOG_OUT((uint8_t *)main, 100);
LOG_OUT("\r\nShow Half-WORD Array:\r\n");
LOG_OUT((uint16_t *)main, 100/sizeof(uint16_t));
LOG_OUT("\r\nShow WORD Array:\r\n");
LOG_OUT((uint32_t *)main, 100/sizeof(uint32_t));
```
![example3](./example/picture/example3.png?raw=true)

View File

@ -0,0 +1,369 @@
/*****************************************************************************
* Copyright(C)2009-2019 by GorgonMeducer<embedded_zhuoran@hotmail.com> *
* *
* 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 *
* *
* http://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. *
* *
****************************************************************************/
#ifndef __PROTECTED_LOW_OVERHEAD_OBJECT_ORIENTED_C_H__
#define __PROTECTED_LOW_OVERHEAD_OBJECT_ORIENTED_C_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
/*============================ 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
/* EOF */

View File

@ -0,0 +1,373 @@
/*****************************************************************************
* Copyright(C)2009-2019 by GorgonMeducer<embedded_zhuoran@hotmail.com> *
* and SimonQian<simonqian@simonqian.com> *
* with support from HenryLong<henry_long@163.com> *
* *
* 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 *
* *
* http://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(__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
/*! \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.
*/
#define __new_class(__name, ...) \
({__name##_cfg_t tCFG = { \
__VA_ARGS__ \
}; \
__name##_init( \
(__name##_t *)malloc(sizeof(__name##_t)), \
&tCFG);})
#define __free_class(__name, __obj) \
do { \
__name##_depose((__name##_t *)(__obj)); \
free(__obj); \
} while(0)
/*============================ 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

View File

@ -0,0 +1,249 @@
/****************************************************************************
* Copyright 2017 Gorgon Meducer (Email:embedded_zhuoran@hotmail.com) *
* *
* 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 *
* *
* http://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. *
* *
****************************************************************************/
/*============================ 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
/* EOF */

View File

@ -0,0 +1,219 @@
/*****************************************************************************
* Copyright(C)2009-2019 by GorgonMeducer<embedded_zhuoran@hotmail.com> *
* and SimonQian<simonqian@simonqian.com> *
* with support from HenryLong<henry_long@163.com> *
* *
* 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 *
* *
* http://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. *
* *
****************************************************************************/
/******************************************************************************
* HOW TO USE *
******************************************************************************/
//!Add following content to your module header file, e.g. xxxxxx.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

View File

@ -0,0 +1,172 @@
/*****************************************************************************
* Copyright(C)2009-2019 by GorgonMeducer<embedded_zhuoran@hotmail.com> *
* and SimonQian<simonqian@simonqian.com> *
* with support from HenryLong<henry_long@163.com> *
* *
* 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 *
* *
* http://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. *
* *
****************************************************************************/
/******************************************************************************
* HOW TO USE *
******************************************************************************/
//!Add following content to your module header file, e.g. xxxxxx.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_C90_H__
#define __PLOOC_CLASS_SIMPLE_C90_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__ */
# define private_member(__member) __member
# define protected_member(__member) __member
# define public_member(__member) __member
// 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(__name)
#define __def_class(__name, __member) \
/*typedef struct __name __name; */ \
struct __name { \
__member \
};
#if defined(__PLOOC_CLASS_IMPLEMENT__) || defined(__PLOOC_CLASS_IMPLEMENT)
# undef __class
# define __class(__name) __name
# undef class
# define class(__name) __class(__name)
# undef __class_internal
# define __class_internal(__src, __des, __type) \
class(__type) *(__des) = (class(__type) *)(__src);
# undef class_internal
# define class_internal(__src, __des, __type) \
__class_internal(__src, __des, __type)
#define __extern_class(__name, __member)
#define __end_extern_class(__name)
#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 __protected_internal
# define __protected_internal(__src, __des, __type) \
class_protected(__type) *(__des)=(class_protected(__type) *)(__src);
# undef protected_internal
# define protected_internal(__src, __des, __type) \
__protected_internal(__src, __des, __type)
#define __extern_class(__name, __member)
#define __end_extern_class(__name)
#else /* __PLOOC_CLASS_EXTERN */
#define __extern_class(__name, __member) __def_class(__name, __member)
#define __end_extern_class(__name)
#endif
#undef which
#define which(__type) __type
#define def_class(__name, __member) __def_class(__name, __member)
#define define_class(__name, __member) def_class(__name, __member)
#define end_def_class(__name) __end_def_class(__name)
#define end_define_class(__name) end_def_class(__name)
#define declare_class(__name) typedef struct __name __name;
#define dcl_class(__name) declare_class(__name)
#define extern_class(__name, __member) __extern_class(__name, __member)
#define end_extern_class(__name) __end_extern_class(__name)
#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

View File

@ -0,0 +1,472 @@
/*****************************************************************************
* Copyright(C)2009-2019 by GorgonMeducer<embedded_zhuoran@hotmail.com> *
* *
* 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 *
* *
* http://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. *
* *
****************************************************************************/
//#ifndef __PLOOC_CLASS_STRICT_H__ /* deliberately comment this out! */
//#define __PLOOC_CLASS_STRICT_H__ /* deliberately comment this out! */
/******************************************************************************
* HOW TO USE *
******************************************************************************/
//!Add following content to your module header file, e.g. xxxxxx.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
/*============================ TYPES =========================================*/
/*============================ GLOBAL VARIABLES ==============================*/
/*============================ LOCAL VARIABLES ===============================*/
/*============================ PROTOTYPES ====================================*/
//#endif /* deliberately comment this out! */
#ifdef __cplusplus
}
#endif

View File

@ -28,7 +28,9 @@
#ifndef __PIKA_OOC_H__
#define __PIKA_OOC_H__
#include "./3rd-party/PLOOC/plooc_class.h"
#if PIKA_PLOOC_ENABLE
#include "../pikascript-lib/PLOOC/plooc_class.h"
#else
#define private_member(X) X
#endif
#endif

View File

@ -35,7 +35,7 @@ enum LINK_IS_DEINIT_SELF {
LINK_IS_DEINIT_SELF_DISABLE,
};
dcl_class(Link)
typedef struct Link Link;
struct Link{
LinkNode* firstNode;
};

View File

@ -40,6 +40,7 @@
#define PIKA_BUILTIN_DICT_ENABLE 0
#define PIKA_READ_FILE_BUFF_SIZE 0x10000
#define PIKA_INIT_STRING_ENABLE 0
#define PIKA_PLOOC_ENABLE 0
/* optimize options */
#define PIKA_OPTIMIZE_SIZE 0