⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mal_properties.mx

📁 一个内存数据库的源代码这是服务器端还有客户端
💻 MX
📖 第 1 页 / 共 2 页
字号:
PropertyUpdateViolation exception when this can not be realized. Note, the property value itself is changed, not the object referenced.getProperty(O,P) retrieves the current value of a property. This may involvecalling a function or running a database query.setPropertyAttribute(O,P,A) changes the behavior of the property. For example,the attribute 'freeze' will result in a call to the underlying function onlyonce and to cache the result for the remainder of the objects life time.@+ Predefined propertiesThe MAL language uses a few defaults, recognizable as properties@multitable @columnfractions .1 .8@item unsafe @tab function has side effects.Default, unsafe=off@item read @tab data can be read but not updated@item append @tab data can be appended@end multitable@-The code base supports multiple property sets.Not used right now.@h#ifndef _MAL_PROPERTIES_#define _MAL_PROPERTIES_#include "mal.h"#include "mal_namespace.h"#define MAXPROPLIST 3typedef struct PROPrecord {	str nme;	str operator;	ValRecord val;	struct PROPrecord *nxt;} *Property;typedef struct PROPSET {	int refcount;	int maxlist;	Property prop[MAXPROPLIST];} *PropertySet;mal_export PropertySet newPropertySet(void);mal_export void freePropertySet(PropertySet ps);mal_export PropertySet cpyPropertySet(PropertySet old);mal_export Property cpyProperty(PropertySet * target, Property src);mal_export Property fndProperty(PropertySet ps, str nme);mal_export Property fndPropertyIndexed(PropertySet ps, int first, int last, str nme);mal_export Property setProperty(PropertySet ps, str nme, str op, int tpe, ptr val);mal_export ptr getPropertyValue(PropertySet ps, str nme);mal_export int getPropertyType(PropertySet ps, str nme);mal_export str propertySet2str(PropertySet ps);mal_export int isPropertyDefined(PropertySet ps, str nme);#define getProps(M,Y) M->var[Y]->props#define fndArgProperty(M,P,I,NME) fndProperty(getProps(M,getArg(P,I)),NME)#define setArgProperty(M,P,I,NME,OP,T,V) if(getProps(M,getArg(P,I))== 0) \		getProps(M,getArg(P,I))= newPropertySet();\		setProperty(getProps(M,getArg(P,I)),NME,OP,T,V)#endif@c#include "mal_config.h"#include "mal_properties.h"#include "mal_type.h"		/* for idcmp() */PropertySetnewPropertySet(){	PropertySet ps;	ps = (PropertySet) GDKzalloc(sizeof(struct PROPSET));	ps->refcount = 0;	ps->maxlist = MAXPROPLIST;	return ps;}PropertycpyProperty(PropertySet * target, Property src){	if (*target == 0)		*target = newPropertySet();	return setProperty(*target, src->nme, 			src->operator, src->val.vtype, VALptr(&src->val));}PropertySetcpyPropertySet(PropertySet old){	PropertySet ps;	Property pr;	int i;	ps = newPropertySet();	for(i=0; i< MAXPROPLIST; i++){		pr = old->prop[i];		while(pr){			cpyProperty(&ps, pr);			pr= pr->nxt;		}	}	return ps;}voidfreePropertySet(PropertySet ps){	Property p1, p2;	int i;	for (i = 0; i < MAXPROPLIST; i++) {		p1 = ps->prop[i];		while(p1){			p2 = p1->nxt;			GDKfree(p1);			p1= p2;		}	}	GDKfree(ps);}PropertyfndProperty(PropertySet ps, str nme){	Property pr;	int i;	if (ps == NULL || nme== NULL)		return NULL;	nme= getName(nme,strlen(nme));	for (i = 0; i < MAXPROPLIST; i++) {		pr = ps->prop[i];		while (pr) {			if (pr->nme== nme)				return pr;			pr = pr->nxt;		}	}	return 0;}PropertyfndPropertyIndexed(PropertySet ps, int first, int last, str nme){	Property pr;	int i;	if (ps == NULL)		return NULL;	nme= getName(nme,strlen(nme));	for (i = first; i < last; i++) {		pr = ps->prop[i];		while (pr) {			if (pr->nme== nme)				return pr;			pr = pr->nxt;		}	}	return 0;}intisPropertyDefined(PropertySet ps, str nme){	Property pr;	if( ps == NULL || nme== NULL) return FALSE;	pr = fndProperty(ps,nme);	return pr != NULL;}@-A property is assigned to a specific property list.@cPropertysetPropertyIndexed(PropertySet ps, int idx, str nme, str op, int tpe, ptr val){	Property pr;	pr = fndPropertyIndexed(ps, idx, idx + 1, nme);	if (pr == 0) {		pr = (Property) GDKmalloc(sizeof(struct PROPrecord));		pr->nxt = ps->prop[idx];		ps->prop[idx] = pr;		pr->nme = putName(nme,strlen(nme));	}	if (val)		VALset(&pr->val, tpe, val);	pr->operator= putName(op,strlen(op));	return pr;}PropertysetProperty(PropertySet ps, str nme, str op, int tpe, ptr val){	return setPropertyIndexed(ps, 0, nme, op, tpe, val);}@-The users of properties need a simple scheme to localize aproperty.@cptrgetPropertyValue(PropertySet ps, str nme){	Property pr;	pr = fndProperty(ps, nme);	if (pr)		return VALptr(&pr->val);	return NULL;}intgetPropertyType(PropertySet ps, str nme){	Property pr;	pr = fndProperty(ps, nme);	if (pr)		return pr->val.vtype;	return TYPE_void;}@-For debugging purposes we should be able to convert any property setback into a string. We simple assume the space required is limited.@cstrpropertySet2str(PropertySet ps){	char buf[128 * 1024];	str s = buf, t = 0;	Property pr;	int i,first=0;	if (ps == NULL )		return GDKstrdup("");	pr = ps->prop[0];	*s++ = '{';	for(i=0; i<MAXPROPLIST; i++){		pr = ps->prop[i];		while(pr){			t = 0;			if (first++ )				*s++ = ',';			ATOMformat(pr->val.vtype, VALget(&pr->val), &t);			if (pr->operator && * pr->operator)				sprintf(s, "%s%s%s", pr->nme, pr->operator, t);			else				sprintf(s, "%s", pr->nme);			while (*s)				s++;			pr= pr->nxt;			if (t)			GDKfree(t);		}	}	*s++ = '}';	*s = 0;	return GDKstrdup(buf);}@}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -