Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Z
zmap
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ensembl-gh-mirror
zmap
Commits
7e738187
Commit
7e738187
authored
16 years ago
by
edgrif
Browse files
Options
Downloads
Patches
Plain Diff
modify/add macros to allow enum to/from exact string OR enum to/from given string.
parent
7f6dcb98
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/include/ZMap/zmapEnum.h
+68
-11
68 additions, 11 deletions
src/include/ZMap/zmapEnum.h
with
68 additions
and
11 deletions
src/include/ZMap/zmapEnum.h
+
68
−
11
View file @
7e738187
...
...
@@ -23,13 +23,14 @@
* Ed Griffiths (Sanger Institute, UK) edgrif@sanger.ac.uk,
* Roy Storey (Sanger Institute, UK) rds@sanger.ac.uk
*
* Description:
* Description: defines macros allowing a single string/enum definition
* to be used to produce enum types, print functions and
* and more.
*
* Exported functions: See XXXXXXXXXXXXX.h
* HISTORY:
* Last edited:
Jun 11 14:1
4 2008 (
rds
)
* Last edited:
Nov 13 09:0
4 2008 (
edgrif
)
* Created: Tue Jun 10 17:27:31 2008 (rds)
* CVS info: $Id: zmapEnum.h,v 1.
1
2008-
06-
11
13
:44:55 rds
Exp $
* CVS info: $Id: zmapEnum.h,v 1.
2
2008-11
-
13
09:05:15 edgrif
Exp $
*-------------------------------------------------------------------
*/
...
...
@@ -66,32 +67,45 @@
* added struct enum_dummy to swallow the semi-colon. G_STMT_START/END
* uses do{...}while(0) idiom, but that doesn't work here. */
#define ENUM_BODY(name, value
)
\
#define ENUM_BODY(name, value
, dummy)
\
name value,
#define AS_STRING_CASE(name, value
)
\
#define AS_STRING_CASE(name, value
, dummy)
\
case name: { return #name; }
#define FROM_STRING_CASE(name, value
)
\
#define FROM_STRING_CASE(name, value
, dummy)
\
if (strcmp(str, #name) == 0) { \
return name; \
}
#define ENUM2STR(name, dummy, string) \
{name, string},
#define SWALLOW_SEMI_COLON struct enum_dummy
/* Only the ZMAP_xxxxx Functions swallow the semi-colon! */
/*
* Define enum type automatically.
*/
#define ZMAP_DEFINE_ENUM(name, list) \
typedef enum { \
list(ENUM_BODY) \
} name; \
SWALLOW_SEMI_COLON
#define ZMAP_ENUM_AS_STRING_DEC(fname, name) \
/*
* Defines enum to exact string convertor function automatically.
*/
#define ZMAP_ENUM_AS_EXACT_STRING_DEC(fname, name) \
const char* fname(name n); \
SWALLOW_SEMI_COLON
#define ZMAP_ENUM_AS_STRING_FUNC(fname, name, list) \
#define ZMAP_ENUM_AS_
EXACT_
STRING_FUNC(fname, name, list) \
const char* fname(name n) { \
switch (n) { \
list(AS_STRING_CASE) \
...
...
@@ -100,11 +114,15 @@ SWALLOW_SEMI_COLON
} \
SWALLOW_SEMI_COLON
#define ZMAP_ENUM_FROM_STRING_DEC(fname, name) \
/*
* Defines exact string to enum convertor function automatically.
*/
#define ZMAP_ENUM_FROM_EXACT_STRING_DEC(fname, name) \
name fname(const char* str); \
SWALLOW_SEMI_COLON
#define ZMAP_ENUM_FROM_STRING_FUNC(fname, name, list) \
#define ZMAP_ENUM_FROM_
EXACT_
STRING_FUNC(fname, name, list) \
name fname(const char* str) { \
list(FROM_STRING_CASE) \
return 0; \
...
...
@@ -112,6 +130,45 @@ SWALLOW_SEMI_COLON
SWALLOW_SEMI_COLON
/*
* Defines given string to enum convertor function automatically.
*/
#define ZMAP_ENUM_FROM_STRING_DEC(FUNCNAME, TYPE) \
TYPE FUNCNAME(const char* str) ; \
SWALLOW_SEMI_COLON
#define ZMAP_ENUM_FROM_STRING_FUNC(fname, TYPE, INVALID_VALUE, list) \
TYPE fname(const char* str) \
{ \
typedef struct {TYPE enum_value ; char *string ;} TYPE##Enum2StrStruct ; \
\
TYPE result = INVALID_VALUE ; \
TYPE##Enum2StrStruct values[] = \
{ \
list(ENUM2STR) \
{INVALID_VALUE, NULL} \
} ; \
TYPE##Enum2StrStruct *curr = values ; \
\
while(curr->string) \
{ \
if (g_ascii_strcasecmp(str, curr->string) == 0) \
{ \
result = curr->enum_value ; \
break ; \
} \
\
curr++ ; \
} \
\
return result ; \
} \
SWALLOW_SEMI_COLON
#ifdef REQUIRE_NON_TYPEDEF_ENUM_FUNCS
/* Additionally gnc_engine_util.h defines these Non typedef enum
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment