00001 //========================================================================== 00002 // CHEAD.H - header for 00003 // OMNeT++ 00004 // Discrete System Simulation in C++ 00005 // 00006 // 00007 // Declaration of the following classes: 00008 // cHead : head of a list of cObjs 00009 // cIterator : walks along a list 00010 // 00011 //========================================================================== 00012 00013 /*--------------------------------------------------------------* 00014 Copyright (C) 1992-2001 Andras Varga 00015 Technical University of Budapest, Dept. of Telecommunications, 00016 Stoczek u.2, H-1111 Budapest, Hungary. 00017 00018 This file is distributed WITHOUT ANY WARRANTY. See the file 00019 `license' for details on this and other legal matters. 00020 *--------------------------------------------------------------*/ 00021 00022 #ifndef __CHEAD_H 00023 #define __CHEAD_H 00024 00025 #include "cobject.h" 00026 00027 //=== classes declared here 00028 class cIterator; 00029 class cHead; 00030 00031 //=== classes mentioned 00032 class cModuleInterface; 00033 class cModuleType; 00034 class cLinkType; 00035 class cFunctionType; 00036 class cNetworkType; 00037 class cInspectorFactory; 00038 class cEnum; 00039 00040 //========================================================================== 00041 00067 class SIM_API cHead : public cObject 00068 { 00069 friend class const_cIterator; 00070 friend class cIterator; 00071 friend class cObject; 00072 00073 public: 00076 00080 cHead(const char *name=NULL); 00081 00085 cHead(const char *name, cHead *h); 00086 00090 cHead(const cHead& h) : cObject(h) {setName(h.name());operator=(h);} 00091 00096 virtual ~cHead() {deleteChildren();} 00097 00101 cHead& operator=(const cHead&) {copyNotSupported();return *this;} 00103 00106 00110 virtual const char *className() const {return "cHead";} 00111 00116 virtual cObject *dup() const {return new cHead(*this);} 00117 00122 virtual const char *inspectorFactoryName() const {return "cHeadIFC";} 00123 00128 virtual void forEach(ForeachFunc f); 00130 00133 00138 cObject *find(const char *objname) const; 00139 00143 int count() const; 00145 }; 00146 00147 //========================================================================== 00148 00154 class SIM_API cIterator 00155 { 00156 private: 00157 cObject *p; 00158 00159 public: 00163 cIterator(const cObject& h) {p = &h ? h.firstchildp : NO(cObject);} 00164 00168 void init(cObject& h) {p = &h ? h.firstchildp : NO(cObject);} 00169 00173 cObject *operator()() const {return p;} 00174 00178 bool end() const {return (bool)(p==NULL);} 00179 00183 cObject *operator++(int) {cObject *t=p; if(p) p=p->nextp; return t;} 00184 }; 00185 00186 00190 class SIM_API const_cIterator 00191 { 00192 private: 00193 const cObject *p; 00194 00195 public: 00199 const_cIterator(const cObject& h) {p = &h ? h.firstchildp : NO(cObject);} 00200 00204 void init(const cObject& h) {p = &h ? h.firstchildp : NO(cObject);} 00205 00209 const cObject *operator()() const {return p;} 00210 00214 bool end() const {return (bool)(p==NULL);} 00215 00219 const cObject *operator++(int) {const cObject *t=p; if(p) p=p->nextp; return t;} 00220 }; 00221 00222 //========================================================================== 00223 00229 00231 inline cNetworkType *findNetwork(const char *s) 00232 {return (cNetworkType *)networks.find(s);} 00233 00235 inline cModuleType *findModuleType(const char *s) 00236 {return (cModuleType *)modtypes.find(s);} 00237 00239 inline cModuleInterface *findModuleInterface(const char *s) 00240 {return (cModuleInterface *)modinterfaces.find(s);} 00241 00243 inline cLinkType *findLink(const char *s) 00244 {return (cLinkType *)linktypes.find(s);} 00245 00247 inline cFunctionType *findFunction(const char *s) 00248 {return (cFunctionType *)functions.find(s);} 00249 00251 inline cInspectorFactory *findInspectorFactory(const char *s) 00252 {return (cInspectorFactory *)inspectorfactories.find(s);} 00253 00255 inline cEnum *findEnum(const char *s) 00256 {return (cEnum *)enums.find(s);} 00258 00259 #endif 00260