Westerland
Gebruiker
- Lid geworden
- 27 jun 2011
- Berichten
- 286
Goedenavond,
Ik ben voor het eerst in mijn "programmeer carriere" beland bij een methode waarin ik het nut van een goto label; in zie alleen is mijn vraag nu, zou ik dat wel doen ? aangezien ik nog nooit echt een goed verhaal gehoord heb over het gebruik van goto's (enkel bij c, aldus google).
Het scenario:
[cpp]
MStatus RoomCommand::CreateObject(SquareObject *objectInstance, unsigned short objectCreated)
{
MStatus status;
MString name = (objectCreated == 1) ? "RoomObject" : "FieldOfInterest";
if (objectCreated == 1)
{
RoomObject *roomObjectInstance = (RoomObject*)objectInstance;
if (roomObjectInstance->isMultiLevel())
{
//when the room has multiple levels, create a subdevision on the y axis
status = MelCommandHelper::CreateCube(name,&dgMod,roomObjectInstance->getDimensions(),roomObjectInstance->getAmountOfLevels());
MCHECKERROR(status,"RoomCommand::CreateFieldOfInterest -> error executing mel object creation (roomobject multilevel)");
goto CREATED;
}
}
//from here onwards, the object creation is the same, the only diffference is the name and the size.
//if the object is multilevel, the object creation is already done
status = MelCommandHelper::CreateCube(name,&dgMod,objectInstance->getDimensions());
MCHECKERROR(status,MString("RoomCommand::CreateObject -> error executing mel object creation of object ") + name);
CREATED:
status = SetVertices(objectInstance, objectCreated);
MCHECKERROR(status,MString("RoomCommand::CreateObject -> error getting the vertices of object ") + name);
status = MelCommandHelper::Translate(name, &dgMod,objectInstance->getDimensions(),objectInstance->getLocation());
MCHECKERROR(status,MString("RoomCommand::CreateObject -> object translation failed of object ") + name);
return status;
}
[/cpp]
Nu kan ik het ook oplossen door te boolean flaggen, alleen wordt dit er niet echt netter op. Mijn vraag is dus, is dit daadwerkelijk een zeer uniek scenario waar goto wel goed toe te passen is of heb ik de methode gewoon verkeerd ontworpen (kan natuurlijk ook anders).
Ik ben voor het eerst in mijn "programmeer carriere" beland bij een methode waarin ik het nut van een goto label; in zie alleen is mijn vraag nu, zou ik dat wel doen ? aangezien ik nog nooit echt een goed verhaal gehoord heb over het gebruik van goto's (enkel bij c, aldus google).
Het scenario:
[cpp]
MStatus RoomCommand::CreateObject(SquareObject *objectInstance, unsigned short objectCreated)
{
MStatus status;
MString name = (objectCreated == 1) ? "RoomObject" : "FieldOfInterest";
if (objectCreated == 1)
{
RoomObject *roomObjectInstance = (RoomObject*)objectInstance;
if (roomObjectInstance->isMultiLevel())
{
//when the room has multiple levels, create a subdevision on the y axis
status = MelCommandHelper::CreateCube(name,&dgMod,roomObjectInstance->getDimensions(),roomObjectInstance->getAmountOfLevels());
MCHECKERROR(status,"RoomCommand::CreateFieldOfInterest -> error executing mel object creation (roomobject multilevel)");
goto CREATED;
}
}
//from here onwards, the object creation is the same, the only diffference is the name and the size.
//if the object is multilevel, the object creation is already done
status = MelCommandHelper::CreateCube(name,&dgMod,objectInstance->getDimensions());
MCHECKERROR(status,MString("RoomCommand::CreateObject -> error executing mel object creation of object ") + name);
CREATED:
status = SetVertices(objectInstance, objectCreated);
MCHECKERROR(status,MString("RoomCommand::CreateObject -> error getting the vertices of object ") + name);
status = MelCommandHelper::Translate(name, &dgMod,objectInstance->getDimensions(),objectInstance->getLocation());
MCHECKERROR(status,MString("RoomCommand::CreateObject -> object translation failed of object ") + name);
return status;
}
[/cpp]
Nu kan ik het ook oplossen door te boolean flaggen, alleen wordt dit er niet echt netter op. Mijn vraag is dus, is dit daadwerkelijk een zeer uniek scenario waar goto wel goed toe te passen is of heb ik de methode gewoon verkeerd ontworpen (kan natuurlijk ook anders).