OMNeT++ Simulation Library  6.0.3
csoftowner.h
1 //==========================================================================
2 // CSOFTOWNER.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_CSOFTOWNER_H
17 #define __OMNETPP_CSOFTOWNER_H
18 
19 #include "cownedobject.h"
20 
21 namespace omnetpp {
22 
23 
33 class SIM_API cSoftOwner : public cNoncopyableOwnedObject
34 {
35  friend class cObject;
36  friend class cOwnedObject;
37  friend class cChannelType;
38 
39  private:
40  cOwnedObject **objs = nullptr; // array of owned objects
41  int numObjs = 0; // number of elements used in objects[] (0..num-1)
42  int capacity = 0; // allocated size of objs[]
43 
44 #ifdef SIMFRONTEND_SUPPORT
45  private:
46  int64_t lastChangeSerial;
47 #endif
48 
49  private:
50  void doInsert(cOwnedObject *obj);
51  virtual void ownedObjectDeleted(cOwnedObject *obj) override;
52  virtual void yieldOwnership(cOwnedObject *obj, cObject *newOwner) override;
53  protected:
54  void reportUndisposed();
55  virtual void objectStealingOnDeletion(cOwnedObject *obj);
56 
57  public:
58  // internal: constructor for the global cSoftOwner instance globalOwningContext which has no owner
59  explicit cSoftOwner(const char *name, bool namepooling, internal::Void *dummy) : cNoncopyableOwnedObject(name, namepooling, dummy) {}
60 
61 #ifdef SIMFRONTEND_SUPPORT
62  // internal: used by the UI to optimize refreshes
63  void updateLastChangeSerial() {lastChangeSerial = changeCounter++;}
64  virtual bool hasChangedSince(int64_t lastRefreshSerial);
65 #endif
66 
67  protected:
70 
74  virtual void take(cOwnedObject *obj) override;
75 
79  virtual void drop(cOwnedObject *obj) override;
80 
81  public:
87  explicit cSoftOwner(const char *name=nullptr, bool namepooling=true);
88 
92  virtual ~cSoftOwner();
94 
100  virtual bool isSoftOwner() const override {return true;}
101 
106  virtual std::string str() const override;
107 
112  virtual void forEachChild(cVisitor *v) override;
114 
116  // Note: we need long method names here because cModule subclasses from this class
118 
122  int getNumOwnedObjects() const {return numObjs;}
123 
128  cOwnedObject *getOwnedObject(int k);
130 };
131 
132 } // namespace omnetpp
133 
134 
135 #endif
136 
omnetpp::cObject
cObject is a lightweight class which serves as the root of the OMNeT++ class hierarchy....
Definition: cobject.h:92
omnetpp::cSoftOwner::getNumOwnedObjects
int getNumOwnedObjects() const
Definition: csoftowner.h:122
omnetpp::cVisitor
Enables traversing the tree of (cObject-rooted) simulation objects.
Definition: cvisitor.h:56
omnetpp::cSoftOwner
Internal class, used as a base class for modules and channels. It is not intended for subclassing out...
Definition: csoftowner.h:33
omnetpp::cSoftOwner::isSoftOwner
virtual bool isSoftOwner() const override
Definition: csoftowner.h:100
omnetpp::cChannelType
Abstract base class for creating a channel of a given type.
Definition: ccomponenttype.h:326
omnetpp::cNoncopyableOwnedObject
Base class for cOwnedObject-based classes that do not wish to support assignment and duplication.
Definition: cownedobject.h:242
omnetpp::cOwnedObject
A cObject that keeps track of its owner. It serves as base class for many classes in the OMNeT++ libr...
Definition: cownedobject.h:105