![]() |
libsesstype
2.0.0
Library for Session Types programming.
|
00001 00006 #ifndef SESSTYPE__PARAMETERISED__SESSION_H__ 00007 #define SESSTYPE__PARAMETERISED__SESSION_H__ 00008 00009 #ifdef __cplusplus 00010 #include <string> 00011 #include <unordered_map> 00012 #endif 00013 00014 #include "sesstype/session.h" 00015 00016 #include "sesstype/parameterised/node.h" 00017 #include "sesstype/parameterised/role.h" 00018 #include "sesstype/parameterised/role_grp.h" 00019 00020 #ifdef __cplusplus 00021 namespace sesstype { 00022 namespace parameterised { 00023 #endif 00024 00025 #ifdef __cplusplus 00026 00029 template <class NodeType, class RoleType, class RoleGrpType> 00030 class SessionTmpl : public sesstype::SessionTmpl<NodeType, RoleType> { 00031 std::unordered_map<std::string, RoleGrpType *> groups_; 00032 00033 public: 00034 using RoleGrpContainer = std::unordered_map<std::string, RoleGrpType *>; 00036 SessionTmpl() : sesstype::SessionTmpl<NodeType, RoleType>(), groups_() { } 00037 00040 SessionTmpl(std::string name) 00041 : sesstype::SessionTmpl<NodeType, RoleType>(name), groups_() { } 00042 00044 virtual ~SessionTmpl() 00045 { 00046 for (auto grp_pair : groups_) { 00047 delete grp_pair.second; 00048 } 00049 } 00050 00054 RoleGrpType *group(std::string name) const 00055 { 00056 return groups_.at(name); 00057 } 00058 00061 bool has_role_grp(std::string name) const 00062 { 00063 return (groups_.find(name) != groups_.end()); 00064 } 00065 00068 void add_group(RoleGrpType *group) 00069 { 00070 groups_.insert(std::pair<std::string, RoleGrpType *>(group->name(), group)); 00071 } 00072 00073 unsigned int num_groups() const 00074 { 00075 return groups_.size(); 00076 } 00077 00078 typename RoleGrpContainer::const_iterator rolegrp_begin() const 00079 { 00080 return groups_.begin(); 00081 } 00082 00083 typename RoleGrpContainer::const_iterator rolegrp_end() const 00084 { 00085 return groups_.end(); 00086 } 00087 }; 00088 00089 using Session = SessionTmpl<Node, Role, RoleGrp>; 00090 #endif 00091 00092 #ifdef __cplusplus 00093 extern "C" { 00094 #endif 00095 00096 #ifdef __cplusplus 00097 typedef Session st_param_tree; 00098 #else 00099 typedef struct Session st_param_tree; 00100 #endif 00101 00104 st_param_tree *st_param_tree_mk_init(const char *name); 00105 00109 st_param_tree *st_param_tree_add_role(st_param_tree *const tree, st_role *role); 00110 00114 st_param_tree *st_param_tree_set_root(st_param_tree *const tree, st_node *root); 00115 00118 st_param_node *st_param_tree_get_root(st_param_tree *const tree); 00119 00120 st_param_tree *st_param_tree_add_role_grp(st_param_tree *tree, st_role_grp *grp); 00121 00122 bool st_param_tree_has_role_grp(st_param_tree *const tree, const char *grp_name); 00123 00124 void st_param_tree_print(st_param_tree *const tree); 00125 00126 st_role_grp *st_param_tree_get_role_grp(st_param_tree *const tree, const char *grp_name); 00127 00129 void st_param_tree_free(st_param_tree *tree); 00130 00131 #ifdef __cplusplus 00132 } // extern "C" 00133 #endif 00134 00135 #ifdef __cplusplus 00136 } // namespace parameterised 00137 } // namespace sesstype 00138 #endif 00139 00140 #endif//SESSTYPE__PARAMETERISED__SESSION_H__