![]() |
libsesstype
2.0.0
Library for Session Types programming.
|
00001 00005 #ifndef SESSTYPE__PARAMETERISED__ROLE_H__ 00006 #define SESSTYPE__PARAMETERISED__ROLE_H__ 00007 00008 #include "sesstype/role.h" 00009 00010 #include "sesstype/parameterised/expr.h" 00011 #include "sesstype/parameterised/expr/rng.h" 00012 00013 #ifdef __cplusplus 00014 namespace sesstype { 00015 namespace parameterised { 00016 namespace util { 00017 class RoleVisitor; 00018 } // namespace util 00019 } // namespace sesstype 00020 } // namespace sesstype 00021 #endif 00022 00023 #ifdef __cplusplus 00024 namespace sesstype { 00025 namespace parameterised { 00026 #endif 00027 00028 #ifdef __cplusplus 00029 00032 class Role : public sesstype::Role { 00033 std::vector<Expr *> param_; 00034 00035 public: 00037 Role() : sesstype::Role(), param_() { } 00038 00040 Role(std::string name) : sesstype::Role(name), param_() { } 00041 00043 Role(const Role &role) : sesstype::Role(role), param_() 00044 { 00045 for (auto param : role.param_) { 00046 param_.push_back(param->clone()); 00047 } 00048 } 00049 00051 ~Role() override 00052 { 00053 for (auto param : param_) { 00054 delete param; 00055 } 00056 } 00057 00059 Role *clone() const override 00060 { 00061 return new Role(*this); 00062 } 00063 00065 unsigned int num_dimens() const 00066 { 00067 return param_.size(); 00068 } 00069 00071 void add_param(Expr *param) 00072 { 00073 param_.push_back(param); 00074 } 00075 00079 Expr *operator[](std::size_t idx) const 00080 { 00081 return param_.at(idx); 00082 } 00083 00086 virtual bool matches(sesstype::Role *other) const 00087 { 00088 bool matching = true; 00089 if (auto other_param = dynamic_cast<Role *>(other)) { 00090 // 0. Check if current role is endpoint role (both dimen=0) 00091 // 1. Check if current role is a member of endpoint role (both dimen>0) 00092 // current role is NOT multi and endpoint role is multi 00093 // 2. Check if current role is subset of endpoint role (both dimen>0) 00094 // Note: endpoint role is always the full set (multi) 00095 // So if name matches this is always a subset (multi) 00096 matching &= (name() == other_param->name()); // Name matches 00097 matching &= (num_dimens() == other_param->num_dimens()); // Dimen 00098 return matching; 00099 } 00100 return false; 00101 } 00102 00104 virtual void accept(util::RoleVisitor &v); 00105 00106 friend std::ostream &operator<<(std::ostream &os, Role &role); 00107 00108 private: 00109 virtual void accept(sesstype::util::RoleVisitor &v) override { /* hidden */ } 00110 }; 00111 #endif // __cplusplus 00112 00113 #ifdef __cplusplus 00114 extern "C" { 00115 #endif 00116 00117 #ifdef __cplusplus 00118 typedef Role st_param_role; 00119 #else 00120 typedef struct Role st_param_role; 00121 #endif 00122 00126 unsigned int st_role_num_dimen(st_param_role *const role); 00127 00131 st_expr *st_role_get_param(st_param_role *const role, unsigned int idx); 00132 00137 st_param_role *st_role_add_param(st_param_role *const role, st_expr *param); 00138 00139 void st_param_role_free(st_param_role *role); 00140 00141 #ifdef __cplusplus 00142 } // extern "C" 00143 #endif 00144 00145 #ifdef __cplusplus 00146 } // namespace parameterised 00147 } // namespace sesstype 00148 #endif 00149 00150 #endif//SESSTYPE__PARAMETERISED__ROLE_H__