cnamedobject.h

00001 //==========================================================================
00002 //  CNAMEDOBJECT.H - part of
00003 //                     OMNeT++/OMNEST
00004 //            Discrete System Simulation in C++
00005 //
00006 //  Author: Andras Varga
00007 //
00008 //==========================================================================
00009 
00010 /*--------------------------------------------------------------*
00011   Copyright (C) 1992-2008 Andras Varga
00012   Copyright (C) 2006-2008 OpenSim Ltd.
00013 
00014   This file is distributed WITHOUT ANY WARRANTY. See the file
00015   `license' for details on this and other legal matters.
00016 *--------------------------------------------------------------*/
00017 
00018 #ifndef __CNAMEDOBJECT_H
00019 #define __CNAMEDOBJECT_H
00020 
00021 #include <typeinfo>
00022 #include <iostream>
00023 #include "simkerneldefs.h"
00024 #include "simutil.h"
00025 #include "cobject.h"
00026 #include "cexception.h"
00027 #include "cstringpool.h"
00028 
00029 NAMESPACE_BEGIN
00030 
00031 
00038 class SIM_API cNamedObject : public cObject
00039 {
00040   private:
00041     const char *namep;  // object name (stringpooled if flags&FL_NAMEPOOLING!=0)
00042 
00043   protected:
00044     unsigned short flags;  // FL_NAMEPOOLING flag; other bits used by derived classes
00045     unsigned short unused; // space lost to due to word aligment; one may make use of it in subclasses (cModule, cSimpleModule, cGate)
00046     enum {FL_NAMEPOOLING = 1};
00047 
00048   private:
00049     void copy(const cNamedObject& other);
00050 
00051   protected:
00052     // internal: set a bit in flags; flag is one of the FL_xxx constants
00053     void setFlag(int flag, bool value) {if (value) flags|=flag; else flags&=~flag;}
00054 
00055   private:
00056     // pool for shared storage of object names
00057     static cStringPool stringPool;
00058 
00059   public:
00065     cNamedObject();
00066 
00070     explicit cNamedObject(const char *name, bool namepooling=true);
00071 
00075     cNamedObject(const cNamedObject& obj);
00076 
00080     virtual ~cNamedObject();
00081 
00090     cNamedObject& operator=(const cNamedObject& o);
00091 
00092     // Note: dup() is still the original cObject one, which throws an error
00093     // to indicate that dup() has to be redefined in each subclass.
00094 
00098     virtual void parsimPack(cCommBuffer *buffer);
00099 
00103     virtual void parsimUnpack(cCommBuffer *buffer);
00105 
00113     virtual void setName(const char *s);
00114 
00119     virtual const char *getName() const  {return namep ? namep : "";}
00120 
00125     virtual void setNamePooling(bool b);
00126 
00130     virtual bool getNamePooling() {return flags&FL_NAMEPOOLING;}
00132 };
00133 
00134 NAMESPACE_END
00135 
00136 
00137 #endif
00138 
Generated on Tue Dec 2 11:16:27 2014 for OMNeT++ Simulation Library by  doxygen 1.6.3