Main Page Modules Class Hierarchy Compound List File List Compound Members

# ctopo.h

    00001 //==========================================================================
    00002 //   CTOPO.H  - header for
    00003 //                             OMNeT++
    00004 //            Discrete System Simulation in C++
    00005 //
    00006 //
    00007 //  Declaration of the following classes:
    00008 //     cTopology : network topology to find shortest paths etc.
    00009 //
    00010 //==========================================================================
    00011
    00012 /*--------------------------------------------------------------*
    00013   Copyright (C) 1992-2003 Andras Varga
    00014
    00015   This file is distributed WITHOUT ANY WARRANTY. See the file
    00016   `license' for details on this and other legal matters.
    00017 *--------------------------------------------------------------*/
    00018
    00019 #ifndef __CTOPO_H
    00020 #define __CTOPO_H
    00021
    00022 #include "cobject.h"
    00023
    00024 class cPar;
    00025
    00026 #ifndef INFINITY
    00027 #define INFINITY  HUGE_VAL
    00028 #endif
    00029
    00030
    00052 class SIM_API cTopology : public cObject
    00053 {
    00054   public:
    00055     class Link;
    00056     class LinkIn;
    00057     class LinkOut;
    00058
    00062     class Node
    00063     {
    00064         friend class cTopology;
    00065
    00066       private:
    00067         int module_id;
    00068         double wgt;
    00069         bool enabl;
    00070
    00071         int num_in_links;
    00072         Link **in_links;
    00073         int num_out_links;
    00074         Link *out_links;
    00075
    00076         // variables used by the shortest-path algorithms
    00077         bool known;
    00078         double dist;
    00079         Link *out_path;
    00080
    00081       public:
    00084
    00088         int moduleId() const         {return module_id;}
    00089
    00093         cModule *module() const           {return &simulation[module_id];}
    00094
    00099         double weight() const        {return wgt;}
    00100
    00105         void setWeight(double d)    {wgt=d;}
    00106
    00111         bool enabled() const         {return enabl;}
    00112
    00117         void enable()               {enabl=true;}
    00118
    00123         void disable()              {enabl=false;}
    00125
    00128
    00132         int inLinks() const          {return num_in_links;}
    00133
    00137         LinkIn *in(int i);
    00138
    00142         int outLinks() const         {return num_out_links;}
    00143
    00147         LinkOut *out(int i);
    00149
    00152
    00156         double distanceToTarget() const   {return dist;}
    00157
    00162         int paths() const                 {return out_path?1:0;}
    00163
    00169         LinkOut *path(int) const     {return (LinkOut *)out_path;}
    00171     };
    00172
    00173
    00177     class Link
    00178     {
    00179         friend class cTopology;
    00180
    00181       protected:
    00182         Node *src_node;
    00183         int src_gate;
    00184         Node *dest_node;
    00185         int dest_gate;
    00186         double wgt;
    00187         bool enabl;
    00188
    00189       public:
    00194         double weight() const        {return wgt;}
    00195
    00200         void setWeight(double d)    {wgt=d;}
    00201
    00206         bool enabled() const         {return enabl;}
    00207
    00212         void enable()               {enabl=true;}
    00213
    00218         void disable()              {enabl=false;}
    00219     };
    00220
    00221
    00230     class LinkIn : public Link
    00231     {
    00232       public:
    00240         Node *remoteNode() const  {return src_node;}
    00241
    00245         int remoteGateId() const  {return src_gate;}
    00246
    00250         int localGateId() const   {return dest_gate;}
    00251
    00255         cGate *remoteGate() const      {return src_node->module()->gate(src_gate);}
    00256
    00260         cGate *localGate() const       {return dest_node->module()->gate(dest_gate);}
    00261     };
    00262
    00263
    00272     class SIM_API LinkOut : public Link
    00273     {
    00274       public:
    00282         Node *remoteNode() const  {return dest_node;}
    00283
    00287         int remoteGateId() const  {return dest_gate;}
    00288
    00292         int localGateId() const   {return src_gate;}
    00293
    00297         cGate *remoteGate() const      {return dest_node->module()->gate(dest_gate);}
    00298
    00302         cGate *localGate() const       {return src_node->module()->gate(src_gate);}
    00303     };
    00304
    00305
    00306   protected:
    00307     int num_nodes;
    00308     Node *nodev;
    00309     Node *target;
    00310
    00311   public:
    00314
    00318     explicit cTopology(const char *name=NULL);
    00319
    00323     cTopology(const cTopology& topo);
    00324
    00328     virtual ~cTopology();
    00329
    00333     cTopology& operator=(const cTopology& topo);
    00335
    00338
    00343     virtual cObject *dup() const     {return new cTopology(*this);}
    00344
    00349     virtual void info(char *buf);
    00350
    00356     virtual int netPack();
    00357
    00363     virtual int netUnpack();
    00365
    00374
    00379     void extractFromNetwork(int (*selfunc)(cModule *,void *), void *data=NULL);
    00380
    00386     void extractByModuleType(const char *type1,...);
    00387
    00393     void extractByParameter(const char *parname, cPar *value=NULL);
    00394
    00398     void clear();
    00400
    00407
    00411     int nodes() const  {return num_nodes;}
    00412
    00417     Node *node(int i);
    00418
    00426     Node *nodeFor(cModule *mod);
    00428
    00437
    00442     void unweightedSingleShortestPathsTo(Node *target);
    00443
    00448     Node *targetNode() const {return target;}
    00450 };
    00451
    00452 #endif