cownedobject.h Source File

API: cownedobject.h Source File
API
cownedobject.h
1//==========================================================================
2// COWNEDOBJECT.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_COWNEDOBJECT_H
17#define __OMNETPP_COWNEDOBJECT_H
18
19#include <utility>
20#include <typeinfo>
21#include <iostream>
22#include "simkerneldefs.h"
23#include "cnamedobject.h"
24#include "cexception.h"
25
26namespace omnetpp {
27
28class cOwnedObject;
30class cStaticFlag;
31class cSimulation;
32class cSoftOwner;
33class cMessage;
34class cPacket;
35
36namespace internal { class Void; }
37
105class SIM_API cOwnedObject : public cNamedObject
106{
107 friend class cObject;
108 friend class cNoncopyableOwnedObject;
109 friend class cSoftOwner;
110 friend class cSimulation;
111 friend class cMessage; // because of refcounting business
112 friend class cPacket; // because of refcounting business
113
114 private:
115 cObject *owner; // owner pointer
116 unsigned int pos; // used only when owner is a cSoftOwner
117
118 // list in which objects are accumulated if there is no simple module in context
119 // (see also setOwningContext() and cSimulation::setContextModule())
120 static cSoftOwner *owningContext;
121
122 // global variables for statistics
123 static long totalObjectCount;
124 static long liveObjectCount;
125
126 private:
127 cOwnedObject(const char *name, bool namepooling, internal::Void *dummy);
128 void copy(const cOwnedObject& obj);
129
130 public:
131 // internal
132 virtual void removeFromOwnershipTree();
133
134 // internal
135 static void setOwningContext(cSoftOwner *list);
136
137 public:
140
145
150 explicit cOwnedObject(const char *name, bool namepooling=true);
151
155 cOwnedObject(const cOwnedObject& obj);
156
160 virtual ~cOwnedObject();
161
172 cOwnedObject& operator=(const cOwnedObject& o);
173
174 // Note: dup() is still the original cObject one, which throws an error
175 // to indicate that dup() has to be redefined in each subclass.
176
180 virtual void parsimPack(cCommBuffer *buffer) const override;
181
185 virtual void parsimUnpack(cCommBuffer *buffer) override;
187
190
193 virtual cObject *getOwner() const override {return owner;}
194
198 virtual bool isOwnedObject() const override {return true;}
199
205 static cSoftOwner *getOwningContext();
207
210
217 static long getTotalObjectCount() {return totalObjectCount;}
218
225 static long getLiveObjectCount() {return liveObjectCount;}
226
231 static void resetObjectCounters() {totalObjectCount=liveObjectCount=0L;}
233};
234
235
242class SIM_API cNoncopyableOwnedObject : public cOwnedObject, noncopyable
243{
244 friend class cSoftOwner;
245 private:
246 cNoncopyableOwnedObject(const char *name, bool namepooling, internal::Void *dummy) : cOwnedObject(name, namepooling, dummy) {}
247 virtual void parsimPack(cCommBuffer *) const override {throw cRuntimeError(this, E_CANTPACK);}
248 virtual void parsimUnpack(cCommBuffer *) override {throw cRuntimeError(this, E_CANTPACK);}
249
250 public:
254 explicit cNoncopyableOwnedObject(const char *name=nullptr, bool namepooling=true) :
255 cOwnedObject(name, namepooling) {}
256
260 virtual cNoncopyableOwnedObject *dup() const override;
261};
262
263
264//
265// Internal class: provides a flag that shows if control is in the main() function.
266//
267class SIM_API cStaticFlag
268{
269 public:
270 cStaticFlag();
271 ~cStaticFlag();
272 static bool insideMain();
273 static bool isExiting();
274 static void setExiting();
275};
276
277} // namespace omnetpp
278
279
280#endif
281
Buffer for the communications layer of parallel simulation.
Definition ccommbuffer.h:42
The message class in OMNeT++. cMessage objects may represent events, messages, jobs or other entities...
Definition cmessage.h:96
cNamedObject()
Definition cnamedobject.h:57
Base class for cOwnedObject-based classes that do not wish to support assignment and duplication.
Definition cownedobject.h:243
cNoncopyableOwnedObject(const char *name=nullptr, bool namepooling=true)
Definition cownedobject.h:254
virtual cNoncopyableOwnedObject * dup() const override
A cObject that keeps track of its owner. It serves as base class for many classes in the OMNeT++ libr...
Definition cownedobject.h:106
static long getLiveObjectCount()
Definition cownedobject.h:225
static cSoftOwner * getOwningContext()
virtual cObject * getOwner() const override
Definition cownedobject.h:193
virtual void parsimPack(cCommBuffer *buffer) const override
static long getTotalObjectCount()
Definition cownedobject.h:217
cOwnedObject(const cOwnedObject &obj)
virtual bool isOwnedObject() const override
Definition cownedobject.h:198
virtual void parsimUnpack(cCommBuffer *buffer) override
static void resetObjectCounters()
Definition cownedobject.h:231
cOwnedObject(const char *name, bool namepooling=true)
cOwnedObject & operator=(const cOwnedObject &o)
A subclass of cMessage to represent packets, frames, datagrams, application messages,...
Definition cpacket.h:53
Thrown when the simulation kernel or other components detect a runtime error.
Definition cexception.h:343
Simulation manager class.
Definition csimulation.h:66
Internal class, used as a base class for modules and channels. It is not intended for subclassing out...
Definition csoftowner.h:34