00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __CTOPO_H
00020 #define __CTOPO_H
00021
00022 #ifdef _MSC_VER
00023
00024 #pragma warning(disable:4786)
00025 #endif
00026
00027 #include <string>
00028 #include <vector>
00029 #include "cobject.h"
00030
00031 class cPar;
00032
00033 #ifndef INFINITY
00034 #define INFINITY HUGE_VAL
00035 #endif
00036
00037
00059 class SIM_API cTopology : public cObject
00060 {
00061 public:
00062 class Link;
00063 class LinkIn;
00064 class LinkOut;
00065
00069 class SIM_API Node
00070 {
00071 friend class cTopology;
00072
00073 private:
00074 int module_id;
00075 double wgt;
00076 bool enabl;
00077
00078 int num_in_links;
00079 Link **in_links;
00080 int num_out_links;
00081 Link *out_links;
00082
00083
00084 bool known;
00085 double dist;
00086 Link *out_path;
00087
00088 public:
00091
00095 int moduleId() const {return module_id;}
00096
00100 cModule *module() const {return &simulation[module_id];}
00101
00106 double weight() const {return wgt;}
00107
00112 void setWeight(double d) {wgt=d;}
00113
00118 bool enabled() const {return enabl;}
00119
00124 void enable() {enabl=true;}
00125
00130 void disable() {enabl=false;}
00132
00135
00139 int inLinks() const {return num_in_links;}
00140
00144 LinkIn *in(int i);
00145
00149 int outLinks() const {return num_out_links;}
00150
00154 LinkOut *out(int i);
00156
00159
00163 double distanceToTarget() const {return dist;}
00164
00169 int paths() const {return out_path?1:0;}
00170
00176 LinkOut *path(int) const {return (LinkOut *)out_path;}
00178 };
00179
00180
00184 class SIM_API Link
00185 {
00186 friend class cTopology;
00187
00188 protected:
00189 Node *src_node;
00190 int src_gate;
00191 Node *dest_node;
00192 int dest_gate;
00193 double wgt;
00194 bool enabl;
00195
00196 public:
00201 double weight() const {return wgt;}
00202
00207 void setWeight(double d) {wgt=d;}
00208
00213 bool enabled() const {return enabl;}
00214
00219 void enable() {enabl=true;}
00220
00225 void disable() {enabl=false;}
00226 };
00227
00228
00237 class SIM_API LinkIn : public Link
00238 {
00239 public:
00247 Node *remoteNode() const {return src_node;}
00248
00252 int remoteGateId() const {return src_gate;}
00253
00257 int localGateId() const {return dest_gate;}
00258
00262 cGate *remoteGate() const {return src_node->module()->gate(src_gate);}
00263
00267 cGate *localGate() const {return dest_node->module()->gate(dest_gate);}
00268 };
00269
00270
00279 class SIM_API LinkOut : public Link
00280 {
00281 public:
00289 Node *remoteNode() const {return dest_node;}
00290
00294 int remoteGateId() const {return dest_gate;}
00295
00299 int localGateId() const {return src_gate;}
00300
00304 cGate *remoteGate() const {return dest_node->module()->gate(dest_gate);}
00305
00309 cGate *localGate() const {return src_node->module()->gate(src_gate);}
00310 };
00311
00312
00313 protected:
00314 int num_nodes;
00315 Node *nodev;
00316 Node *target;
00317
00318 public:
00321
00325 explicit cTopology(const char *name=NULL);
00326
00330 cTopology(const cTopology& topo);
00331
00335 virtual ~cTopology();
00336
00340 cTopology& operator=(const cTopology& topo);
00342
00345
00350 virtual cPolymorphic *dup() const {return new cTopology(*this);}
00351
00356 virtual std::string info() const;
00357
00363 virtual void netPack(cCommBuffer *buffer);
00364
00370 virtual void netUnpack(cCommBuffer *buffer);
00372
00381
00388 void extractFromNetwork(int (*selfunc)(cModule *,void *), void *userdata=NULL);
00389
00401 void extractByModuleType(const char *type1,...);
00402
00409 void extractByModuleType(const char **types);
00410
00416 void extractByModuleType(const std::vector<std::string> types);
00417
00423 void extractByParameter(const char *parname, cPar *value=NULL);
00424
00428 void clear();
00430
00437
00441 int nodes() const {return num_nodes;}
00442
00447 Node *node(int i);
00448
00456 Node *nodeFor(cModule *mod);
00458
00460
00461
00462
00463
00464
00465
00467
00472 void unweightedSingleShortestPathsTo(Node *target);
00473
00478 Node *targetNode() const {return target;}
00480 };
00481
00482 #endif