Esempio n. 1
0
int DaoClass_GetData( DaoClass *self, DString *name, DaoValue **value, DaoClass *thisClass )
{
	DaoValue *p = NULL;
	DNode *node = MAP_Find( self->lookupTable, name );
	int child = thisClass && DaoClass_ChildOf( thisClass, (DaoValue*)self );
	int sto, perm, up, id;

	*value = NULL;
	if( ! node ) return DAO_ERROR_FIELD_NOTEXIST;
	perm = LOOKUP_PM( node->value.pInt );
	sto = LOOKUP_ST( node->value.pInt );
	up = LOOKUP_UP( node->value.pInt );
	id = LOOKUP_ID( node->value.pInt );
	if( self == thisClass || perm == DAO_DATA_PUBLIC || (child && perm >= DAO_DATA_PROTECTED) ){
		switch( sto ){
		case DAO_CLASS_VARIABLE : p = self->variables->items.pVar[id]->value; break;
		case DAO_CLASS_CONSTANT : p = self->constants->items.pConst[id]->value; break;
		default : return DAO_ERROR_FIELD;
		}
		if( p ) *value = p;
	}else{
		return DAO_ERROR_FIELD_NOTPERMIT;
	}
	return 0;
}
Esempio n. 2
0
int DaoClass_ChildOf( DaoClass *self, DaoValue *klass )
{
	DaoCdata *cdata = (DaoCdata*) klass;
	if( self == NULL || klass == NULL ) return 0;
	if( klass == (DaoValue*) self ) return 1;
	if( klass == self->parent ) return 1;
	if( self->parent == NULL ) return 0;
	if( self->parent->type == DAO_CLASS ){
		return DaoClass_ChildOf( (DaoClass*) self->parent, klass );
	}else if( self->parent->type == DAO_CTYPE && klass->type == DAO_CTYPE ){
		DaoCdata *csup = (DaoCdata*) self->parent;
		return DaoCdata_ChildOf( csup->ctype->kernel->typer, cdata->ctype->kernel->typer );
	}
	return 0;
}
Esempio n. 3
0
int  DaoClass_ChildOf( DaoClass *self, DaoValue *klass )
{
	DaoCdata *cdata = (DaoCdata*) klass;
	int i;
	if( self == NULL ) return 0;
	if( klass == (DaoValue*) self ) return 1;
	for( i=0; i<self->superClass->size; i++ ){
		DaoClass *dsup = self->superClass->items.pClass[i];
		DaoCdata *csup = self->superClass->items.pCdata[i];
		if( dsup == NULL ) continue;
		if( klass == self->superClass->items.pValue[i] ) return 1;
		if( dsup->type == DAO_CLASS && DaoClass_ChildOf( dsup,  klass ) ){
			return 1;
		}else if( csup->type == DAO_CTYPE && klass->type == DAO_CTYPE ){
			if( DaoCdata_ChildOf( csup->ctype->kernel->typer, cdata->ctype->kernel->typer ) )
				return 1;
		}
	}
	return 0;
}