Statistics
| Branch: | Revision:

root / include / clockeddefaultlist.h @ ffa9279f

History | View | Annotate | Download (3.92 KB)

1 01873262 Georg Kunz
//==========================================================================
2
//  CLOCKEDDEFAULTLIST.H - part of
3
//
4
//                     Horizon/OMNeT++/OMNEST
5
//            Discrete System Simulation in C++
6
//
7
//
8
//  Declaration of the following classes:
9
//    cLockedDefaultList : holds a set of cObjects in a thread-safe manner
10
//
11
//==========================================================================
12
13
/*--------------------------------------------------------------*
14
  Copyright (C) 1992-2005 Andras Varga
15
  Copyright (C) 2009      Georg Kunz
16

17
  This file is distributed WITHOUT ANY WARRANTY. See the file
18
  `license' for details on this and other legal matters.
19
*--------------------------------------------------------------*/
20
21
#ifndef __CLOCKEDDEFAULTLIST_H
22
#define __CLOCKEDDEFAULTLIST_H
23
24
#include <pthread.h>
25
#include "cdefaultlist.h"
26
27
28
/**
29
 * This is a thread safe wrapper around cDefaultList
30
 *
31
 * @ingroup Horizon
32
 */
33 93d0d4d3 Simon Tenbusch
template<class T>
34 01873262 Georg Kunz
class SIM_API cLockedDefaultList : public cDefaultList
35
{
36
  private:
37 b781545c Georg Kunz
        T lock;
38 01873262 Georg Kunz
39
    //void construct();
40
    virtual void doInsert(cOwnedObject *obj);                                // called from constructor of cObject
41
    virtual void ownedObjectDeleted(cOwnedObject *obj);                      // called from destructor of cObject
42
    virtual void yieldOwnership(cOwnedObject *obj, cObject *newOwner);
43
44
  public:
45
    // internal: called from module creation code in ctypes.cc
46
    void takeAllObjectsFrom(cLockedDefaultList& other);
47
48
  protected:
49
    /** @name Redefined cDefaultList member functions */
50
    //@{
51
52
    /**
53
     * Redefined.
54
     */
55
    void take(cOwnedObject *obj);
56
57
    /**
58
     * Redefined.
59
     */
60
    void drop(cOwnedObject *obj);
61
62
  public:
63
    /** @name Constructors, destructor, assignment. */
64
    //@{
65
66
    /**
67
     * Copy constructor. Throws exception.
68
     */
69
    cLockedDefaultList(const cLockedDefaultList& list);
70
71
    /**
72
     * Constructor.
73
     */
74
    explicit cLockedDefaultList(const char *name=NULL);
75
76
    /**
77
     * Destructor. The contained objects will be deleted.
78
     */
79
    virtual ~cLockedDefaultList();
80
81
    /**
82
     * Assignment operator. Throws exception.
83
     */
84
    cLockedDefaultList& operator=(const cLockedDefaultList& list);
85
    //@}
86
87
    /** @name Redefined cObject member functions */
88
    //@{
89
90
    /**
91
     * Duplication. Throws exception.
92
     */
93
    virtual cLockedDefaultList *dup() const  {return new cLockedDefaultList(*this);}
94
95
    /**
96
     * Returns true.
97
     */
98
    virtual bool isSoftOwner()  {return true;}
99
100
    /**
101
     * Produces a one-line description of object contents into the buffer passed as argument.
102
     * See cObject for more details.
103
     */
104
    virtual std::string info();
105
106
    /**
107
     * Calls v->visit(this) for each contained object.
108
     * See cObject for more details.
109
     */
110
    virtual void forEachChild(cVisitor *v);
111
112
    /**
113
     * Packing and unpacking cannot be supported with this class.
114
     * This method raises an error.
115
     */
116
    virtual void parsimPack(cCommBuffer *buffer);
117
118
    /**
119
     * Packing and unpacking cannot be supported with this class.
120
     * This method raises an error.
121
     */
122
    virtual void parsimUnpack(cCommBuffer *buffer);
123
    //@}
124
125
    /** @name Container functions. */
126
    // Note: we need long method names here because cModule subclasses from this class
127
    //@{
128
129
    /**
130
     * Returns the number of elements stored.
131
     */
132
    int defaultListItems() const {return cDefaultList::defaultListSize();}
133
134
    /**
135
     * Get the element at the given position. k must be between 0 and
136
     * items()-1 (inclusive). Note that elements may move as the result
137
     * of add() and remove() operations. If the index is out of bounds,
138
     * NULL is returned.
139
     */
140
    cOwnedObject *defaultListGet(int k);
141
142
    /**
143
     * Returns true if the set contains the given object, false otherwise.
144
     */
145
    // Note: we need a long name here because cModule subclasses from this
146
    bool defaultListContains(cOwnedObject *obj);
147
    //@}
148
};
149
150
#endif