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

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7603 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2005-10-07 13:16:21 +00:00
commit c974e55455
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),
* 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
DohGetFlag(DOH *obj, const DOH *name) {
DOH *val;
val = Getattr(obj,(DOH *) name);
if (!val) return 0;
return (Strcmp(val, "0") != 0);
return 0;
return DohGetFlagAttr(obj, name) ? 1: 0;
}
/* -----------------------------------------------------------------------------
* DohGetVoid()
* ----------------------------------------------------------------------------- */
@ -436,9 +445,14 @@ DohSetChar(DOH *obj, const DOH *name, char *value) {
* DohSetFlag()
* ----------------------------------------------------------------------------- */
void
DohSetFlagAttr(DOH *obj, const DOH *name, const DOH* attr) {
Setattr(obj,(DOH *) name, attr ? attr : NewString("0"));
}
void
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 char *DohGetChar(DOH *obj, const DOHString_or_char *name);
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 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 *DohGetVoid(DOH *obj, const DOHString_or_char *name);
extern void DohSetVoid(DOH *obj, const DOHString_or_char *name, void *value);
@ -359,12 +361,16 @@ extern void DohMemoryDebug(void);
#define GetDouble DohGetDouble
#define GetChar DohGetChar
#define GetVoid DohGetVoid
#define GetFlagAttr DohGetFlagAttr
#define GetFlag DohGetFlag
#define SetInt DohSetInt
#define SetDouble DohSetDouble
#define SetChar DohSetattr
#define SetVoid DohSetVoid
#define SetFlagAttr DohSetFlagAttr
#define SetFlag DohSetFlag
#define UnsetFlag(o,n) DohSetFlagAttr(o,n,NULL)
#define ClearFlag(o,n) DohSetFlagAttr(o,n,"")
#define Readline DohReadline
#define Replace DohReplace
#define Chop DohChop