diff options
author | 2023-06-20 22:21:57 +0600 | |
---|---|---|
committer | 2023-06-20 22:21:57 +0600 | |
commit | 06d3ab6ce203be3cb8a9d5bdcf86224b48fa3006 (patch) | |
tree | 6b006b2d407645ad78a588ea83f113f7637f115d | |
parent | 858a09b5f21d2b8c5f963c0a8fe39c478c95bbde (diff) | |
download | c-obp-example-06d3ab6ce203be3cb8a9d5bdcf86224b48fa3006.tar.gz c-obp-example-06d3ab6ce203be3cb8a9d5bdcf86224b48fa3006.zip |
Rename the Object like template header
Signed-off-by: Mubashshir <ahmubashshir@gmail.com>
-rw-r--r-- | src/cobj.h | 46 | ||||
-rw-r--r-- | src/teams-hell.h | 50 | ||||
-rw-r--r-- | src/teams.c | 4 | ||||
-rw-r--r-- | src/teams.h | 8 |
4 files changed, 51 insertions, 57 deletions
diff --git a/src/cobj.h b/src/cobj.h new file mode 100644 index 0000000..f8a4fec --- /dev/null +++ b/src/cobj.h @@ -0,0 +1,46 @@ +#ifndef __COBJ_IMPLS_H__ +# define __COBJ_IMPLS_H__ +# define get(klass, instance, field, ...) \ + klass##_get_##field(instance, ## __VA_ARGS__) +# define set(klass, instance, field, ...) \ + klass##_set_##field(instance, ## __VA_ARGS__) +# define new(klass, ...) klass##_new(__VA_ARGS__) +# define del(klass, ...) klass##_del(__VA_ARGS__) +# define ask(klass, fun, ...) klass##_##fun(__VA_ARGS__) +#endif /* __COBJ_IMPLS_H__ */ + +#if defined(__USE_C_OBJSYS__) +# undef GETTER +# undef SETTER +# undef DEFINE +# undef NEW +# undef DEL +# undef __USE_C_OBJSYS__ +#elif defined(__COBJ_PRIV_IMPLS_H__) +# define UNUSED(arg) while(0 && (arg)) +# define GETTER(klass, field, type, body, ...) \ + type klass##_get_##field(klass self, ## __VA_ARGS__) \ + body +# define SETTER(klass, field, type, body, ...) \ + bool klass##_set_##field(klass self, ## __VA_ARGS__, type value) \ + body +# define DEFINE(klass, name, type, body, ...) \ + type klass##_##name(klass self, ## __VA_ARGS__) \ + body +# define NEW(klass, body, ...) \ + klass klass ## _new(__VA_ARGS__) \ + body +# define DEL(klass, body, ...) \ + void klass ## _del(klass self, ## __VA_ARGS__) \ + body +#else +# define GETTER(klass, field, type, ...) \ + type klass##_get_##field(klass self, ## __VA_ARGS__) +# define SETTER(klass, field, type, ...) \ + bool klass##_set_##field(klass self, ## __VA_ARGS__, type value) +# define DEFINE(klass, name, type, ...) \ + type klass##_##name(klass self, ## __VA_ARGS__) +# define NEW(klass, ...) klass klass ## _new(__VA_ARGS__) +# define DEL(klass, ...) void klass ## _del(klass self, ## __VA_ARGS__) +# define __USE_C_OBJSYS__ +#endif diff --git a/src/teams-hell.h b/src/teams-hell.h deleted file mode 100644 index a59a4e1..0000000 --- a/src/teams-hell.h +++ /dev/null @@ -1,50 +0,0 @@ -#if defined(__TEAMS_H__) || defined(__TEAMS_PRIVATE_UNDEF__) - -# ifndef __TEAMS_HELL_H__ -# define __TEAMS_HELL_H__ -# define get(klass, instance, field, ...) \ - klass##_get_##field(instance, ## __VA_ARGS__) -# define set(klass, instance, field, ...) \ - klass##_set_##field(instance, ## __VA_ARGS__) -# define new(klass, ...) klass##_new(__VA_ARGS__) -# define del(klass, ...) klass##_del(__VA_ARGS__) -# define ask(klass, fun, ...) klass##_##fun(__VA_ARGS__) -# endif /* __TEAMS_HELL_H__ */ - -# if defined(__TEAMS_PRIVATE_UNDEF__) -# undef GETTER -# undef SETTER -# undef DEFINE -# undef NEW -# undef DEL -# undef __TEAMS_PRIVATE_UNDEF__ -# undef __TEAMS_PRIVATE_H__ -# elif defined(__IMPL_TEAMS_INTERNAL) -# define UNUSED(arg) while(0 && (arg)) -# define GETTER(klass, field, type, body, ...) \ - type klass##_get_##field(klass self, ## __VA_ARGS__) \ - body -# define SETTER(klass, field, type, body, ...) \ - bool klass##_set_##field(klass self, ## __VA_ARGS__, type value) \ - body -# define DEFINE(klass, name, type, body, ...) \ - type klass##_##name(klass self, ## __VA_ARGS__) \ - body -# define NEW(klass, body, ...) \ - klass klass ## _new(__VA_ARGS__) \ - body -# define DEL(klass, body, ...) \ - void klass ## _del(klass self, ## __VA_ARGS__) \ - body -# elif defined(__TEAMS_PRIVATE_H__) -# define GETTER(klass, field, type, ...) \ - type klass##_get_##field(klass self, ## __VA_ARGS__) -# define SETTER(klass, field, type, ...) \ - bool klass##_set_##field(klass self, ## __VA_ARGS__, type value) -# define DEFINE(klass, name, type, ...) \ - type klass##_##name(klass self, ## __VA_ARGS__) -# define NEW(klass, ...) klass klass ## _new(__VA_ARGS__) -# define DEL(klass, ...) void klass ## _del(klass self, ## __VA_ARGS__) -# endif - -#endif diff --git a/src/teams.c b/src/teams.c index 2f0814a..e8dbf74 100644 --- a/src/teams.c +++ b/src/teams.c @@ -3,8 +3,8 @@ #include <string.h> #include "teams.h" -#define __IMPL_TEAMS_INTERNAL -#include "teams-hell.h" +#define __COBJ_PRIV_IMPLS_H__ +#include "cobj.h" typedef struct team_impl_struct { char name[255]; diff --git a/src/teams.h b/src/teams.h index 3eba2f7..87cc01f 100644 --- a/src/teams.h +++ b/src/teams.h @@ -1,9 +1,8 @@ #ifndef __TEAMS_H__ # define __TEAMS_H__ -# define __TEAMS_PRIVATE_H__ # include <stdint.h> # include <stdbool.h> -# include "teams-hell.h" +# include "cobj.h" // Type definition typedef struct team_impl_struct * team; @@ -26,8 +25,7 @@ GETTER(team, solved, uint8_t); // helper functions DEFINE(team, printf, int); DEFINE(team, fprintf, int, FILE *); -DEFINE(team, find_champion, team, team *, unsigned num); +DEFINE(team, find_champion, team, team *, unsigned); -# define __TEAMS_PRIVATE_UNDEF__ -# include "teams-hell.h" +# include "cobj.h" #endif /* __TEAMS_H__ */ |