libsesstype  2.0.0
Library for Session Types programming.
block.h
00001 #ifndef SESSTYPE__NODE__BLOCK_H__
00002 #define SESSTYPE__NODE__BLOCK_H__
00003 
00004 #ifdef __cplusplus
00005 #include <vector>
00006 #endif
00007 
00008 #include "sesstype/msg.h"
00009 #include "sesstype/role.h"
00010 #include "sesstype/node.h"
00011 
00012 #ifdef __cplusplus
00013 namespace sesstype {
00014 #endif
00015 
00016 #ifdef __cplusplus
00017 
00020 template <class BaseNode, class RoleType, class MessageType, class VisitorType>
00021 class BlockNodeTmpl : public BaseNode {
00022     std::vector<BaseNode *> children_;
00023 
00024   public:
00025     typedef typename std::vector<BaseNode *> NodeContainer;
00026 
00028     BlockNodeTmpl() : BaseNode(ST_NODE_ROOT), children_() { }
00029 
00031     BlockNodeTmpl(const BlockNodeTmpl &node) : BaseNode(ST_NODE_ROOT), children_()
00032     {
00033         for (BaseNode *child : node.children_) {
00034             children_.push_back(static_cast<BaseNode *>(child->clone()));
00035         }
00036     }
00037 
00039     ~BlockNodeTmpl() override
00040     {
00041         for (auto node: children_) {
00042             delete node;
00043         }
00044     }
00045 
00047     BlockNodeTmpl *clone() const override
00048     {
00049         return new BlockNodeTmpl<BaseNode, RoleType, MessageType, VisitorType>(*this);
00050     }
00051 
00056     BaseNode *child(unsigned int idx) const
00057     {
00058         return children_.at(idx);
00059     }
00060 
00063     unsigned int num_children() const
00064     {
00065         return children_.size();
00066     }
00067 
00070     void append_child(BaseNode *child)
00071     {
00072         children_.push_back(child);
00073     }
00074 
00075     void set_child(unsigned int idx, BaseNode *child)
00076     {
00077         children_.at(idx) = child;
00078     }
00079 
00081     typename NodeContainer::const_iterator child_begin() const
00082     {
00083         return children_.begin();
00084     }
00085 
00087     typename NodeContainer::const_iterator child_end() const
00088     {
00089         return children_.end();
00090     }
00091 
00092     virtual void accept(VisitorType &v) override;
00093 
00094   protected:
00095     BlockNodeTmpl(int type) : BaseNode(type), children_() { }
00096 };
00097 
00098 using BlockNode = BlockNodeTmpl<Node, Role, MsgSig, util::NodeVisitor>;
00099 #endif // __cplusplus
00100 
00101 #ifdef __cplusplus
00102 extern "C" {
00103 #endif
00104 
00105 st_node *st_node_append_child(st_node *const parent, st_node *child);
00106 
00107 unsigned int st_node_num_children(st_node *const parent);
00108 
00109 st_node *st_node_get_child(st_node *const parent, unsigned int index);
00110 
00111 #ifdef __cplusplus
00112 } // extern "C"
00113 #endif
00114 
00115 #ifdef __cplusplus
00116 } // namespace sesstype
00117 #endif
00118 
00119 #endif//SESSTYPE__NODE__BLOCK_H__
 All Classes Namespaces Files Functions