ctopology.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __CTOPOLOGY_H
00021 #define __CTOPOLOGY_H
00022
00023 #include <string>
00024 #include <vector>
00025 #include "cownedobject.h"
00026 #include "csimulation.h"
00027 #include "cmodule.h"
00028 #include "cgate.h"
00029
00030 NAMESPACE_BEGIN
00031
00032 class cPar;
00033
00034
00035 #ifndef INFINITY
00036 #define INFINITY HUGE_VAL
00037 #endif
00038
00060 class SIM_API cTopology : public cOwnedObject
00061 {
00062 public:
00063 class Link;
00064 class LinkIn;
00065 class LinkOut;
00066
00070 class SIM_API Node
00071 {
00072 friend class cTopology;
00073
00074 private:
00075 int module_id;
00076 double wgt;
00077 bool enabl;
00078
00079 int num_in_links;
00080 Link **in_links;
00081 int num_out_links;
00082 Link *out_links;
00083
00084
00085 double dist;
00086 Link *out_path;
00087
00088 public:
00091
00095 int getModuleId() const {return module_id;}
00096
00100 cModule *getModule() const {return simulation.getModule(module_id);}
00101
00106 double getWeight() const {return wgt;}
00107
00112 void setWeight(double d) {wgt=d;}
00113
00118 bool isEnabled() const {return enabl;}
00119
00124 void enable() {enabl=true;}
00125
00130 void disable() {enabl=false;}
00132
00135
00139 int getNumInLinks() const {return num_in_links;}
00140
00144 LinkIn *getLinkIn(int i);
00145
00149 int getNumOutLinks() const {return num_out_links;}
00150
00154 LinkOut *getLinkOut(int i);
00156
00159
00163 double getDistanceToTarget() const {return dist;}
00164
00169 int getNumPaths() const {return out_path?1:0;}
00170
00176 LinkOut *getPath(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 getWeight() const {return wgt;}
00202
00207 void setWeight(double d) {wgt=d;}
00208
00213 bool isEnabled() 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 *getRemoteNode() const {return src_node;}
00248
00252 int getRemoteGateId() const {return src_gate;}
00253
00257 int getLocalGateId() const {return dest_gate;}
00258
00262 cGate *getRemoteGate() const {return src_node->getModule()->gate(src_gate);}
00263
00267 cGate *getLocalGate() const {return dest_node->getModule()->gate(dest_gate);}
00268 };
00269
00270
00279 class SIM_API LinkOut : public Link
00280 {
00281 public:
00289 Node *getRemoteNode() const {return dest_node;}
00290
00294 int getRemoteGateId() const {return dest_gate;}
00295
00299 int getLocalGateId() const {return src_gate;}
00300
00304 cGate *getRemoteGate() const {return dest_node->getModule()->gate(dest_gate);}
00305
00309 cGate *getLocalGate() const {return src_node->getModule()->gate(src_gate);}
00310 };
00311
00317 class SIM_API Predicate
00318 {
00319 public:
00320 virtual ~Predicate() {}
00321 virtual bool matches(cModule *module) = 0;
00322 };
00323
00324 protected:
00325 int num_nodes;
00326 Node *nodev;
00327 Node *target;
00328
00329 public:
00332
00336 explicit cTopology(const char *name=NULL);
00337
00341 cTopology(const cTopology& topo);
00342
00346 virtual ~cTopology();
00347
00351 cTopology& operator=(const cTopology& topo);
00353
00356
00361 virtual cTopology *dup() const {return new cTopology(*this);}
00362
00367 virtual std::string info() const;
00368
00374 virtual void parsimPack(cCommBuffer *buffer);
00375
00381 virtual void parsimUnpack(cCommBuffer *buffer);
00383
00392
00399 void extractFromNetwork(bool (*selfunc)(cModule *,void *), void *userdata=NULL);
00400
00404 void extractFromNetwork(Predicate *predicate);
00405
00415 void extractByModulePath(const std::vector<std::string>& fullPathPatterns);
00416
00427 void extractByNedTypeName(const std::vector<std::string>& nedTypeNames);
00428
00447 void extractByProperty(const char *propertyName, const char *value=NULL);
00448
00455 void extractByParameter(const char *paramName, const char *paramValue=NULL);
00456
00460 void clear();
00462
00469
00473 int getNumNodes() const {return num_nodes;}
00474
00479 Node *getNode(int i);
00480
00488 Node *getNodeFor(cModule *mod);
00490
00492
00493
00494
00495
00496
00498
00503 void calculateUnweightedSingleShortestPathsTo(Node *target);
00504
00510 void calculateWeightedSingleShortestPathsTo(Node *target);
00511
00516 Node *getTargetNode() const {return target;}
00518 };
00519
00520 NAMESPACE_END
00521
00522
00523 #endif