OMNeT++ Simulation Library  6.0.3
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 "cobject.h"
23 #include "cexception.h"
24 
25 namespace omnetpp {
26 
27 
34 class SIM_API cNamedObject : public cObject
35 {
36  private:
37  const char *name = nullptr; // object name (stringpooled if flags&FL_NAMEPOOLING!=0)
38 
39  protected:
40  uint32_t flags = FL_NAMEPOOLING; // FL_NAMEPOOLING flag; other bits used by derived classes
41  enum {FL_NAMEPOOLING = 1};
42 
43  private:
44  void copy(const cNamedObject& other);
45 
46  protected:
47  // internal: set a bit in flags; flag is one of the FL_xxx constants
48  void setFlag(int flag, bool value) {if (value) flags|=flag; else flags&=~flag;}
49  int getFlag(int flag) {return flags & flag;}
50 
51  public:
58 
62  explicit cNamedObject(const char *name, bool namepooling=true);
63 
67  cNamedObject(const cNamedObject& obj);
68 
72  virtual ~cNamedObject();
73 
82  cNamedObject& operator=(const cNamedObject& o);
83 
84  // Note: dup() is still the original cObject one, which throws an error
85  // to indicate that dup() has to be redefined in each subclass.
86 
90  virtual void parsimPack(cCommBuffer *buffer) const override;
91 
95  virtual void parsimUnpack(cCommBuffer *buffer) override;
97 
105  virtual void setName(const char *s);
106 
111  virtual const char *getName() const override {return name ? name : "";}
112 
117  virtual void setNamePooling(bool b);
118 
122  virtual bool getNamePooling() {return flags&FL_NAMEPOOLING;}
124 };
125 
126 } // namespace omnetpp
127 
128 
129 #endif
130 
omnetpp::cObject
cObject is a lightweight class which serves as the root of the OMNeT++ class hierarchy....
Definition: cobject.h:92
omnetpp::cNamedObject::getName
virtual const char * getName() const override
Definition: cnamedobject.h:111
omnetpp::cNamedObject::cNamedObject
cNamedObject()
Definition: cnamedobject.h:57
omnetpp::cNamedObject
Extends cObject with a name string. Also includes a "flags" member, with bits open for use by subclas...
Definition: cnamedobject.h:34
omnetpp::cNamedObject::getNamePooling
virtual bool getNamePooling()
Definition: cnamedobject.h:122
omnetpp::cCommBuffer
Buffer for the communications layer of parallel simulation.
Definition: ccommbuffer.h:41