Ejemplo n.º 1
0
/* Create FastIntBuffer with initial page size of 1024 ints */
FastIntBuffer *createFastIntBuffer(){
	FastIntBuffer *fib = NULL;
	ArrayList *al= createArrayList();
	if (al==NULL){
		throwException2(out_of_mem,
			"FastIntBuffer allocation failed ");
		return NULL;
	}

	fib = (FastIntBuffer *)malloc(sizeof(FastIntBuffer));
	if (fib==NULL) {
		freeArrayList(al);
		throwException2(out_of_mem,
			"FastIntBuffer allocation failed ");
		return NULL;
	}

	fib->size = 0;
	fib->capacity = 0;
	fib->pageSize = 1<<10;
	fib->exp = 10;
	fib->r = 1023;
	fib->al = al;
	return fib;
}
Ejemplo n.º 2
0
NodeRecorder* createNodeRecorder(VTDNav *vn){
	exception e;
	NodeRecorder *nr;
	if (vn==NULL){
		throwException2(invalid_argument,
			"NodeRecorder allocation failed ");
		return NULL;
	}
	nr = (NodeRecorder*) malloc(sizeof(NodeRecorder));
	if (nr==NULL) {
		throwException2(out_of_mem,
			"NodeRecorder allocation failed ");
		return NULL;
	}
	nr->vn = vn;
	Try{
		nr->fib = createFastIntBuffer2(BUF_SZ_EXPO);
	}Catch(e){
		free(nr);
		throwException2(out_of_mem,
			"NodeRecorder allocation failed ");
		return NULL;
	}

	nr->count = nr->size = nr->position = 0;
	return nr;
}
Ejemplo n.º 3
0
/* create FastLongBuffer with page size of (1<<e) longs*/
FastLongBuffer *createFastLongBuffer2(int exp){
	FastLongBuffer *flb = NULL;
	ArrayList *al= createArrayList();
	if (al==NULL){
		throwException2(out_of_mem,
			"FastLongBuffer allocation failed ");
		return NULL;
	}

	flb = (FastLongBuffer *)malloc(sizeof(FastLongBuffer));
	if (flb==NULL) {
		freeArrayList(al); 
		throwException2(out_of_mem,
			"FastLongBuffer allocation failed ");
		return NULL;
	}

	flb->size = 0;
	flb->capacity = 0;
	flb->pageSize = 1<<exp;
	flb->exp = exp;
	flb->r = (1<<exp)-1;
	flb->al = al;

	return flb;
}
Ejemplo n.º 4
0
void bind4BookMark(BookMark *bm, VTDNav *vn) {
    if (vn==NULL)
        throwException2(invalid_argument,"vn can't be null");
    bm->vn1 = vn;
    if (vn->shallowDepth) {
        if (bm->ba == NULL || vn->nestingLevel+8 != bm->ba_len) {
            if (vn->nestingLevel+8 != bm->ba_len) {
                free(bm->ba);
            }
            bm->ba = malloc(sizeof(int)*(vn->nestingLevel + 8));
            if (bm->ba == NULL) {
                throwException2(out_of_mem,
                                "BookMark.ba allocation failed ");
            }
        }
    } else {
        if (bm->ba == NULL || vn->nestingLevel+8 != bm->ba_len) {
            if (vn->nestingLevel+14 != bm->ba_len) {
                free(bm->ba);
            }
            bm->ba = malloc(sizeof(int)*(vn->nestingLevel + 14));
            if (bm->ba == NULL) {
                throwException2(out_of_mem,
                                "BookMark.ba allocation failed ");
            }
        }
    }
    bm->ba[0]= -2 ; // this would never happen in a VTDNav obj's context
}
Ejemplo n.º 5
0
/* append a long array to the end of FastLongBuffer */
void appendLongArray(FastLongBuffer *flb, Long *longArray, int len){
	Long *lastBuffer = NULL;
	int lastBufferIndex;

	if (longArray == NULL || len <0) {
		throwException2(invalid_argument,
			"invalid argument for appendLongArray /n");
    }
    /* no additional buffer space needed */
	if (flb->al->size == 0)
	{
		lastBuffer = (Long *) malloc(sizeof(Long)<< flb->exp);
		if (lastBuffer == NULL){
			throwException2(out_of_mem,
				" appendLongArray failed to allocate mem ");
		}
		add(flb->al,lastBuffer);
		lastBufferIndex = 0;
		flb->capacity = flb->pageSize;
	}else {
		lastBufferIndex = min((flb->size>>flb->exp),flb->al->size-1);
		lastBuffer = (Long *)get(flb->al, lastBufferIndex);
	}


	if ((flb->size + len)< flb->capacity){
		if (flb->size + len <(lastBufferIndex+1)<<flb->exp){
			memcpy(lastBuffer+(flb->size&flb->r), longArray, len<<3);
		} 
		else {
			int offset = flb->pageSize -(flb->size&flb->r);
			int l = len - offset;
			int k = (l)>>flb->exp;
			int z;
			memcpy(lastBuffer+(flb->size & flb->r),
				longArray,offset<<3);
			for (z=1;z<=k;z++){
				memcpy(get(flb->al,lastBufferIndex+z),
					longArray+offset, flb->pageSize<<3);
				offset += flb->pageSize;
			}
			memcpy(get(flb->al,lastBufferIndex+z),
				longArray + offset, (l & flb->r)<<3);

		}
		flb->size += len;
		return;
    } else
        {
Ejemplo n.º 6
0
unaryExpr *createUnaryExpr(opType op, expr *e1){
	unaryExpr* ue = (unaryExpr *)malloc(sizeof(unaryExpr));
	if (ue == NULL){
		//e1->freeExpr(e1);
		throwException2(out_of_mem,
			"unaryExpr allocation failed ");
		return NULL;
	}
	ue->freeExpr = (free_Expr)&freeUnaryExpr;
	ue->evalBoolean = (eval_Boolean)&evalBoolean_ue;
	ue->evalNodeSet = (eval_NodeSet)&evalNodeSet_ue;
	ue->evalNumber  = (eval_Number)&evalNumber_ue;
	ue->evalString  = (eval_String)&evalString_ue;
	ue->isNumerical = (is_Numerical)&isNumerical_ue;
	ue->isBoolean = (is_Boolean)&isBoolean_ue;
	ue->isString =  (is_String)&isString_ue;
	ue->isNodeSet = (is_NodeSet)&isNodeSet_ue;
	ue->requireContextSize = (require_ContextSize)&requireContextSize_ue;
	ue->setContextSize = (set_ContextSize)&setContextSize_ue;
	ue->setPosition = (set_Position)&setPosition_ue;
	ue->reset = (reset_)&reset_ue;
	ue->toString = (to_String)&toString_ue;
	ue->adjust = (adjust_)&adjust_ue;
	ue->e = e1;
	ue->op = op;
	ue->clearCache=(clearCache_)&clearCache_ue;
	ue->markCacheable = (markCacheable_)&markCacheable_ue;
	ue->markCacheable2 = (markCacheable2_)&markCacheable2_ue;
	ue->isFinal = (isFinal_)&isFinal_ue;
	ue->getFuncOpCode = (getFuncOpCode_)&getFuncOpCode;
	return ue;
}
Ejemplo n.º 7
0
void bind4NodeRecorder(NodeRecorder *nr, VTDNav *vn){
	if (vn==NULL){
		throwException2(invalid_argument,
			"vn can't be NULL");
	}
	nr->vn = vn;
}
Ejemplo n.º 8
0
UCSChar* evalString_ne  (numberExpr *ne,VTDNav *vn){
	Boolean b = FALSE;
	double d = 0;
	UCSChar *tmp;
	if (ne->dval != ne->dval){
		tmp = wcsdup(L"NaN");
		b = TRUE;
	}
	else if ( ne->dval == 1/d){
		tmp = wcsdup(L"Infinity");
		b= TRUE;
	}
	else if (ne->dval == -1/d){
		tmp = wcsdup(L"-Infinity");
		b = TRUE;
	}	else
	tmp = malloc(sizeof(UCSChar)<<8);

	if (tmp == NULL) {
		throwException2(out_of_mem,
			"string allocation in evalString_ne failed ");
	}
	if (b)
		return tmp;
    if (ne->dval == (Long) ne->dval){
		swprintf(tmp, 64, L"%d",(Long) ne->dval);
	} else {
		swprintf(tmp, 64, L"%f", ne->dval);
	}
	return tmp;
}
Ejemplo n.º 9
0
numberExpr *createNumberExpr (double d){
	numberExpr *n = (numberExpr*) malloc(sizeof(numberExpr));
	if (n==NULL){
		throwException2(out_of_mem,
			"numberExpr allocation failed ");
		return NULL;
	}
	n->freeExpr = (free_Expr)&freeNumberExpr;
	n->evalBoolean = (eval_Boolean)&evalBoolean_ne;
	n->evalNodeSet = (eval_NodeSet)&evalNodeSet_ne;
	n->evalNumber  = (eval_Number)&evalNumber_ne;
	n->evalString  = (eval_String)&evalString_ne;
	n->isNumerical = (is_Numerical)&isNumerical_ne;
	n->isBoolean = (is_Boolean)&isBoolean_ne;
	n->isString =  (is_String)&isString_ne;
	n->isNodeSet = (is_NodeSet)&isNodeSet_ne;
	n->requireContextSize = (require_ContextSize)&requireContextSize_ne;
	n->setContextSize = (set_ContextSize)&setContextSize_ne;
	n->setPosition = (set_Position)&setPosition_ne;
	n->reset = (reset_)&reset_ne;
	n->toString = (to_String)&toString_ne;
	n->adjust =  (adjust_)&adjust_ne;
	n->dval= d;
	n->isFinal = (isFinal_)&isFinal_ne;
	n->markCacheable = (markCacheable_)&markCacheable_ne;
	n->markCacheable2 = (markCacheable2_)&markCacheable2_ne;
	n->clearCache = (clearCache_)&clearCache_ne;

	return n;
}
Ejemplo n.º 10
0
variableExpr *createVariableExpr(UCSChar* s, expr *e){
	variableExpr *v = (variableExpr*) malloc(sizeof(variableExpr));
	if (v==NULL){
		throwException2(out_of_mem,"variableExpr allocation failed ");
		return NULL;
	}
	v->freeExpr = (free_Expr)&freeVariableExpr;
	v->evalBoolean = (eval_Boolean)&evalBoolean_ve;
	v->evalNodeSet = (eval_NodeSet)&evalNodeSet_ve;
	v->evalNumber  = (eval_Number)&evalNumber_ve;
	v->evalString  = (eval_String)&evalString_ve;
	v->isNumerical = (is_Numerical)&isNumerical_ve;
	v->isBoolean = (is_Boolean)&isBoolean_ve;
	v->isString =  (is_String)&isString_ve;
	v->isNodeSet = (is_NodeSet)&isNodeSet_ve;
	v->requireContextSize = (require_ContextSize)&requireContextSize_ve;
	v->setContextSize = (set_ContextSize)&setContextSize_ve;
	v->setPosition = (set_Position)&setPosition_ve;
	v->reset = (reset_)&reset_ve;
	v->toString = (to_String)&toString_ve;
	v->adjust= (adjust_)&adjust_ve;
	v->exprName = s;
	v->exprVal = e;
	return v;
}
Ejemplo n.º 11
0
literalExpr *createLiteralExpr(UCSChar *st){
	literalExpr *l = (literalExpr*) malloc(sizeof(literalExpr));
	if (l==NULL){
		throwException2(out_of_mem,"literalExpr allocation failed ");
		return NULL;
	}
	l->freeExpr = (free_Expr)&freeLiteralExpr;
	l->evalBoolean = (eval_Boolean)&evalBoolean_le;
	l->evalNodeSet = (eval_NodeSet)&evalNodeSet_le;
	l->evalNumber  = (eval_Number)&evalNumber_le;
	l->evalString  = (eval_String)&evalString_le;
	l->isNumerical = (is_Numerical)&isNumerical_le;
	l->isBoolean = (is_Boolean)&isBoolean_le;
	l->isString =  (is_String)&isString_le;
	l->isNodeSet = (is_NodeSet)&isNodeSet_le;
	l->requireContextSize = (require_ContextSize)&requireContextSize_le;
	l->setContextSize = (set_ContextSize)&setContextSize_le;
	l->setPosition = (set_Position)&setPosition_le;
	l->reset = (reset_)&reset_le;
	l->toString = (to_String)&toString_le;
	l->adjust= (adjust_)&adjust_le;
	l->s= st;


	return l;

}
Ejemplo n.º 12
0
// add the element to the end of the storage, 
// return the status of add
// 1 if ok, 0 if failed
 int add(ArrayList *al, void *element){
	int t = 0,k=0;
	void **v=NULL;
	if (al->size < al->capacity){
		al->storage[al->size] = element;
		al->size++;
		return al->size;
	}
	else{
		t = al->capacity + AL_GROW_INC;
		v = (void **)malloc(t*sizeof(void *));
		if (v==NULL) {
			throwException2(out_of_mem,
				"ArrayList add failed ");
		} // add failed
	
		
		for (k=0;k<al->size;k++)
		{
               v[k] = al->storage[k]; // copy content
		}
		for (k=al->size;k<al->capacity;k++){
			v[k] = NULL;			// the remaining ones set to NULL
		}
		v[al->size]=element;
		al->capacity = t;
		al->size++;
		free(al->storage);
		al->storage = v;
		return al->size;
	}
}
Ejemplo n.º 13
0
cachedExpr *createCachedExpr(expr *e1){
	cachedExpr *ce = malloc(sizeof(cachedExpr));
	if (ce ==NULL){
		throwException2(out_of_mem,
			"cachedExpr allocation failed");
		return NULL;
	}
	ce->freeExpr = (free_Expr)&freeCachedExpr;
	ce->evalBoolean = (eval_Boolean)&evalBoolean_ce;
	ce->evalNodeSet = (eval_NodeSet)&evalNodeSet_ce;
	ce->evalNumber  = (eval_Number)&evalNumber_ce;
	ce->evalString  = (eval_String)&evalString_ce;
	ce->isNumerical = (is_Numerical)&isNumerical_ce;
	ce->isBoolean = (is_Boolean)&isBoolean_ce;
	ce->isString =  (is_String)&isString_ce;
	ce->isNodeSet = (is_NodeSet)&isNodeSet_ce;
	ce->requireContextSize = (require_ContextSize)&requireContextSize_ce;
	ce->setContextSize = (set_ContextSize)&setContextSize_ce;
	ce->setPosition = (set_Position)&setPosition_ce;
	ce->reset = (reset_)&reset_ce;
	ce->toString = (to_String)&toString_ce;
	ce->adjust = (adjust_)&adjust_ce;
	ce->isFinal = (isFinal_)&isFinal_ce;
	ce->markCacheable = (markCacheable_)&markCacheable_ce;
	ce->markCacheable2 = (markCacheable_)&markCacheable2_ce;
	ce->clearCache = (clearCache_)&clearCache_ce;
	ce->e = e1;
	ce->ens =  NULL;
	ce->cached = FALSE;
	ce->count = 0;
	ce->vn1 = NULL;
	ce->es = NULL;
	return ce;
}
Ejemplo n.º 14
0
UCSChar* evalString_be  (binaryExpr *be,VTDNav *vn){
	double n = 0.0;
	Boolean b = FALSE;
	UCSChar *tmp;
	if(isNumerical_be(be)){
		double d = evalNumber_be(be,vn);
		if (d != d){
			tmp = _wcsdup(L"NaN");
			b= TRUE;
		}
		else if ( d == 1/n){
			tmp = _wcsdup(L"Infinity");
			b = TRUE;
		}
		else if (d == -1/n){
			tmp = _wcsdup(L"-Infinity");
			b  = TRUE;
		}else
		tmp = malloc(sizeof(UCSChar)<<8);

		if (tmp == NULL) {
			throwException2(out_of_mem,
				"string allocation in evalString_be failed ");
		}
		if (b)
			return tmp;
		if (d == (Long) d){
			swprintf(tmp,64,L"%d",(Long) d);
		} else {
			swprintf(tmp,64,L"%f", d);
		}
		return tmp;
	} else {
		Boolean b = evalBoolean_be(be,vn);
		if (b)
			tmp= _wcsdup(L"true");
		else
			tmp= _wcsdup(L"false");
		if (tmp == NULL){
			throwException2(out_of_mem,
				"String allocation failed in evalString_be");
		}
		return tmp;

	}
}
Ejemplo n.º 15
0
 ArrayList *createArrayList2(int initialCapacity){
	 int i;
	ArrayList *al = (ArrayList*) malloc(sizeof(ArrayList));
	if (al==NULL) {
		throwException2(out_of_mem,"ArrayList allocation failed ");
	}
	al->storage = (void **)malloc(initialCapacity * sizeof(void *)); // initial capacity of 10;
	if (al->storage == NULL){
		free(al);		
		throwException2(out_of_mem,
			"ArrayList allocation failed ");
	}

	for (i=0;i<initialCapacity;i++)
		al->storage[i] = NULL;
    al->capacity = initialCapacity;
    al->size = 0;
    return al;
}
Ejemplo n.º 16
0
UCSChar* createEmptyString(){
	UCSChar* es =  malloc(sizeof(UCSChar));
	if (es!=NULL){
		es[0] = 0;
		return es;
	}
	throwException2(out_of_mem,
		"string allocation faild in createEmptyString ");
	return NULL;
}
Ejemplo n.º 17
0
BookMark *createBookMark() {
    BookMark *bm = (BookMark*) malloc(sizeof(BookMark));
    if (bm==NULL) {
        throwException2(out_of_mem,
                        "BookMark allocation failed ");
    }
    bm->ba = NULL;
    bm->ba_len = -1;
    bm->vn1 = NULL;
    return bm;
}
Ejemplo n.º 18
0
int	evalNodeSet_pe (pathExpr *pe,VTDNav *vn){
	int a;
	while (TRUE) {
		switch (pe->evalState) {
		case 0: /*this state is teh initial state;*/
			a = pe->fe->evalNodeSet(pe->fe,vn);
			if (a == -1){
				pe->evalState =4;
			}
			else
				pe->evalState = 1;
			break;
		case 1: /* fe returns valid value, then iterate the locationPath*/
			push2(vn);
			a = evalNodeSet_lpe(pe->lpe, vn);
			if (a == -1) {
				reset_lpe(pe->lpe, vn);
				pe->evalState = 3;
			} else {
				pe->evalState = 2;
				if (isUnique_pe(pe,a))
					return a;
			}
			break;
		case 2:
			a = evalNodeSet_lpe(pe->lpe, vn);
			if (a == -1) {
				reset_lpe(pe->lpe, vn);
				pe->evalState = 3;
			} else{
				if (isUnique_pe(pe, a))
					return a;
				//return a;
			}
			break;
		case 3:
			pop2(vn);
			a = pe->fe->evalNodeSet(pe->fe,vn);
			if (a == -1)
				pe->evalState = 4;
			else{
			    push2(vn);
				pe->evalState = 2;
			}
			break;
		case 4:
			return -1;
		default:
			throwException2(other_exception,
				"Invalid state evaluating PathExpr");
		}
	}
}
Ejemplo n.º 19
0
UCSChar* evalString_ue  (unaryExpr *ue,VTDNav *vn){
	UCSChar *string1 = (ue->e->evalString)(ue->e,vn);
	size_t len = wcslen(string1);
	UCSChar *string = (UCSChar*) malloc((len+1)*sizeof(UCSChar));
	if (string == NULL) {
			throwException2(out_of_mem,
				"allocate string failed in funcExpr's evalString()");
	}

	swprintf(string,64,L"-%ls",string1);

	free(string1);
	return string;
}
Ejemplo n.º 20
0
BookMark *createBookMark2(VTDNav *vn) {
    BookMark *bm = (BookMark*) malloc(sizeof(BookMark));
    if (bm==NULL) {
        throwException2(out_of_mem,
                        "BookMark allocation failed ");
    }
    bm->ba = NULL;
    bm->ba_len = -1;
    bm->vn1 = NULL;

    bind4BookMark(bm,vn);
    recordCursorPosition2(bm);

    return bm;
}
Ejemplo n.º 21
0
binaryExpr *createBinaryExpr(expr *e1, opType op, expr *e2){
	binaryExpr *be = malloc(sizeof(binaryExpr));
	if (be == NULL){
		throwException2(out_of_mem,
			"binaryExpr allocation failed");
		return NULL;
	}
	be->freeExpr = (free_Expr) &freeBinaryExpr;
	be->evalBoolean = (eval_Boolean)&evalBoolean_be;
	be->evalNodeSet = (eval_NodeSet)&evalNodeSet_be;
	be->evalNumber  = (eval_Number)&evalNumber_be;
	be->evalString  = (eval_String)&evalString_be;
	be->isNumerical = (is_Numerical)&isNumerical_be;
	be->isBoolean = (is_Boolean)&isBoolean_be;
	be->isString =  (is_String)&isString_be;
	be->isNodeSet = (is_NodeSet)&isNodeSet_be;
	be->requireContextSize = (require_ContextSize) &requireContextSize_be;
	be->setContextSize = (set_ContextSize)&setContextSize_be;
	be->setPosition = (set_Position)&setPosition_be;
	be->reset = (reset_)&reset_be;
	be->toString = (to_String)&toString_be;
	be->adjust = (adjust_)&adjust_be;
	be->left = e1;
	be->op = op;
	be->right = e2;
	be->fib1 = NULL;
	switch(be->op){
	 	case OP_ADD:
		case OP_SUB:
		case OP_MULT:
		case OP_DIV:
		case OP_MOD: be->isNum = TRUE; be->isBool = FALSE; break;
		case OP_OR :
		case OP_AND:
		case OP_EQ:
		case OP_NE:
		case OP_LE:
		case OP_GE:
		case OP_LT:
		default: be->isNum= FALSE; be->isBool = TRUE;
	}
	return be;
}
Ejemplo n.º 22
0
pathExpr *createPathExpr(expr *f, locationPathExpr *l){
	exception e;
	pathExpr *pe = (pathExpr *)malloc(sizeof(pathExpr));
	if (pe==NULL){
		throwException2(out_of_mem,
			"pathExpr allocation failed ");
		return NULL;
	}
	Try{
		pe->ih = createIntHash();
	}
	Catch(e){
		free(pe);
		Throw e;
	}

	pe->freeExpr = (free_Expr) &freePathExpr;
	pe->evalBoolean = (eval_Boolean)&evalBoolean_pe;
	pe->evalNodeSet = (eval_NodeSet)&evalNodeSet_pe;
	pe->evalNumber  = (eval_Number)&evalNumber_pe;
	pe->evalString  = (eval_String)&evalString_pe;
	pe->isNumerical =  (is_Numerical)&isNumerical_pe;
	pe->isBoolean = (is_Boolean)&isBoolean_pe;
	pe->isString =  (is_String)&isString_pe;
	pe->isNodeSet = (is_NodeSet)&isNodeSet_pe;
	pe->requireContextSize = (require_ContextSize)&requireContextSize_pe;
	pe->setContextSize = (set_ContextSize)&setContextSize_pe;
	pe->setPosition = (set_Position)&setPosition_pe;
	pe->reset = (reset_)&reset_pe;
	pe->toString = (to_String)&toString_pe;
	pe->adjust = (adjust_)&adjust_pe;
	pe->fe = f;
	pe->lpe= l;
	pe->evalState = 0;

	return pe;

}
Ejemplo n.º 23
0
int	evalNodeSet_ne (numberExpr *ne,VTDNav *vn){
	throwException2(xpath_eval_exception,
		"numberExpr can't eval to a node set!");
	return -1;
}
Ejemplo n.º 24
0
int	evalNodeSet_ue (unaryExpr *ue,VTDNav *vn){
	throwException2(xpath_eval_exception,
		"unaryExpr can't eval to a node set!");
	return -1;
}
Ejemplo n.º 25
0
int	evalNodeSet_le (literalExpr *le,VTDNav *vn){
	throwException2(xpath_eval_exception,
		"LiteralExpr can't eval to a node set!");
	return -1;
}
Ejemplo n.º 26
0
int	evalNodeSet_be (binaryExpr *be,VTDNav *vn){
	throwException2(xpath_eval_exception,
		"can't evaluate nodeset on a binary expr");
	return -1;
}