查看单个帖子
旧 2009-05-05, 09:30 AM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】entity type

entity type
entity type
is there an a better way to find the entity type without using a string compare?
odstring entitytype;
entitytype = pent->isa()->name();
if (0 == stricmp(entitytype, "acdbline"))
{
}
else if (0 == stricmp(entitytype, "acdbarc"))
{
}
...
in the old libraries you could use a switch statement:
switch (adenhd->enttype)
{
case ad_ent_line:
break;
case ad_ent_arc:
break;
...
}
you can also use iskindof(), isderivedfrom() methods.
but the most efficient way to replace old style "switch" statement is using protocol extensions (see odreadex sample).
sergey slezkin
can the desc() method help in this way (because sometimes on simple lines of code the protocol extensions can be more difficult to implement).
i.e.:
switch(pent->isa()) {
case(oddbline::desc()) : {}
case(oddbarc::desc()) : {}
}
regards
chudomir
is this correct? the case statements need to be constant expressions. how do you resolve this?
case (oddbline::desc()): {}
yes - use if else
if( f ( obj->iskindof(oddbmtext::desc()) ) {
...
} else if ( obj->iskindof(oddbfcf::desc()) )
...
} else if ( obj->iskindof(oddbblockreference::desc()) )
...
} else if ( obj->iskindof(oddbleader::desc()) )
...
} else if ( obj->iskindof(oddbarc::desc()) )
ect...
thank you
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)