libsesstype  2.0.0
Library for Session Types programming.
module.h
Go to the documentation of this file.
00001 
00005 #ifndef SESSTYPE__PARAMETERISED__MODULE_H__
00006 #define SESSTYPE__PARAMETERISED__MODULE_H__
00007 
00008 #ifdef __cplusplus
00009 #include <iterator>
00010 #include <unordered_map>
00011 #endif
00012 
00013 #include "sesstype/module.h"
00014 #include "sesstype/import.h"
00015 #include "sesstype/parameterised/const.h"
00016 #include "sesstype/parameterised/session.h"
00017 
00018 #ifdef __cplusplus
00019 namespace sesstype {
00020 namespace parameterised {
00021 #endif
00022 
00023 #ifdef __cplusplus
00024 
00028 template <class ImportType, class SessionType, class ConstantType>
00029 class ModuleTmpl : public sesstype::ModuleTmpl<ImportType, SessionType> {
00030     std::unordered_map<std::string, ConstantType *> consts_;
00031 
00032   public:
00033     using ConstantContainer = std::unordered_map<std::string, ConstantType *>;
00034 
00036     ModuleTmpl()
00037         : sesstype::ModuleTmpl<ImportType, SessionType>(), consts_() { }
00038 
00040     ModuleTmpl(std::string name)
00041         : sesstype::ModuleTmpl<ImportType, SessionType>(name), consts_() { }
00042 
00044     virtual ~ModuleTmpl()
00045     {
00046         for (auto constant_pair : consts_) {
00047             delete constant_pair.second;
00048         }
00049     }
00050 
00052     void add_constant(ConstantType *c)
00053     {
00054         consts_.insert({ c->name(), c });
00055     }
00056 
00058     unsigned int num_constants() const
00059     {
00060         return consts_.size();
00061     }
00062 
00065     bool has_constant(std::string name) const
00066     {
00067         return (consts_.find(name) != consts_.end());
00068     }
00069 
00072     ConstantType *constant(std::string name) const
00073     {
00074         return consts_.at(name);
00075     }
00076 
00077     typename ConstantContainer::const_iterator const_begin() const
00078     {
00079         return consts_.begin();
00080     }
00081 
00082     typename ConstantContainer::const_iterator const_end() const
00083     {
00084         return consts_.end();
00085     }
00086 };
00087 
00088 using Module = ModuleTmpl<sesstype::Import, Session, Constant>;
00089 #endif // __cplusplus
00090 
00091 #ifdef __cplusplus
00092 } // namespace parameterised
00093 } // namespace sesstype
00094 #endif
00095 
00096 #endif//SESSTYPE__PARAMETERISED__MODULE_H__
 All Classes Namespaces Files Functions