00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef __DSIM_NETWORK__
00011 #define __DSIM_NETWORK__
00012
00013 #include <map>
00014 #include "dsim_value.h"
00015
00016 class dsim_connection;
00017 class dsim_model;
00018 class dsim_network;
00019
00020 class dsim_connection_key
00021 {
00022 public:
00023 dsim_connection_key(const std::string &source,const std::string &destination,bool bi_directional);
00024 dsim_connection_key(const dsim_connection_key &base);
00025 bool operator<(const dsim_connection_key &r) const;
00026
00027 private:
00028 std::string _source_path;
00029 std::string _destination_path;
00030 bool _bi_directional;
00031 };
00032
00042 class dsim_connection_iterator
00043 {
00044 public:
00045 dsim_connection_iterator(const dsim_connection_iterator &base)
00046 : _it(base._it), _network(base._network)
00047 {}
00048
00054 dsim_connection *connection() { return (*_it).second; }
00062 dsim_connection_iterator &next() { _it++; return *this; }
00064 bool finished();
00065
00066 private:
00067 dsim_connection_iterator(std::map<dsim_connection_key,dsim_connection *>::iterator it,dsim_network *network)
00068 : _it(it), _network(network)
00069 {}
00070 std::map<dsim_connection_key,dsim_connection *>::iterator _it;
00071 dsim_network *_network;
00072
00073 friend class dsim_network;
00074 };
00075
00076 class dsim_connection_variable
00077 {
00078 public:
00079 dsim_connection_variable()
00080 : type(0)
00081 {
00082 }
00083 dsim_connection_variable(const std::string &tname,int ttype,const char *tdescription)
00084 {
00085 name = tname;
00086 description = tdescription;
00087 type = ttype;
00088 }
00089 dsim_connection_variable(const dsim_connection_variable &base)
00090 {
00091 name = base.name;
00092 description = base.description;
00093 type = base.type;
00094 }
00095 dsim_connection_variable &operator=(const dsim_connection_variable &base)
00096 {
00097 name = base.name;
00098 description = base.description;
00099 type = base.type;
00100 return *this;
00101 }
00102
00103 std::string name;
00104 std::string description;
00105 int type;
00106 };
00107
00120 class dsim_network
00121 {
00122 public:
00123 ~dsim_network();
00124
00126 dsim_model *network_manager();
00128 const char *description() const;
00129
00131 void declare_variable(const std::string &name,int type,const char *description);
00133 int type_for_variable(const std::string &name);
00134
00136 dsim_connection *create_connection(const std::string &source,const std::string &destination,bool bi_directional = true);
00137
00139 unsigned int connection_count();
00141 dsim_connection_iterator connection_iterator();
00143 dsim_connection *retrieve_connection(const std::string &source,const std::string &destination,bool bi_directional = true);
00145 unsigned int object_identifier(const std::string &path);
00146
00147 private:
00148 dsim_network(dsim_model *manager,sd_data_type_manager *tm,const char *name,const char *description);
00149
00150 dsim_model *_manager;
00151 sd_data_type_manager *_tm;
00152 std::string _name;
00153 std::string _description;
00154
00155 std::map<dsim_connection_key,dsim_connection *> _connections;
00156 std::map<std::string,dsim_connection_variable> _variables;
00157 std::map<std::string,unsigned int> _model_identifiers;
00158 int _next_identifier;
00159
00160 friend class dsim_model;
00161 friend class dsim_connection;
00162 friend class dsim_connection_iterator;
00163 };
00164
00165 #endif