OMNeT++ Simulation Library  5.6.1
cnamedobject.h
1 //==========================================================================
2 // CNAMEDOBJECT.H - part of
3 // OMNeT++/OMNEST
4 // Discrete System Simulation in C++
5 //
6 //==========================================================================
7 
8 /*--------------------------------------------------------------*
9  Copyright (C) 1992-2017 Andras Varga
10  Copyright (C) 2006-2017 OpenSim Ltd.
11 
12  This file is distributed WITHOUT ANY WARRANTY. See the file
13  `license' for details on this and other legal matters.
14 *--------------------------------------------------------------*/
15 
16 #ifndef __OMNETPP_CNAMEDOBJECT_H
17 #define __OMNETPP_CNAMEDOBJECT_H
18 
19 #include <typeinfo>
20 #include <iostream>
21 #include "simkerneldefs.h"
22 #include "simutil.h"
23 #include "cobject.h"
24 #include "cexception.h"
25 #include "cstringpool.h"
26 
27 namespace omnetpp {
28 
29 
36 class SIM_API cNamedObject : public cObject
37 {
38  private:
39  const char *name; // object name (stringpooled if flags&FL_NAMEPOOLING!=0)
40 
41  protected:
42  unsigned short flags; // FL_NAMEPOOLING flag; other bits used by derived classes
43  unsigned short unused; // space lost to due to word aligment; one may make use of it in subclasses (cModule, cSimpleModule, cGate)
44  enum {FL_NAMEPOOLING = 1};
45 
46  private:
47  void copy(const cNamedObject& other);
48 
49  protected:
50  // internal: set a bit in flags; flag is one of the FL_xxx constants
51  void setFlag(int flag, bool value) {if (value) flags|=flag; else flags&=~flag;}
52 
53  private:
54  // pool for shared storage of object names
55  static cStringPool stringPool;
56 
57  public:
63  cNamedObject();
64 
68  explicit cNamedObject(const char *name, bool namepooling=true);
69 
73  cNamedObject(const cNamedObject& obj);
74 
78  virtual ~cNamedObject();
79 
88  cNamedObject& operator=(const cNamedObject& o);
89 
90  // Note: dup() is still the original cObject one, which throws an error
91  // to indicate that dup() has to be redefined in each subclass.
92 
96  virtual void parsimPack(cCommBuffer *buffer) const override;
97 
101  virtual void parsimUnpack(cCommBuffer *buffer) override;
103 
111  virtual void setName(const char *s);
112 
117  virtual const char *getName() const override {return name ? name : "";}
118 
123  virtual void setNamePooling(bool b);
124 
128  virtual bool getNamePooling() {return flags&FL_NAMEPOOLING;}
130 };
131 
132 } // namespace omnetpp
133 
134 
135 #endif
136 
Root of the OMNeT++ class hierarchy. cObject is a lightweight class without any data members...
Definition: cobject.h:58
virtual const char * getName() const override
Definition: cnamedobject.h:117
Extends cObject with a name string. Also includes a "flags" member, with bits open for use by subclas...
Definition: cnamedobject.h:36
Buffer for the communications layer of parallel simulation.
Definition: ccommbuffer.h:41
virtual bool getNamePooling()
Definition: cnamedobject.h:128
Definition: cabstracthistogram.h:21
Reference-counted storage for strings.
Definition: cstringpool.h:36