int DaoObject_GetData( DaoObject *self, DString *name, DaoValue **data, DaoObject *othis ) { DNode *node; DaoValue *p = NULL; DaoClass *klass = self->defClass; DaoObject *null = & klass->objType->value->xObject; int child = othis && DaoObject_ChildOf( (DaoValue*)othis, (DaoValue*)self ); int id, st, up, pm, access; *data = NULL; node = DMap_Find( self->defClass->lookupTable, name ); if( node == NULL ) return DAO_ERROR_FIELD_NOTEXIST; pm = LOOKUP_PM( node->value.pInt ); st = LOOKUP_ST( node->value.pInt ); up = LOOKUP_UP( node->value.pInt ); id = LOOKUP_ID( node->value.pInt ); if( self == null && st == DAO_OBJECT_VARIABLE ) return DAO_ERROR_FIELD_NOTPERMIT; access = othis == self || pm == DAO_PERM_PUBLIC || (child && pm >= DAO_PERM_PROTECTED); if( access == 0 ) return DAO_ERROR_FIELD_NOTPERMIT; switch( st ){ case DAO_OBJECT_VARIABLE : p = self->objValues[id]; break; case DAO_CLASS_VARIABLE : p = klass->variables->items.pVar[id]->value; break; case DAO_CLASS_CONSTANT : p = klass->constants->items.pConst[id]->value; break; default : break; } *data = p; return 0; }
int DaoObject_ChildOf( DaoValue *self, DaoValue *obj ) { int i; if( obj == self ) return 1; if( self->type == DAO_CDATA || self->type == DAO_CSTRUCT ){ if( obj->type == DAO_CDATA || obj->type == DAO_CSTRUCT ){ DaoCstruct *cdata1 = (DaoCstruct*) self; DaoCstruct *cdata2 = (DaoCstruct*) obj; if( DaoType_ChildOf( cdata1->ctype, cdata2->ctype ) ) return 1; } return 0; } if( self->type != DAO_OBJECT || self->xObject.parent == NULL ) return 0; if( obj == self->xObject.parent ) return 1; if( DaoObject_ChildOf( self->xObject.parent, obj ) ) return 1; return 0; }
int DaoObject_ChildOf( DaoObject *self, DaoValue *obj ) { if( obj == (DaoValue*) self ) return 1; #if 0 // No way to determine inheritance relationship between wrapped C++ objects; if( self->type >= DAO_CSTRUCT && self->type <= DAO_CDATA ){ if( obj->type >= DAO_CSTRUCT && obj->type <= DAO_CDATA ){ DaoCstruct *cdata1 = (DaoCstruct*) self; DaoCstruct *cdata2 = (DaoCstruct*) obj; if( DaoType_ChildOf( cdata1->ctype, cdata2->ctype ) ) return 1; } return 0; } #endif if( self->parent == NULL ) return 0; if( self->parent == obj ) return 1; if( self->parent->type != DAO_OBJECT ) return 0; return DaoObject_ChildOf( (DaoObject*) self->parent, obj ); }
int DaoObject_SetData( DaoObject *self, DString *name, DaoValue *data, DaoObject *othis ) { DNode *node; DaoType *type; DaoValue **value ; DaoClass *klass = self->defClass; DaoObject *null = & klass->objType->value->xObject; int child = othis && DaoObject_ChildOf( (DaoValue*)othis, (DaoValue*)self ); int id, st, up, pm, access; if( self == (DaoObject*)self->defClass->objType->value ) return DAO_ERROR; node = DMap_Find( self->defClass->lookupTable, name ); if( node == NULL ) return DAO_ERROR_FIELD_NOTEXIST; pm = LOOKUP_PM( node->value.pInt ); st = LOOKUP_ST( node->value.pInt ); up = LOOKUP_UP( node->value.pInt ); id = LOOKUP_ID( node->value.pInt ); if( self == null && st == DAO_OBJECT_VARIABLE ) return DAO_ERROR_FIELD_NOTPERMIT; access = othis == self || pm == DAO_PERM_PUBLIC || (child && pm >= DAO_PERM_PROTECTED); if( access == 0 ) return DAO_ERROR_FIELD_NOTPERMIT; if( st == DAO_OBJECT_VARIABLE ){ if( id <0 ) return DAO_ERROR_FIELD_NOTPERMIT; type = klass->instvars->items.pVar[ id ]->dtype; value = self->objValues + id; if( DaoValue_Move( data, value, type ) ==0 ) return DAO_ERROR_VALUE; }else if( st == DAO_CLASS_VARIABLE ){ DaoVariable *var = klass->variables->items.pVar[id]; if( DaoValue_Move( data, & var->value, var->dtype ) ==0 ) return DAO_ERROR_VALUE; }else if( st == DAO_CLASS_CONSTANT ){ return DAO_ERROR_FIELD; }else{ return DAO_ERROR_FIELD; } return 0; }