csoftowner.h Source File

API: csoftowner.h Source File
API
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
21namespace omnetpp {
22
23
33class 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:
84
87 explicit cSoftOwner(const char *name=nullptr, bool namepooling=true);
88
92 virtual ~cSoftOwner();
94
97
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
cOwnedObject * getOwnedObject(int k)
virtual void take(cOwnedObject *obj) override
cSoftOwner(const char *name=nullptr, bool namepooling=true)
virtual bool isSoftOwner() const override
Definition csoftowner.h:100
virtual void drop(cOwnedObject *obj) override
virtual void forEachChild(cVisitor *v) override
virtual std::string str() const override
int getNumOwnedObjects() const
Definition csoftowner.h:122
Enables traversing the tree of (cObject-rooted) simulation objects.
Definition cvisitor.h:57