Statistics
| Branch: | Revision:

root / include / clockeddefaultlist.h @ 01873262

History | View | Annotate | Download (3.94 KB)

1
//==========================================================================
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

    
26
#include "cdefaultlist.h"
27

    
28

    
29
/**
30
 * This is a thread safe wrapper around cDefaultList
31
 *
32
 * @ingroup Horizon
33
 */
34
class SIM_API cLockedDefaultList : public cDefaultList
35
{
36
  private:
37
    // the lock
38
    pthread_mutex_t mutex;
39

    
40
    //void construct();
41
    virtual void doInsert(cOwnedObject *obj);                                // called from constructor of cObject
42
    virtual void ownedObjectDeleted(cOwnedObject *obj);                      // called from destructor of cObject
43
    virtual void yieldOwnership(cOwnedObject *obj, cObject *newOwner);
44

    
45
  public:
46
    // internal: called from module creation code in ctypes.cc
47
    void takeAllObjectsFrom(cLockedDefaultList& other);
48

    
49
  protected:
50
    /** @name Redefined cDefaultList member functions */
51
    //@{
52

    
53
    /**
54
     * Redefined.
55
     */
56
    void take(cOwnedObject *obj);
57

    
58
    /**
59
     * Redefined.
60
     */
61
    void drop(cOwnedObject *obj);
62

    
63
  public:
64
    /** @name Constructors, destructor, assignment. */
65
    //@{
66

    
67
    /**
68
     * Copy constructor. Throws exception.
69
     */
70
    cLockedDefaultList(const cLockedDefaultList& list);
71

    
72
    /**
73
     * Constructor.
74
     */
75
    explicit cLockedDefaultList(const char *name=NULL);
76

    
77
    /**
78
     * Destructor. The contained objects will be deleted.
79
     */
80
    virtual ~cLockedDefaultList();
81

    
82
    /**
83
     * Assignment operator. Throws exception.
84
     */
85
    cLockedDefaultList& operator=(const cLockedDefaultList& list);
86
    //@}
87

    
88
    /** @name Redefined cObject member functions */
89
    //@{
90

    
91
    /**
92
     * Duplication. Throws exception.
93
     */
94
    virtual cLockedDefaultList *dup() const  {return new cLockedDefaultList(*this);}
95

    
96
    /**
97
     * Returns true.
98
     */
99
    virtual bool isSoftOwner()  {return true;}
100

    
101
    /**
102
     * Produces a one-line description of object contents into the buffer passed as argument.
103
     * See cObject for more details.
104
     */
105
    virtual std::string info();
106

    
107
    /**
108
     * Calls v->visit(this) for each contained object.
109
     * See cObject for more details.
110
     */
111
    virtual void forEachChild(cVisitor *v);
112

    
113
    /**
114
     * Packing and unpacking cannot be supported with this class.
115
     * This method raises an error.
116
     */
117
    virtual void parsimPack(cCommBuffer *buffer);
118

    
119
    /**
120
     * Packing and unpacking cannot be supported with this class.
121
     * This method raises an error.
122
     */
123
    virtual void parsimUnpack(cCommBuffer *buffer);
124
    //@}
125

    
126
    /** @name Container functions. */
127
    // Note: we need long method names here because cModule subclasses from this class
128
    //@{
129

    
130
    /**
131
     * Returns the number of elements stored.
132
     */
133
    int defaultListItems() const {return cDefaultList::defaultListSize();}
134

    
135
    /**
136
     * Get the element at the given position. k must be between 0 and
137
     * items()-1 (inclusive). Note that elements may move as the result
138
     * of add() and remove() operations. If the index is out of bounds,
139
     * NULL is returned.
140
     */
141
    cOwnedObject *defaultListGet(int k);
142

    
143
    /**
144
     * Returns true if the set contains the given object, false otherwise.
145
     */
146
    // Note: we need a long name here because cModule subclasses from this
147
    bool defaultListContains(cOwnedObject *obj);
148
    //@}
149
};
150

    
151
#endif