OMNeT++ Simulation Library  5.6.1
cdefaultlist.h
1 //==========================================================================
2 // CDEFAULTLIST.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_CDEFAULTLIST_H
17 #define __OMNETPP_CDEFAULTLIST_H
18 
19 #include "cownedobject.h"
20 
21 namespace omnetpp {
22 
23 
33 class SIM_API cDefaultList : public cNoncopyableOwnedObject
34 {
35  friend class cObject;
36  friend class cOwnedObject;
37  friend class cChannelType;
38 
39  private:
40  enum {FL_PERFORMFINALGC = 2}; // whether to delete owned objects in the destructor
41 
42  private:
43  cOwnedObject **objs; // array of owned objects
44  int numObjs; // number of elements used in objects[] (0..num-1)
45  int capacity; // allocated size of objs[]
46 
47 #ifdef SIMFRONTEND_SUPPORT
48  private:
49  int64_t lastChangeSerial;
50 #endif
51 
52  private:
53  void construct();
54  void doInsert(cOwnedObject *obj);
55  virtual void ownedObjectDeleted(cOwnedObject *obj) override;
56  virtual void yieldOwnership(cOwnedObject *obj, cObject *newOwner) override;
57 
58  public:
59  // internal: called from module creation code in ctypes.cc
60  void takeAllObjectsFrom(cDefaultList& other);
61 
62 #ifdef SIMFRONTEND_SUPPORT
63  // internal: used by the UI to optimize refreshes
64  void updateLastChangeSerial() {lastChangeSerial = changeCounter++;}
65  virtual bool hasChangedSince(int64_t lastRefreshSerial);
66 #endif
67 
68  protected:
71 
75  virtual void take(cOwnedObject *obj) override;
76 
80  virtual void drop(cOwnedObject *obj) override;
81 
82  public:
88  explicit cDefaultList(const char *name=nullptr);
89 
93  virtual ~cDefaultList();
95 
101  virtual bool isSoftOwner() const override {return true;}
102 
107  virtual std::string str() const override;
108 
113  virtual void forEachChild(cVisitor *v) override;
114 
119  virtual void parsimPack(cCommBuffer *buffer) const override;
120 
125  virtual void parsimUnpack(cCommBuffer *buffer) override;
127 
129  // Note: we need long method names here because cModule subclasses from this class
131 
137  bool getPerformFinalGC() const {return flags&FL_PERFORMFINALGC;}
138 
160  virtual void setPerformFinalGC(bool b) {setFlag(FL_PERFORMFINALGC,b);}
161 
165  int defaultListSize() const {return numObjs;}
166 
172  cOwnedObject *defaultListGet(int k);
173 
177  // Note: we need a long name here because cModule subclasses from this
178  bool defaultListContains(cOwnedObject *obj) const;
180 };
181 
182 } // namespace omnetpp
183 
184 
185 #endif
186 
Internal class, used as a base class for modules and channels. It is not intended for subclassing out...
Definition: cdefaultlist.h:33
Root of the OMNeT++ class hierarchy. cObject is a lightweight class without any data members...
Definition: cobject.h:58
bool getPerformFinalGC() const
Definition: cdefaultlist.h:137
virtual void setPerformFinalGC(bool b)
Definition: cdefaultlist.h:160
int defaultListSize() const
Definition: cdefaultlist.h:165
virtual bool isSoftOwner() const override
Definition: cdefaultlist.h:101
Buffer for the communications layer of parallel simulation.
Definition: ccommbuffer.h:41
A cObject that keeps track of its owner. It serves as base class for many classes in the OMNeT++ libr...
Definition: cownedobject.h:104
Enables traversing the tree of (cObject-rooted) simulation objects.
Definition: cvisitor.h:56
Definition: cabstracthistogram.h:21
Base class for cOwnedObject-based classes that do not wish to support assignment and duplication...
Definition: cownedobject.h:248
Abstract base class for creating a channel of a given type.
Definition: ccomponenttype.h:312