[gme-users] Enum problem in interpreters

Zoltan Molnar zolmol at isis.vanderbilt.edu
Thu May 26 11:54:48 CDT 2005


Supposed we have a model kind called "MyModel" which has an Enumattribute called "MyEnumattribute"
The code below (generated by BonX interpreter) illustrates how it works the attribute set/get method.

//********************************************************************************
MyModelImpl::MyEnumAttribute_Type MyModelImpl::getMyEnumAttribute()
{
	std::string val = FCOImpl::getAttribute("MyEnumAttribute")->getStringValue();

	if ( val == "first_val") return first_val_MyEnumAttribute_Type;
	else if ( val == "second_val") return second_val_MyEnumAttribute_Type;
	else if ( val == "third_val") return third_val_MyEnumAttribute_Type;
	else throw("None of the possible items");
}

//********************************************************************************
void MyModelImpl::setMyEnumAttribute( MyModelImpl::MyEnumAttribute_Type val)
{
	std::string str_val = "";

	if ( val == first_val_MyEnumAttribute_Type) str_val = "first_val";
	else if ( val == second_val_MyEnumAttribute_Type) str_val = "second_val";
	else if ( val == third_val_MyEnumAttribute_Type) str_val = "third_val";
	else throw("None of the possible items");

	FCOImpl::getAttribute("MyEnumAttribute")->setStringValue( str_val);
}

These methods can be used like this:

enumos_BON::MyModelImpl::MyEnumAttribute_Type e = m->getMyEnumAttribute();

if( e == enumos_BON::MyModelImpl::first_val_MyEnumAttribute_Type)
{
	m->setMyEnumAttribute(enumos_BON::MyModelImpl::second_val_MyEnumAttribute_Type);
}
else if( e == enumos_BON::MyModelImpl::second_val_MyEnumAttribute_Type)
{
	m->setMyEnumAttribute(enumos_BON::MyModelImpl::first_val_MyEnumAttribute_Type);
}

This code changes the enum values from first to second, and from second to first.


To show the whole picture I paste below the BonX generated class declaration:

namespace enumos_BON
{
DECLARE_BONEXTENSION( BON::Model, MyModelImpl, MyModel );

//*******************************************************************
//   C  L  A  S  S   MyModelImpl
//*******************************************************************
class MyModelImpl :
	  virtual public BON::ModelImpl
{
public:
	typedef enum
	{
		first_val_MyEnumAttribute_Type,
		second_val_MyEnumAttribute_Type,
		third_val_MyEnumAttribute_Type
	} MyEnumAttribute_Type;

	//
	// attribute getters and setters
	virtual MyModelImpl::MyEnumAttribute_Type   getMyEnumAttribute();
	virtual void        setMyEnumAttribute( MyModelImpl::MyEnumAttribute_Type val);
};


Hth,
Zoli

> -----Original Message-----
> From: gme-users-bounces at list.isis.vanderbilt.edu 
> [mailto:gme-users-bounces at list.isis.vanderbilt.edu] On Behalf 
> Of Gábor Bátori (IJ/ETH)
> Sent: Thursday, May 26, 2005 3:01 AM
> To: gme-users
> Subject: [gme-users] Enum problem in interpreters
> 
> 
> Hello,
> 
> I have some problem about handling enum attributes in 
> interpreters in BON2. I need to compare the value of the enum 
> attribute but I cannot know how to do this. Another problem 
> is how to get the string value of an enum attribute.
> 
> Thanks,
> 
> Gabor
> _______________________________________________
> gme-users mailing list
> gme-users at list.isis.vanderbilt.edu
> http://list.isis.vanderbilt.edu/mailman/listinfo/gme-users
> 


More information about the gme-users mailing list