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

📄 gdk_value.mx

📁 这个是内存数据库中的一个管理工具
💻 MX
📖 第 1 页 / 共 2 页
字号:
@' The contents of this file are subject to the MonetDB Public License@' Version 1.1 (the "License"); you may not use this file except in@' compliance with the License. You may obtain a copy of the License at@' http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html@'@' Software distributed under the License is distributed on an "AS IS"@' basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the@' License for the specific language governing rights and limitations@' under the License.@'@' The Original Code is the MonetDB Database System.@'@' The Initial Developer of the Original Code is CWI.@' Portions created by CWI are Copyright (C) 1997-2007 CWI.@' All Rights Reserved.@f gdk_value@a Martin L. Kersten & Peter Boncz@v 2.0@+ Value representationWhen manipulating values, MonetDB puts them into value records.The built-in types have a direct entry in the union. Others shouldbe represented as a pointer of memory in pval or as a string, whichis basically the same. In such cases the @%len@ field indicatesthe size of this piece of memory.MonetDB extenders will use value records for passing parameters totheir new operators. MonetDB algebraic commands receive an(argc, argv) combination, whereargc is an integer indicating the size of the the argv array of valuerecords. On call, the first record, argv[0], is always empty. Theroutine must place its return value - if any - there. The othervalues are the parameters.@{Actually, the gdk value type defined here should become a built-intype in the kernel. Next step will be to define the correspondingextension module.@}@{@+ Value operationsThe following primitives are required to manipulate value records.Note that binding a BAT requires upgrading its reference count.The receiver of the value should have been cleared or representfree space.@c#include "monetdb_config.h"#include "gdk.h"ValPtrVALnew(void){	ValPtr v = (ValPtr) GDKmalloc(sizeof(ValRecord));	VALempty(v);	return v;}ValPtrVALset(ValPtr v, int t, ptr p){	switch (ATOMstorage(v->vtype = t)) {	case TYPE_chr:		v->val.cval[0] = *(chr *) p;		v->val.cval[1] = 0;		v->val.cval[2] = 0;		v->val.cval[3] = 0;		break;	case TYPE_bte:		v->val.btval = *(bte *) p;		break;	case TYPE_sht:		v->val.shval = *(sht *) p;		break;	case TYPE_int:		v->val.ival = *(int *) p;		break;	case TYPE_flt:		v->val.fval = *(flt *) p;		break;	case TYPE_dbl:		v->val.dval = *(dbl *) p;		break;	case TYPE_lng:		v->val.lval = *(lng *) p;		break;	default:		v->val.pval = p;		v->len = ATOMlen(t, p);	}	return v;}void *VALget(ValPtr v){	switch (ATOMstorage(v->vtype)) {	case TYPE_chr:		return (void *) &v->val.cval[0];	case TYPE_bte:		return (void *) &v->val.btval;	case TYPE_sht:		return (void *) &v->val.shval;	case TYPE_void:	case TYPE_int:		return (void *) &v->val.ival;	case TYPE_flt:		return (void *) &v->val.fval;	case TYPE_dbl:		return (void *) &v->val.dval;	case TYPE_lng:		return (void *) &v->val.lval;	case TYPE_str:		return (void *) v->val.pval;	}	return NULL;}voidVALclear(ValPtr v){	if (v->vtype == TYPE_str || ATOMextern(v->vtype)) {		if (v->val.pval && v->val.pval != str_nil)			GDKfree(v->val.pval);	}	VALempty(v);}voidVALempty(ValPtr v){	v->len = 0;	v->val.oval = oid_nil;	v->vtype = TYPE_void;}ValPtrVALcopy(ValPtr d, ValPtr s){	if (!ATOMextern(s->vtype)) {		*d = *s;	} else if (s->val.pval == 0) {		d->val.pval = ATOMnil(s->vtype);		d->vtype = s->vtype;	} else if (s->vtype == TYPE_str) {		d->vtype = TYPE_str;		d->val.sval = GDKstrdup(s->val.sval);		d->len = strLen(d->val.sval);	} else if (s->vtype == TYPE_bit) {		d->vtype = s->vtype;		d->len = 1;		d->val.cval[0] = s->val.cval[0];	} else {		ptr p = s->val.pval;		d->vtype = s->vtype;		d->len = ATOMlen(d->vtype, p);		d->val.pval = GDKmalloc(d->len);		memcpy(d->val.pval, p, d->len);	}	return d;}ValPtrVALinit(ValPtr d, int tpe, ptr s){	if (ATOMextern(tpe) == 0) {		d->vtype = tpe;		memcpy(&d->val.ival, s, ATOMlen(tpe, s));	} else if (s == 0) {		GDKerror("VALinit:unsupported init\n");		d->vtype = TYPE_int;	} else if (tpe >= TYPE_str && ATOMstorage(tpe) == TYPE_str) {		d->vtype = TYPE_str;		d->val.sval = GDKstrdup(s);		d->len = strLen(s);	} else {		d->vtype = tpe;		d->len = ATOMlen(tpe, s);		d->val.pval = GDKmalloc(d->len);		memcpy(d->val.pval, s, d->len);	}	return d;}@-VALprint shows the contents of a value record, but withoutexpanding the BAT contents.@cintVALprint(stream *s, ValPtr res){	int t = ATOMstorage(res->vtype);	return ATOMprint(t, VALptr(res), s);}intVALformat(char **buf, ValPtr res){	int t = res->vtype;	*buf = 0;	return ATOMformat(t, VALptr(res), buf);}@-The routine @%VALconvert@ transforms a value for interpretationin a certain type. It uses some standard cast conventions to do this.The result, a pointer to a value, is returned. If there areillegal values, or type combinations involved, it givesup with an ILLEGALVALUE.@= valcheck	((@3) @1 < (@3) GDK_@2_min || (@3) @1 > (@3) GDK_@2_max) ? @2_nil : (@2) @1@= valcheck_r	/* when converting from oid, there's no need to compare to GDK_@2_min,	 * since source value is unsigned (i.e. >= 0) and all GDK_*_min values	 * are <= 0 (in fact, compilers may warn about the test) */	((@3) @1 > (@3) GDK_@2_max) ? @2_nil : (@2) @1@= valcheck_l	/* when converting to oid, there's no need to compare to GDK_@2_max	 * for those types, where we know that GDK_@2_max <= GDK_oid_max	 * (in fact, compilers may warn about the test) */	((@3) @1 < (@3) GDK_@2_min) ? @2_nil : (@2) @1@= valfconvert	/* dbl always fits; flt almost always fits */	switch (src_tpe) {	case TYPE_bit:	case TYPE_chr:		@1 = (@2) src->val.cval[0];		break;	case TYPE_bte:		@1 = (@2) src->val.btval;		break;	case TYPE_sht:		@1 = (@2) src->val.shval;		break;	case TYPE_int:		@1 = (@2) src->val.ival;		break;	case TYPE_oid:		@1 = (@2) src->val.oval;		break;	case TYPE_wrd:		@1 = (@2) src->val.wval;		break;	case TYPE_lng:		@1 = (@2) src->val.lval;		break;	case TYPE_flt:		@1 = (@2) src->val.fval;		break;	case TYPE_dbl:		/* only need to do range check on dbl for dbl->flt conversion */		if (src->val.dval < (dbl) GDK_@2_min || src->val.dval > (dbl) GDK_@2_max)			@1 = @2_nil;		else			@1 = (@2) src->val.dval;		break;	case TYPE_bat:		@1 = (@2) src->val.bval;		break;	}@c/* convert value in src and store in dst   does not destroy src, but src and dst are allowed to point to the   same location if the caller knows that that won't do any harm */ptrVALconvert1(int typ, ValPtr src, ValPtr dst){	int orig_src_tpe = src->vtype, src_tpe = src->vtype, dst_tpe = typ;	ptr p;			/* what's going to be returned (may change for BATs */	/* use base types for user types */	if (src_tpe > TYPE_str)		src_tpe = ATOMstorage(src_tpe);	if (dst_tpe > TYPE_str)		dst_tpe = ATOMstorage(dst_tpe);	if (src != dst)		*dst = *src;	/* copy already in case there is no conversion */	/* we saved the original value of src->vtype, so we can	   overwrite that (in case src==dst */	dst->vtype = typ;	p = VALptr(dst);	if (src_tpe != dst_tpe && orig_src_tpe != typ && dst_tpe != TYPE_void) {		if (src_tpe >= TYPE_str || dst_tpe >= TYPE_str) {			if (ATOMcmp(src_tpe, ATOMnilptr(src_tpe), VALptr(src)) == 0) {				VALset(dst, dst_tpe, ATOMnil(dst_tpe));			} else {				return ILLEGALVALUE;			}		} else if ((orig_src_tpe == TYPE_bat && src->val.bval == 0) ||			   ATOMcmp(src_tpe, ATOMnilptr(src_tpe), VALptr(src)) == 0) {			/* dst_tpe is a built-in type, so VALptr(dst) (p) points to valid memory */			memcpy(p, ATOMnilptr(dst_tpe), ATOMsize(dst_tpe));		} else {			switch (dst_tpe) {			case TYPE_bat:			{				bat bid = (bat) 0;				switch (src_tpe) {				case TYPE_bit:				case TYPE_chr:					if (ABS(src->val.cval[0]) <= BBPsize)						bid = (bat) src->val.cval[0];					break;				case TYPE_bte:					if (ABS(src->val.btval) <= BBPsize)						bid = (bat) src->val.btval;					break;				case TYPE_sht:					if (ABS(src->val.shval) <= BBPsize)						bid = (bat) src->val.shval;					break;				case TYPE_int:					if (ABS(src->val.ival) <= BBPsize)						bid = (bat) src->val.ival;					break;				case TYPE_oid:					if (ABS(src->val.oval) <= BBPsize)						bid = (bat) src->val.oval;					break;				case TYPE_wrd:					if (ABS(src->val.wval) <= BBPsize)						bid = (bat) src->val.wval;					break;				case TYPE_lng:					if (ABS(src->val.lval) <= BBPsize)						bid = (bat) src->val.lval;					break;				case TYPE_flt:					if (ABS(src->val.fval) <= BBPsize)						bid = (bat) src->val.fval;					break;				case TYPE_dbl:					if (ABS(src->val.dval) <= BBPsize)						bid = (bat) src->val.dval;					break;				}				if (bid == 0 || !BBPvalid(bid)) {					return ILLEGALVALUE;				}

⌨️ 快捷键说明

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