cmodule.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef __CMODULE_H
00017 #define __CMODULE_H
00018
00019 #include <vector>
00020 #include "ccomponent.h"
00021 #include "globals.h"
00022 #include "cgate.h"
00023 #include "csimulation.h"
00024
00025 NAMESPACE_BEGIN
00026
00027
00028 class cMessage;
00029 class cGate;
00030 class cSimulation;
00031 class cModuleType;
00032 class cCanvas;
00033
00048 class SIM_API cModule : public cComponent
00049 {
00050 friend class cGate;
00051 friend class cSimulation;
00052 friend class cModuleType;
00053 friend class cChannelType;
00054
00055 public:
00068 class SIM_API GateIterator
00069 {
00070 private:
00071 const cModule *module;
00072 int descIndex;
00073 bool isOutput;
00074 int index;
00075
00076 private:
00077 void advance();
00078 cGate *current() const;
00079
00080 public:
00084 GateIterator(const cModule *m) {init(m);}
00085
00089 void init(const cModule *m);
00090
00095 cGate *operator()() const {cGate *result=current(); ASSERT(result||end()); return result;}
00096
00100 bool end() const;
00101
00107 cGate *operator++(int);
00108
00113 cGate *operator+=(int k);
00114 };
00115
00128 class SIM_API SubmoduleIterator
00129 {
00130 private:
00131 cModule *p;
00132
00133 public:
00137 SubmoduleIterator(const cModule *m) {init(m);}
00138
00142 void init(const cModule *m) {p = m ? const_cast<cModule *>(m->firstsubmodp) : NULL;}
00143
00149 cModule *operator()() const {return p;}
00150
00154 bool end() const {return (bool)(p==NULL);}
00155
00161 cModule *operator++(int) {if (!p) return NULL; cModule *t=p; p=p->nextp; return t;}
00162 };
00163
00169 class SIM_API ChannelIterator
00170 {
00171 private:
00172 std::vector<cChannel *> channels;
00173 int k;
00174
00175 public:
00179 ChannelIterator(const cModule *parentmodule) {init(parentmodule);}
00180
00184 void init(const cModule *parentmodule);
00185
00190 cChannel *operator()() const {return k < (int)channels.size() ? channels[k] : NULL;}
00191
00195 bool end() const {return k == (int)channels.size();}
00196
00203 cChannel *operator++(int) {return end() ? NULL : channels[k++];}
00204 };
00205
00206 private:
00207 static std::string lastmodulefullpath;
00208 static const cModule *lastmodulefullpathmod;
00209
00210 private:
00211 enum {
00212 FL_BUILDINSIDE_CALLED = 128,
00213 FL_RECORD_EVENTS = 256,
00214 };
00215
00216 protected:
00217 mutable char *fullpath;
00218 mutable char *fullname;
00219 int mod_id;
00220 static bool cachefullpath;
00221
00222
00223
00224
00225 cModule *prevp, *nextp;
00226 cModule *firstsubmodp;
00227 cModule *lastsubmodp;
00228
00229 typedef std::set<cGate::Name> NamePool;
00230 static NamePool namePool;
00231 int descvSize;
00232 cGate::Desc *descv;
00233
00234 int idx;
00235 int vectsize;
00236
00237 cCanvas *canvas;
00238
00239 public:
00240
00241 void setRecordEvents(bool e) {setFlag(FL_RECORD_EVENTS,e);}
00242 bool isRecordEvents() const {return flags&FL_RECORD_EVENTS;}
00243
00244 protected:
00245
00246 void releaseListeners();
00247
00248
00249 bool buildInsideCalled() const {return flags&FL_BUILDINSIDE_CALLED;}
00250
00251
00252
00253 virtual bool initializeModules(int stage);
00254
00255
00256
00257 virtual bool initializeChannels(int stage);
00258
00259
00260
00261 virtual void arrived(cMessage *msg, cGate *ongate, simtime_t t);
00262
00263
00264 virtual void setId(int n);
00265
00266
00267
00268 virtual void setNameAndIndex(const char *s, int i, int n);
00269
00270
00271 void updateFullName();
00272
00273
00274 void updateFullPath();
00275
00276
00277 void insertSubmodule(cModule *mod);
00278
00279
00280 void removeSubmodule(cModule *mod);
00281
00282
00283
00284 virtual cGate *createGateObject(cGate::Type type);
00285
00286
00287 void disposeGateDesc(cGate::Desc *desc, bool checkConnected);
00288
00289
00290 void disposeGateObject(cGate *gate, bool checkConnected);
00291
00292
00293 cGate::Desc *addGateDesc(const char *name, cGate::Type type, bool isVector);
00294
00295
00296
00297 int findGateDesc(const char *gatename, char& suffix) const;
00298
00299
00300 cGate::Desc *gateDesc(const char *gatename, char& suffix) const;
00301
00302
00303 void adjustGateDesc(cGate *g, cGate::Desc *newvec);
00304
00305
00306 void clearGates();
00307
00308
00309 virtual void doBuildInside();
00310
00311 public:
00312
00313 static void clearNamePools();
00314
00315
00316 int gateCount() const;
00317
00318
00319 cGate *gateByOrdinal(int k) const;
00320
00321
00322 cCanvas *getCanvasIfExists() {return canvas;}
00323
00324 public:
00334 cModule();
00335
00339 virtual ~cModule();
00341
00344
00349 virtual void forEachChild(cVisitor *v);
00350
00354 virtual void setName(const char *s);
00355
00361 virtual const char *getFullName() const;
00362
00368 virtual std::string getFullPath() const;
00369
00373 std::string info() const;
00375
00378
00389 virtual cGate *addGate(const char *gatename, cGate::Type type, bool isvector=false);
00390
00397 virtual void setGateSize(const char *gatename, int size);
00398
00410 virtual cGate *getOrCreateFirstUnconnectedGate(const char *gatename, char suffix,
00411 bool inside, bool expand);
00412
00419 virtual void getOrCreateFirstUnconnectedGatePair(const char *gatename,
00420 bool inside, bool expand,
00421 cGate *&gatein, cGate *&gateout);
00422
00440 virtual void finalizeParameters();
00441
00451 virtual int buildInside();
00453
00456
00461 virtual bool isSimple() const;
00462
00466 virtual bool isModule() const {return true;}
00467
00472 virtual bool isPlaceholder() const {return false;}
00473
00478 virtual cModule *getParentModule() const;
00479
00483 cModuleType *getModuleType() const {return (cModuleType *)getComponentType();}
00484
00489 virtual cProperties *getProperties() const;
00490
00500 int getId() const {return mod_id;}
00501
00505 bool isVector() const {return vectsize>=0;}
00506
00510 int getIndex() const {return idx;}
00511
00516 int getVectorSize() const {return vectsize<0 ? 1 : vectsize;}
00517
00521 int size() const {return getVectorSize();}
00523
00530 bool hasSubmodules() const {return firstsubmodp!=NULL;}
00531
00537 int findSubmodule(const char *submodname, int idx=-1);
00538
00544 cModule *getSubmodule(const char *submodname, int idx=-1);
00545
00553 _OPPDEPRECATED cModule *getModuleByRelativePath(const char *path);
00554
00573 cModule *getModuleByPath(const char *path);
00575
00578
00585 virtual cGate *gate(const char *gatename, int index=-1);
00586
00593 const cGate *gate(const char *gatename, int index=-1) const {
00594 return const_cast<cModule *>(this)->gate(gatename, index);
00595 }
00596
00604 virtual cGate *gateHalf(const char *gatename, cGate::Type type, int index=-1);
00605
00613 const cGate *gateHalf(const char *gatename, cGate::Type type, int index=-1) const {
00614 return const_cast<cModule *>(this)->gateHalf(gatename, type, index);
00615 }
00616
00624 virtual bool hasGate(const char *gatename, int index=-1) const;
00625
00633 virtual int findGate(const char *gatename, int index=-1) const;
00634
00642 virtual cGate *gate(int id);
00643
00651 const cGate *gate(int id) const {return const_cast<cModule *>(this)->gate(id);}
00652
00658 virtual void deleteGate(const char *gatename);
00659
00670 virtual std::vector<const char *> getGateNames() const;
00671
00677 virtual cGate::Type gateType(const char *gatename) const;
00678
00684 virtual bool isGateVector(const char *gatename) const;
00685
00696 virtual int gateSize(const char *gatename) const;
00697
00707 virtual int gateBaseId(const char *gatename) const;
00708
00715 bool checkInternalConnections() const;
00717
00724 cPar& getAncestorPar(const char *parname);
00725
00729 virtual cCanvas *getCanvas();
00731
00741 virtual void callInitialize();
00742
00747 virtual bool callInitialize(int stage);
00748
00752 virtual void callFinish();
00754
00757
00762 virtual void scheduleStart(simtime_t t);
00763
00769 virtual void deleteModule();
00770
00792 virtual void changeParentTo(cModule *mod);
00794 };
00795
00796
00800 class SIM_API _OPPDEPRECATED cSubModIterator : public cModule::SubmoduleIterator
00801 {
00802 public:
00803 cSubModIterator(const cModule& m) : cModule::SubmoduleIterator(&m) {}
00804 void init(const cModule& m) {cModule::SubmoduleIterator::init(&m);}
00805 };
00806
00807 NAMESPACE_END
00808
00809
00810 #endif
00811