libsesstype  2.0.0
Library for Session Types programming.
role_grp.h
Go to the documentation of this file.
00001 
00005 #ifndef SESSTYPE__PARAMETERISED__ROLE_GRP_H__
00006 #define SESSTYPE__PARAMETERISED__ROLE_GRP_H__
00007 
00008 #ifdef __cplusplus
00009 #include <string>
00010 #include <vector>
00011 #endif
00012 
00013 #include "sesstype/parameterised/role.h"
00014 
00015 #ifdef __cplusplus
00016 namespace sesstype {
00017 namespace parameterised {
00018 #endif
00019 
00020 #ifdef __cplusplus
00021 
00024 class RoleGrp : public Role {
00025     std::vector<sesstype::parameterised::Role *> members_;
00026 
00027   public:
00028     typedef std::vector<sesstype::parameterised::Role *> RoleContainer;
00029 
00031     RoleGrp() : Role("default_grp"), members_() { }
00032 
00034     RoleGrp(std::string name) : Role(name), members_() { }
00035 
00037     RoleGrp(const RoleGrp &role) : Role(role), members_(role.members_)
00038     {
00039         // We don't explicitly copy members
00040         // --> because this is a shallow copy (of ptr)
00041     }
00042 
00046     ~RoleGrp() override { }
00047 
00049     RoleGrp *clone() const override
00050     {
00051         return new RoleGrp(*this);
00052     }
00053 
00057     sesstype::Role *member(unsigned int index) const
00058     {
00059         return members_.at(index);
00060     }
00061 
00063     unsigned int num_members() const
00064     {
00065         return members_.size();
00066     }
00067 
00069     void add_member(Role *role)
00070     {
00071         members_.push_back(role);
00072     }
00073 
00076     bool matches(sesstype::Role *other) const override
00077     {
00078         if (auto other_param = dynamic_cast<Role *>(other)) {
00079             for (auto it=member_begin(); it!=member_end(); it++) {
00080                 if (!(*it)->matches(other_param)) return false;
00081             }
00082             return true;
00083         }
00084         return false;
00085     }
00086 
00088     RoleContainer::const_iterator member_begin() const
00089     {
00090         return members_.begin();
00091     }
00092 
00094     RoleContainer::const_iterator member_end() const
00095     {
00096         return members_.end();
00097     }
00098 
00099     virtual void accept(util::RoleVisitor &v) override;
00100 };
00101 #endif
00102 
00103 #ifdef __cplusplus
00104 extern "C" {
00105 #endif
00106 
00107 #ifdef __cplusplus
00108 typedef RoleGrp st_role_grp;
00109 #else
00110 typedef struct RoleGrp st_role_grp;
00111 #endif
00112 
00113 st_role_grp *st_role_grp_init(const char *name);
00114 
00115 const char *st_role_grp_name(const st_role_grp * const role_grp);
00116 st_role_grp *st_role_grp_set_name(st_role_grp * const role_grp, const char *name);
00117 
00118 void st_role_grp_add_member(st_param_role *role);
00119 unsigned int st_role_grp_num_member(const st_role_grp * const role_grp);
00120 void st_role_grp_free(st_role_grp *role_grp);
00121 
00122 #ifdef __cplusplus
00123 }; // extern "C"
00124 #endif
00125 
00126 #ifdef __cplusplus
00127 } // namespace parameterised
00128 } // namespace sesstype
00129 #endif
00130 
00131 #endif//SESSTYPE__PARAMETERISED__ROLE_GRP_H__
 All Classes Namespaces Files Functions