add GetFlagAttr/SetFlagAttr to deal with flag attributes as callbak and ref/unref

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7603 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2005-10-07 13:16:21 +00:00
commit deba68d4da
2 changed files with 28 additions and 8 deletions

View file

@ -373,20 +373,29 @@ DohGetChar(DOH *obj, const DOH *name) {
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* DohGetFlag() * DohGetFlagAttr() / DohGetFlag()
* A flag is unset if the attribute (name) does not exist on the node (obj), * A flag is unset if the attribute (name) does not exist on the node (obj),
* or it is set to "0". If the attribute is set to any other value, the flag is set. * or it is set to "0". If the attribute is set to any other value,
* the flag is set.
*
* DohGetFlag() returns if the flag is set or not
* DohGetFlagAttr() returns the flag value if is set, NULL otherwise
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
DOH *
DohGetFlagAttr(DOH *obj, const DOH *name) {
DOH *val = Getattr(obj,(DOH *) name);
if (!val) return NULL;
return (Strcmp(val, "0") != 0) ? val : NULL;
}
int int
DohGetFlag(DOH *obj, const DOH *name) { DohGetFlag(DOH *obj, const DOH *name) {
DOH *val; return DohGetFlagAttr(obj, name) ? 1: 0;
val = Getattr(obj,(DOH *) name);
if (!val) return 0;
return (Strcmp(val, "0") != 0);
return 0;
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* DohGetVoid() * DohGetVoid()
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
@ -436,9 +445,14 @@ DohSetChar(DOH *obj, const DOH *name, char *value) {
* DohSetFlag() * DohSetFlag()
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
void
DohSetFlagAttr(DOH *obj, const DOH *name, const DOH* attr) {
Setattr(obj,(DOH *) name, attr ? attr : NewString("0"));
}
void void
DohSetFlag(DOH *obj, const DOH *name) { DohSetFlag(DOH *obj, const DOH *name) {
Setattr(obj,(DOH *) name,NewString("1")); Setattr(obj,(DOH *) name, NewString("1"));
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------

View file

@ -193,7 +193,9 @@ extern double DohGetDouble(DOH *obj, const DOHString_or_char *name);
extern void DohSetDouble(DOH *obj, const DOHString_or_char *name, double); extern void DohSetDouble(DOH *obj, const DOHString_or_char *name, double);
extern char *DohGetChar(DOH *obj, const DOHString_or_char *name); extern char *DohGetChar(DOH *obj, const DOHString_or_char *name);
extern void DohSetChar(DOH *obj, const DOH *name, char *value); extern void DohSetChar(DOH *obj, const DOH *name, char *value);
extern void *DohGetFlagAttr(DOH *obj, const DOHString_or_char *name);
extern int DohGetFlag(DOH *obj, const DOHString_or_char *name); extern int DohGetFlag(DOH *obj, const DOHString_or_char *name);
extern void DohSetFlagAttr(DOH *obj, const DOHString_or_char *name, const DOHString_or_char *attr);
extern void DohSetFlag(DOH *obj, const DOHString_or_char *name); extern void DohSetFlag(DOH *obj, const DOHString_or_char *name);
extern void *DohGetVoid(DOH *obj, const DOHString_or_char *name); extern void *DohGetVoid(DOH *obj, const DOHString_or_char *name);
extern void DohSetVoid(DOH *obj, const DOHString_or_char *name, void *value); extern void DohSetVoid(DOH *obj, const DOHString_or_char *name, void *value);
@ -359,12 +361,16 @@ extern void DohMemoryDebug(void);
#define GetDouble DohGetDouble #define GetDouble DohGetDouble
#define GetChar DohGetChar #define GetChar DohGetChar
#define GetVoid DohGetVoid #define GetVoid DohGetVoid
#define GetFlagAttr DohGetFlagAttr
#define GetFlag DohGetFlag #define GetFlag DohGetFlag
#define SetInt DohSetInt #define SetInt DohSetInt
#define SetDouble DohSetDouble #define SetDouble DohSetDouble
#define SetChar DohSetattr #define SetChar DohSetattr
#define SetVoid DohSetVoid #define SetVoid DohSetVoid
#define SetFlagAttr DohSetFlagAttr
#define SetFlag DohSetFlag #define SetFlag DohSetFlag
#define UnsetFlag(o,n) DohSetFlagAttr(o,n,NULL)
#define ClearFlag(o,n) DohSetFlagAttr(o,n,"")
#define Readline DohReadline #define Readline DohReadline
#define Replace DohReplace #define Replace DohReplace
#define Chop DohChop #define Chop DohChop