Dynamic View Services > Specifying Dynamic View Types > User-Defined Representation Attributes Types > Declaring and Implementing the Identity Type
 
Declaring and Implementing the Identity Type
The Identity class is declared as follows:
class Identity: public IlsMvUserType
{
public:
Identity(IlsString surname,IlsString firstName)
:_surname(surname),_firstName(firstName) {}
private:
IlsString _surname;
IlsString _firstName;
 
ILS_USERTYPE_DECL(Identity,IlsMvUserType)
};
The source file for the class Identity must include the following macro:
ILS_USERTYPE_DEF(Identity,IlsMvUserType)
and implement the following functions:
IlsMvMessage& Identity::ilsEncode(IlsMvMessage& msg) const
{
return msg << _surname << _firstName;
}
IlsMvUserType*
Identity::IlsDecode(IlsMvMessage& msg) const
{
IlsString surname;
IlsString firstName;
 
msg >> surname >> firstName;
return new Identity(surname,firstName);
}
 
Identity::Identity(const IlsMvValue& v)
{
IlsMvUserType* u=v;
if (u){
Identity* id=Identity::Narrow(*u);
if (id){
_surname=id->_surname;
_firstName=d->_firstName;
}
}
}
Note that the function Identity::Narrow is a safe downcast function declared by the macro ILS_USERTYPE_DECL and implemented in the macro ILS_USERTYPE_DEF.
When a client first opens a view on a server, the server sends the description of the model back to the client, including the default value for all the attributes of the model. If no default value has been defined for attributes whose type is user-defined, Rogue Wave® Server tries to get one from an empty IlsMvValue by calling the following contructor:
Identity::Identity(const IlsMvValue& v)
with an IlsMvValue whose kind is MV_VOID.
Therefore, you should implement this constructor so that it accept sthis kind of value.
if (v.isVoid()) {
// do nothing
return;
}

Version 5.8
Copyright © 2014, Rogue Wave Software, Inc. All Rights Reserved.