Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members  

cobject.h

00001 //==========================================================================
00002 //   COBJECT.H - header for
00003 //                             OMNeT++
00004 //            Discrete System Simulation in C++
00005 //
00006 //  Declaration of the following classes:
00007 //    cObject      : general base class
00008 //
00009 //==========================================================================
00010 
00011 /*--------------------------------------------------------------*
00012   Copyright (C) 1992-2001 Andras Varga
00013   Technical University of Budapest, Dept. of Telecommunications,
00014   Stoczek u.2, H-1111 Budapest, Hungary.
00015 
00016   This file is distributed WITHOUT ANY WARRANTY. See the file
00017   `license' for details on this and other legal matters.
00018 *--------------------------------------------------------------*/
00019 
00020 #ifndef __COBJECT_H
00021 #define __COBJECT_H
00022 
00023 #include <iostream.h>
00024 #include "defs.h"
00025 #include "util.h"
00026 
00027 #define FULLPATHBUF_SIZE  1024
00028 
00029 //=== classes declared here
00030 class  cObject;
00031 class  cStaticFlag;
00032 
00033 //=== classes mentioned
00034 class  TInspector;
00035 class  cIterator;
00036 class  cHead;
00037 
00038 //=== Global objects:
00039 SIM_API extern cHead superhead;           
00040 SIM_API extern cHead networks;            
00041 SIM_API extern cHead modinterfaces;       
00042 SIM_API extern cHead modtypes;            
00043 SIM_API extern cHead linktypes;           
00044 SIM_API extern cHead functions;           
00045 SIM_API extern cHead classes;             
00046 SIM_API extern cHead inspectorfactories;  
00047 SIM_API extern cHead enums;               
00048 
00049 
00059 typedef int (*CompareFunc)(cObject *a, cObject *b);
00060 
00066 typedef bool (*ForeachFunc)(cObject *,bool);
00067 
00068 
00084 class SIM_API cObject
00085 {
00086     friend class cHead;
00087     friend class cIterator;
00088     friend class const_cIterator;
00089     friend class cStaticFlag;
00090 
00091   protected:
00092     char *namestr;                    // name string
00093     char stor;                        // storage: Static/Auto/Dynamic ('S'/'A'/'D')
00094 
00095     bool tkownership;                 // for derived containers: take ownership of objects?
00096     cObject *ownerp, *prevp, *nextp;  // ptr to owner; linked list ptrs
00097     cObject *firstchildp;             // list of owned objects
00098 
00099     static int staticflag;            // to determine 'storage' (1 while in main())
00100     static int heapflag;              // to determine 'storage' (1 immediately after 'new')
00101     static char fullpathbuf[FULLPATHBUF_SIZE]; // buffer for fullPath()
00102 
00103   protected:
00110 
00121     void take(cObject *object)
00122         {object->setOwner( this );}
00123 
00136     void drop(cObject *object)
00137         {object->setOwner( object->defaultOwner() );}
00138 
00155     void dealloc(cObject *object)
00156         {if(object->storage()=='D') delete object; else object->setOwner(NULL);}
00158 
00161 
00168     void copyNotSupported() const;
00170 
00171   public:
00174 
00179     cObject(const cObject& obj);
00180 
00184     cObject();
00185 
00189     explicit cObject(const char *name);
00190 
00196     cObject(const char *name, cObject *ownerobj);
00197 
00202     virtual ~cObject();
00203 
00210     virtual cObject *dup() const    {return new cObject(*this);}
00211 
00217     void destruct() {this->~cObject();}
00218 
00227     cObject& operator=(const cObject& o);
00229 
00236 
00241     void setName(const char *s)  {delete namestr; namestr=opp_strdup(s);}
00242 
00247     const char *name() const     {return namestr ? namestr : "";}
00248 
00253     bool isName(const char *s) const {return !opp_strcmp(namestr,s);}
00254 
00260     virtual const char *fullName() const
00261         {return name();}
00262 
00268     virtual const char *fullPath() const;
00269 
00274     virtual const char *fullPath(char *buffer, int buffersize) const;
00276 
00279 
00283     cObject *owner() const {return ownerp;}
00284 
00291     void setOwner(cObject *newowner);
00292 
00298     virtual cObject *defaultOwner() const;
00300 
00308 
00314     void takeOwnership(bool tk) {tkownership=tk;}
00315 
00321     bool takeOwnership() const   {return tkownership;}
00323 
00326 
00331     virtual const char *className() const {return "cObject";}
00332 
00338     virtual void info(char *buf);
00339 
00346     virtual TInspector *inspector(int type, void *data);
00347 
00354     virtual const char *inspectorFactoryName() const {return "cObjectIFC";}
00355 
00362     virtual void writeTo(ostream& os);
00363 
00371     virtual void writeContents(ostream& os);
00373 
00382 
00387     virtual int netPack();
00388 
00393     virtual int netUnpack();
00395 
00398 
00437     virtual void forEach(ForeachFunc f);
00438 
00445     char storage() const         {return stor;}
00446 
00454     void *operator new(size_t m);
00455 
00460     void deleteChildren();
00461 
00474     void destructChildren();
00475 
00485     cObject *findObject(const char *name, bool deep=true);
00486 
00491     static int cmpbyname(cObject *one, cObject *other);
00493 };
00494 
00495 
00496 //
00497 // Internal helper class for cObject.
00498 //
00499 class cStaticFlag
00500 {
00501   public:
00502     cStaticFlag()  {cObject::staticflag = 1;}
00503     ~cStaticFlag() {cObject::staticflag = 0;}
00504 };
00505 
00506 #endif
00507 

Generated at Sat May 4 15:45:48 2002 for OMNeT++ by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001