Modeling Services > Rogue Wave Script Integration > Using User-Defined Types in a Script
 
Using User-Defined Types in a Script
A dynamic method can have a signature that references a user-defined type (or user type), that is, an instance of IlsMvUserType. In this case, its script implementation will receive a string value and the user type will be converted to a string. If the return type of the dynamic method is a user type, the return value will be built from a string returned by the script function.
A script function can access or assign an attribute whose type is a user type. This user type will be considered as a string in the script function. To be manipulated by script functions, the user type must implement:
*a constructor that receives an IlsMvValue of type string as its argument: this constructor must initialize the user type from the string received as an argument.
*the virtual member function IlsMvUserType::asString.
Example
Date::Date(const IlsMvValue& v)
: _hour(0),_mn(0),_sec(0)
{
IlsMvUserType* u=v;
if (u){
Date* d=Date::Narrow(*u);
if (d){
_hour=d->_hour;
_mn=d->_mn;
_sec=d->_sec;
}
} else {
if (v.isString()) {
// build the value from a string with format: "mm/dd/yyyy hh:mn:ss ms"
int mm=0; int dd=0, yy=0, hh=0, mn=0, ss=0, ms=0;
const char* buffer = (const char*)v.asString();
try {
sscanf(buffer, "%d/%d/%d %d:%d:%d %d", &mm, &dd,
&yy, &hh, &mn, &ss, &ms);
} catch(...) {
// date cannot be parsed
IlsError() << "Cannot create date from string "
<< buffer << IlsEOM;
}
_hour = hh;
_mn = mn;
_sec = ss;
}
}
}

Version 6.3
Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.