libsesstype  2.0.0
Library for Session Types programming.
nested.h
00001 #ifndef SESSTYPE__NODE__NESTED_H__
00002 #define SESSTYPE__NODE__NESTED_H__
00003 
00004 #ifdef __cplusplus
00005 #include <string>
00006 #include <iterator>
00007 #include <vector>
00008 #endif
00009 
00010 #include "sesstype/msg.h"
00011 #include "sesstype/node.h"
00012 #include "sesstype/role.h"
00013 #include "sesstype/util/clonable.h"
00014 #include "sesstype/util/visitor_tmpl.h"
00015 
00016 #ifdef __cplusplus
00017 namespace sesstype {
00018 #endif
00019 
00020 #ifdef __cplusplus
00021 
00024 template <class BaseNode, class RoleType, class MessageType, class VisitorType>
00025 class NestedNodeTmpl : public BaseNode {
00026     std::string name_;
00027     std::string scope_;
00028     typename std::vector<MessageType *> args_;
00029     typename std::vector<RoleType *> role_args_;
00030 
00031   public:
00033     NestedNodeTmpl(std::string protocol_name)
00034         : BaseNode(ST_NODE_NESTED),
00035         name_(protocol_name), scope_(), args_(), role_args_() { }
00036 
00038     NestedNodeTmpl(std::string protocol_name, std::string scope)
00039         : BaseNode(ST_NODE_NESTED),
00040           name_(protocol_name), scope_(scope), args_(), role_args_() { }
00041 
00043     NestedNodeTmpl(const NestedNodeTmpl &node)
00044         : BaseNode(node),
00045           name_(node.name_), scope_(node.scope_), args_(), role_args_()
00046     {
00047         for (auto arg : node.args_) {
00048             add_arg(arg->clone());
00049         }
00050         for (auto role_arg : node.role_args_) {
00051             add_arg(role_arg->clone());
00052         }
00053     }
00054 
00056     ~NestedNodeTmpl() override
00057     {
00058         for (auto arg : args_) {
00059             delete arg;
00060         }
00061         for (auto role_arg : role_args_) {
00062             delete role_arg;
00063         }
00064     }
00065 
00067     NestedNodeTmpl *clone() const override
00068     {
00069         return new NestedNodeTmpl(*this);
00070     }
00071 
00073     std::string name() const
00074     {
00075         return name_;
00076     }
00077 
00079     void set_scope(std::string scope)
00080     {
00081         scope_ = scope;
00082     }
00083 
00085     std::string scope() const
00086     {
00087         return scope_;
00088     }
00089 
00092     void add_arg(MessageType *msg)
00093     {
00094         args_.push_back(msg);
00095     }
00096 
00098     unsigned int num_args() const
00099     {
00100         return args_.size();
00101     }
00102 
00103     MessageType *arg(unsigned int idx) const
00104     {
00105         return args_.at(idx);
00106     }
00107 
00108     typename std::vector<MessageType *>::const_iterator arg_begin() const
00109     {
00110         return args_.begin();
00111     }
00112 
00113     typename std::vector<MessageType *>::const_iterator arg_end() const
00114     {
00115         return args_.end();
00116     }
00117 
00120     void add_arg(RoleType *role)
00121     {
00122         role_args_.push_back(role);
00123     }
00124 
00126     unsigned int num_roleargs() const
00127     {
00128         return role_args_.size();
00129     }
00130 
00131 
00132     RoleType *rolearg(unsigned int idx) const
00133     {
00134         return role_args_.at(idx);
00135     }
00136 
00137     typename std::vector<RoleType *>::const_iterator rolearg_begin() const
00138     {
00139         return role_args_.begin();
00140     }
00141 
00142     typename std::vector<RoleType *>::const_iterator rolearg_end() const
00143     {
00144         return role_args_.end();
00145     }
00146 
00147     void accept(VisitorType &v) override;
00148 };
00149 
00150 using NestedNode = NestedNodeTmpl<Node, Role, MsgSig, util::NodeVisitor>;
00151 #endif // __cplusplus
00152 
00153 #ifdef __cplusplus
00154 extern "C" {
00155 #endif
00156 
00157 st_node *st_mk_nested_node(char *protocol_name);
00158 
00159 st_node *st_mk_nested_node_scoped(char *protocol_name, char *scope_name);
00160 
00161 st_node *st_nested_node_add_arg(st_node *const node, st_msg *arg);
00162 
00163 unsigned int st_nested_node_num_args(st_node *const node);
00164 
00165 st_msg *st_nested_node_get_arg(st_node *const node, unsigned int index);
00166 
00167 st_node *st_nested_node_add_rolearg(st_node *const node, st_role *rolearg);
00168 
00169 unsigned int st_nested_node_num_roleargs(st_node *const node);
00170 
00171 st_role *st_nested_node_get_rolearg(st_node *const node, unsigned int index);
00172 
00173 #ifdef __cplusplus
00174 } // extern "C"
00175 #endif
00176 
00177 
00178 #ifdef __cplusplus
00179 } // namespace sesstype
00180 #endif
00181 
00182 #endif//SESSTYPE__NODE__NESTED_H__
 All Classes Namespaces Files Functions