00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00035 #include "role.h"
00036 #include "pathexpression.h"
00037 #include "signoffexpression.h"
00038
00039 Role::Role(unsigned _id, ROLE_TYPE _type, unsigned _basing_var,
00040 unsigned _basing_fsa, PathExpression * _rel_path,
00041 PathExpression * _var_path):id(_id),
00042 type(_type),
00043 basing_var(_basing_var),
00044 basing_fsa(_basing_fsa),
00045 rel_path(_rel_path),
00046 var_path(_var_path) {
00047
00048 var_path = var_path ? var_path->clone() : NULL;
00049
00050 concat_path = rel_path ? rel_path->clone() : new PathExpression();
00051 if (var_path) {
00052 vector < PathStepExpression * >*ps = var_path->getPathSteps();
00053 for (unsigned i = 0; i < ps->size(); i++) {
00054 concat_path->addPathStep((*ps)[i]->clone());
00055 }
00056 }
00057 }
00058
00059 Role::~Role() {
00060 delete rel_path;
00061 delete var_path;
00062 delete concat_path;
00063 }
00064
00065 void Role::print(OutputStream & dos) const {
00066 dos << "r" << id;
00067 }
00068
00069 void Role::printExtended(OutputStream & dos) {
00070 dos << "role=r" << id << ", base_var=$"
00071 << VarName::getInstance()->getVarname(basing_var) << ", base_fsa=$"
00072 << VarName::getInstance()->getVarname(basing_fsa);
00073 (rel_path == NULL || rel_path->isEmptyPath())?
00074 dos << ", rel_path=%" : dos << ", rel_path=" << *(rel_path);
00075 (var_path == NULL || var_path->isEmptyPath())?
00076 dos << ", var_path=%" : dos << ", var_path=" << *(var_path);
00077 }
00078
00079 SignOffExpression *Role::getSignOffExpression() {
00080
00081 if (concat_path && !concat_path->isEmptyPath()) {
00082 return new SignOffExpression(new
00083 VarStepExpression(basing_fsa,
00084 concat_path->clone()),
00085 this);
00086 } else {
00087 VarExpression *var = new VarExpression();
00088
00089 var->setId(basing_fsa);
00090 return new SignOffExpression((VarExpression *) var, this);
00091 }
00092 }
00093
00094 bool Role::isPosRole() {
00095 return var_path && var_path->getTailPathStep()->hasAttribute()
00096 && var_path->getTailPathStep()->getAttribute()->getType() ==
00097 at_position;
00098 }
00099
00100 bool Role::isDosRole() {
00101 return var_path && !var_path->isEmptyPath()
00102 && var_path->getTailPathStep()->isDosNodeStep();
00103 }