libsesstype  2.0.0
Library for Session Types programming.
interaction.h
00001 #ifndef SESSTYPE__NODE__INTERACTION_H__
00002 #define SESSTYPE__NODE__INTERACTION_H__
00003 
00004 #ifdef __cplusplus
00005 #include <vector>
00006 #endif
00007 
00008 #include "sesstype/msg.h"
00009 #include "sesstype/node.h"
00010 #include "sesstype/role.h"
00011 
00012 #ifdef __cplusplus
00013 namespace sesstype {
00014 #endif
00015 
00016 #ifdef __cplusplus
00017 
00022 template <class BaseNode, class RoleType, class MessageType, class VisitorType>
00023 class InteractionNodeTmpl : public BaseNode {
00024     MessageType *msg_;
00025     RoleType *sndr_;
00026     std::vector<RoleType *> rcvrs_;
00027 
00028   public:
00029     typedef typename std::vector<RoleType *> RoleContainer;
00030 
00032     InteractionNodeTmpl() : BaseNode(ST_NODE_SENDRECV),
00033                             msg_(new MessageType("")),
00034                             sndr_(nullptr), rcvrs_() { }
00035 
00038     InteractionNodeTmpl(MessageType *msg) : BaseNode(ST_NODE_SENDRECV),
00039                                             msg_(msg->clone()),
00040                                             sndr_(nullptr), rcvrs_() { }
00041 
00043     InteractionNodeTmpl(const InteractionNodeTmpl &node)
00044         : BaseNode(ST_NODE_SENDRECV),
00045           msg_(node.msg_->clone()),
00046           sndr_(node.sndr_ ? node.sndr_->clone() : nullptr), rcvrs_()
00047     {
00048         for (auto rcvr : node.rcvrs_) {
00049             rcvrs_.push_back(rcvr->clone());
00050         }
00051     }
00052 
00054     ~InteractionNodeTmpl() override
00055     {
00056         delete msg_;
00057         if (sndr_) delete sndr_;
00058         for (auto rcvr : rcvrs_) {
00059             delete rcvr;
00060         }
00061     }
00062 
00064     InteractionNodeTmpl *clone() const override
00065     {
00066         return new InteractionNodeTmpl(*this);
00067     }
00068 
00071     void set_msg(MessageType *msg)
00072     {
00073         if (msg_) delete msg_;
00074         msg_ = msg->clone();
00075     }
00076 
00078     MessageType *msg() const
00079     {
00080         return msg_;
00081     }
00082 
00084     void set_sndr(RoleType *sndr)
00085     {
00086         if (sndr_) delete sndr_;
00087         sndr_ = sndr->clone();
00088     }
00089 
00091     RoleType *sndr() const
00092     {
00093         return sndr_;
00094     }
00095 
00097     void remove_sndr()
00098     {
00099         delete sndr_;
00100         sndr_ = nullptr;
00101     }
00102 
00104     void add_rcvr(RoleType *rcvr)
00105     {
00106         rcvrs_.push_back(rcvr->clone());
00107     }
00108 
00110     unsigned int num_rcvrs() const
00111     {
00112         return rcvrs_.size();
00113     }
00114 
00117     RoleType *rcvr() const
00118     {
00119         return rcvrs_.at(0);
00120     }
00121 
00123     RoleType *rcvr(unsigned int idx) const
00124     {
00125         return rcvrs_.at(idx);
00126     }
00127 
00129     void remove_rcvrs()
00130     {
00131         for (auto rcvr : rcvrs_) {
00132             delete rcvr;
00133         }
00134         rcvrs_.clear();
00135     }
00136 
00138     typename RoleContainer::const_iterator rcvr_begin() const
00139     {
00140         return rcvrs_.begin();
00141     }
00142 
00144     typename RoleContainer::const_iterator rcvr_end() const
00145     {
00146         return rcvrs_.end();
00147     }
00148 
00149     void accept(VisitorType &v) override;
00150 };
00151 
00152 using InteractionNode = InteractionNodeTmpl<Node, Role, MsgSig, util::NodeVisitor>;
00153 #endif // __cplusplus
00154 
00155 #ifdef __cplusplus
00156 extern "C" {
00157 #endif
00158 
00159 st_node *st_mk_interaction_node_init();
00160 
00161 st_node *st_mk_interaction_node(st_msg *msg);
00162 
00163 st_node *st_interaction_node_set_msg(st_node *const node, st_msg *msg);
00164 
00165 st_msg *st_interaction_node_get_msg(st_node *const node);
00166 
00167 st_node *st_interaction_node_set_from(st_node *const node, st_role *from);
00168 
00169 st_role *st_interaction_node_get_from(st_node *const node);
00170 
00171 st_node *st_interaction_node_add_to(st_node *const node, st_role *to);
00172 
00173 unsigned int st_interaction_node_num_tos(st_node *const node);
00174 
00175 st_role **st_interaction_node_get_tos(st_node *const node);
00176 
00177 st_role *st_interaction_node_get_to(st_node *const node, unsigned int index);
00178 
00179 #ifdef __cplusplus
00180 } // extern "C"
00181 #endif
00182 
00183 #ifdef __cplusplus
00184 } // namespace sesstype
00185 #endif
00186 
00187 #endif//SESSTYPE__NODE__INTERACTION_H__
 All Classes Namespaces Files Functions